diff --git a/api.lua b/api.lua index 81e43bb..d3c2a12 100644 --- a/api.lua +++ b/api.lua @@ -9,10 +9,11 @@ function affects.registerAffect( aDef ) if ( #aDef.stages < 1 ) then return false end - - -- TODO add more checks here to ensure the affect definition won't crash the server + + -- TODO add more checks here to ensure the affect definition won't crash the server affects._affects[aDef.affectid] = aDef + end function affects.removeAffect(name, affectid) @@ -39,6 +40,7 @@ function affects.affectPlayer(name, affectid) if ( affects._affectedPlayers[name][affectid] == nil ) then if ( affects._affects[affectid] ~= nil ) then + whoison.updateStats(name) local ns = ( whoison.getTimeOnline(name) + affects._affects[affectid].stages[1].time ) affects._affectedPlayers[name][affectid] = { stage = 1, nextStage = ns, ran=false } applyAffect(name,affectid) diff --git a/functions.lua b/functions.lua index aea6b8b..7cca007 100644 --- a/functions.lua +++ b/functions.lua @@ -1,17 +1,21 @@ function applyAffect(name,affectid) minetest.log("action","Applying affect "..affectid.." on "..name) + whoison.updateStats(name) local player = minetest.get_player_by_name(name) local oStage = affects._affectedPlayers[name][affectid].stage -- see if they need advanced into the next stage - if ( affects._affectedPlayers[name][affectid].nextStage < whoison.getTimeOnline(name) ) then - affects._affectedPlayers[name][affectid].stage = affects._affectedPlayers[name][affectid].stage + 1 + if ( affects._affectedPlayers[name][affectid].nextStage < whoison.getTimeOnline(name) ) then + local nextStageNum = affects._affectedPlayers[name][affectid].stage + 1 + affects._affectedPlayers[name][affectid].stage = nextStageNum affects._affectedPlayers[name][affectid].ran = false - if ( #affects._affects[affectid].stages < affects._affectedPlayers[name][affectid].stage ) then + minetest.log("action","Advancing "..affectid.." to the next stage for "..name) + if ( #affects._affects[affectid].stages < nextStageNum ) then minetest.log("action","Affect "..affectid.." has worn off of "..name) affects.removeAffect(name,affectid) return - end + end + affects._affectedPlayers[name][affectid].nextStage = (whoison.getTimeOnline(name) + affects._affects[affectid].stages[nextStageNum].time) end local iStage = affects._affectedPlayers[name][affectid].stage diff --git a/init.lua b/init.lua index 874406a..e2f7e17 100644 --- a/init.lua +++ b/init.lua @@ -18,4 +18,7 @@ affects.loadAffects() minetest.register_privilege("affects", "Player can use the affects chat commands.") - +minetest.register_on_shutdown(function() + affects.saveAffects() +end +)