summaryrefslogtreecommitdiff
path: root/npc/config/duplicates.txt
blob: 6eabefc61184bb7548a07b4354bda69be37102e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// TMW2 script
// Author: Jesusalva <admin@tmw2.org>
// Manages duplicates

-	script	#dupemaster	32767,{
    end;

OnInterIfInitOnce:
    // (dupe_name$, expire_tick)
    $@_DUPES = htnew();
    // Try again if it failed, or if ID is zero
    if (!$@_DUPES)
        $@_DUPES = htnew();
    debugmes "NPC Duplication database initiated at ID %d", $@_DUPES;
    end;

OnInit:
    initnpctimer;
    end;

// Cleans every 1s
OnTimer1000:
    .@t = gettimetick(2);

    .@iter = htiterator($@_DUPES);
    for (.@key$ = htinextkey(.@iter); hticheck(.@iter); .@key$ = htinextkey(.@iter)) {
        // Check if the NPC expired, remove from hash table if so
        if (htget($@_DUPES, .@key$, INT_MAX) <= .@t) {
            npc_duplicate_remove(.@key$);
            htput($@_DUPES, .@key$, 0);
        }
    }
    htidelete(.@iter);

    initnpctimer;
    end;
}