diff options
author | gumi <git@gumi.ca> | 2020-07-24 14:06:43 -0400 |
---|---|---|
committer | gumi <git@gumi.ca> | 2020-07-27 08:47:44 -0400 |
commit | 97561caeca7e9518ff7e4961a57257c5298bdf25 (patch) | |
tree | 39f97f8453d1b9a14cbf17c20924184e6194d0b6 /npc/functions/player-cache.txt | |
parent | b899412192d02f5f36d693a92d97b8cf6863f72f (diff) | |
download | serverdata-s20200729.tar.gz serverdata-s20200729.tar.bz2 serverdata-s20200729.tar.xz serverdata-s20200729.zip |
add a reusable event dispatching systems20200729
Diffstat (limited to 'npc/functions/player-cache.txt')
-rw-r--r-- | npc/functions/player-cache.txt | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/npc/functions/player-cache.txt b/npc/functions/player-cache.txt index 7c281af9..204d1fe1 100644 --- a/npc/functions/player-cache.txt +++ b/npc/functions/player-cache.txt @@ -216,8 +216,7 @@ * @param 0 - the public local function */ public function addNameHandler { - htput(.name_handlers, "" + getnpcid(), getarg(0)); - return; + return addEventListener(.name_handlers, getarg(0)); } /** @@ -229,8 +228,7 @@ * @param 0 - the public local function */ public function addVaultHandler { - htput(.vault_handlers, "" + getnpcid(), getarg(0)); - return; + return addEventListener(.vault_handlers, getarg(0)); } @@ -253,16 +251,7 @@ if (.@old$ != "" && .@old$ != .account_to_name$[playerattached()]) { // fire event handlers - .@it = htiterator(.name_handlers); - for (.@npc$ = htinextkey(.@it); hticheck(.@it); .@npc$ = htinextkey(.@it)) { - if (.@npc$ == "") { - continue; - } - - .@func$ = htget(.name_handlers, .@npc$, ""); - callfunctionofnpc(atoi(.@npc$), .@func$, .@old$); - } - htidelete(.@it); + dispatchEvent(.name_handlers, .@old$); return true; } @@ -285,16 +274,7 @@ if (.@old > 0 && .@old != .vault_to_account[getvaultid()]) { // fire event handlers - .@it = htiterator(.vault_handlers); - for (.@npc$ = htinextkey(.@it); hticheck(.@it); .@npc$ = htinextkey(.@it)) { - if (.@npc$ == "") { - continue; - } - - .@func$ = htget(.vault_handlers, .@npc$, ""); - callfunctionofnpc(atoi(.@npc$), .@func$, .@old, .@old$); - } - htidelete(.@it); + dispatchEvent(.vault_handlers, .@old, .@old$); return true; } |