Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
lunaluascripts/api_scripts/deathcounter/deathcounter.lua
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
55 lines (49 sloc)
1.48 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local __title = "Death Counter" | |
| local __author = "Mike Santiago" | |
| local __version = "0.8.1.0" | |
| local __url = "http://www.supermariobrosx.org/forums/viewtopic.php?f=51&t=10228" | |
| local __description = "A simple module to count the amount of times you've died on a per episode, per save basis." | |
| local deathCounterApi = {} | |
| --functions go in between these | |
| --Variables | |
| local deathAniState = 0; | |
| local hasDied = false; | |
| local dataInstance = Data(Data.DATA_WORLD, "deathcounter", true); | |
| local deathCount = 0; | |
| --registers | |
| function deathCounterApi.onInitAPI() | |
| ---have to put the onLoad() stuff here.. | |
| deathCount = tonumber(dataInstance:get("deathCount")); | |
| if (deathCount == nil) then | |
| deathCount = 0; | |
| end | |
| registerEvent(deathCounterApi, "onLoop", "loopFrame"); | |
| registerEvent(deathCounterApi, "onExitLevel", "exitLevel"); | |
| end | |
| --internal funcs | |
| function deathCounterApi.loopFrame() | |
| deathAniState = player:mem(0x13E, FIELD_WORD); | |
| Text.print("DEATHS: " .. tostring(deathCount), 3, 2, 2); | |
| if (hasDied == false) then | |
| if (deathAniState > 0) then | |
| deathCount = deathCount + 1; | |
| hasDied = true; | |
| end | |
| end | |
| end | |
| function deathCounterApi.exitLevel() | |
| dataInstance:set("deathCount", tostring(deathCount)); | |
| dataInstance:save(); | |
| end | |
| function deathCounterApi.getDeathCount() | |
| if (deathCount == nil) then | |
| deathCount = tonumber(dataInstance:get("deathCount")); | |
| if(deathCount == nil) then | |
| return 0; | |
| else | |
| return deathCount; | |
| end | |
| end | |
| end | |
| --end with this | |
| return deathCounterApi; |