diff options
author | Jesusaves <cpntb1@ymail.com> | 2021-07-12 23:25:20 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2021-07-12 23:25:20 -0300 |
commit | a7e396a0d5459f401a916d7361ece608fed0c49f (patch) | |
tree | 05d020ec4f052e6f38a2bf1872a6fc8b3954eb1e /npc | |
parent | 85f6f317c6f086c1155eb5a45c93781f4cf95943 (diff) | |
download | serverdata-a7e396a0d5459f401a916d7361ece608fed0c49f.tar.gz serverdata-a7e396a0d5459f401a916d7361ece608fed0c49f.tar.bz2 serverdata-a7e396a0d5459f401a916d7361ece608fed0c49f.tar.xz serverdata-a7e396a0d5459f401a916d7361ece608fed0c49f.zip |
Reimplement addnpctimer() altough in a less efficient way.
Father Time inherited it. Cycles every 1s while Weather cycles every 2.5s
I would like to stop adding expensive hacks, please ^^
Diffstat (limited to 'npc')
-rw-r--r-- | npc/annuals/fathertime.txt | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/npc/annuals/fathertime.txt b/npc/annuals/fathertime.txt index 6a92e7dc..bb2361a1 100644 --- a/npc/annuals/fathertime.txt +++ b/npc/annuals/fathertime.txt @@ -2,17 +2,55 @@ end; OnInit: + .evtc = htnew; // event : time in seconds if (debug >= 2) end; - donpcevent strnpcinfo(0) + "::OnTimer20000"; - end; OnClock0000: -OnTimer20000: donpcevent "#XmasConfig::OnCommandRestartQuest"; donpcevent "#HalloweenConfig::OnCommandRestartQuest"; donpcevent "Easter Eggs::OnCheckEaster"; - //initnpctimer; + initnpctimer; + end; + +OnTimer1000: + // There are no NPC timers ongoing, loop forever + if (!htsize(.evtc)) { + initnpctimer; + end; + } + // Otherwise, we got a job to do + .@hti = htiterator(.evtc); + .@cur = gettimetick(2); + for (.@key$ = htinextkey(.@hti); hticheck(.@hti); .@key$ = htinextkey(.@hti)) + { + .@target=htget(.evtc, .@key$, 0); + // Not yet expired + if (.@target > .@cur) + continue; + // Execute NPC Event after removing it from hashtable + htput(.evtc, .@key$, 0); + donpcevent(.@key$); + } + // Deallocate memory and cycle forever + htidelete(.@hti); + initnpctimer; end; + +public function addnpcevent { + .@ev$=getarg(1); + .@t=getarg(0); + htput(.evtc, .@ev$, gettimetick(2)+.@t); + return true; +} + +// NPC Father Time end +} + +function script addnpctimer { + .@t=getarg(0)/1000; + .@ev$=getarg(1); + "#HolidayConfig"::addnpcevent(.@t, .@ev$); + return true; } function script TMWBirthday { |