From a7e396a0d5459f401a916d7361ece608fed0c49f Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Mon, 12 Jul 2021 23:25:20 -0300 Subject: 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 ^^ --- npc/annuals/fathertime.txt | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'npc/annuals') 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 { -- cgit v1.2.3-70-g09d2