From 1aa0c7f8ed925a181809fb72ed531b0981435537 Mon Sep 17 00:00:00 2001 From: mekolat Date: Sun, 1 May 2016 20:27:30 -0400 Subject: allow addtimer to have a target --- src/map/script-fun.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/map') diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 90eb557..849bffa 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -2640,11 +2640,23 @@ void builtin_donpcevent(ScriptState *st) static void builtin_addtimer(ScriptState *st) { + dumb_ptr sd; interval_t tick = static_cast(conv_num(st, &AARG(0))); ZString event_ = ZString(conv_str(st, &AARG(1))); NpcEvent event; extract(event_, &event); - pc_addeventtimer(script_rid2sd(st), tick, event); + + if (HARG(2)) + sd = map_id_is_player(wrap(conv_num(st, &AARG(2)))); + else if (st->rid) + sd = script_rid2sd(st); + + if (sd == nullptr) + { + PRINTF("builtin_addtimer: player not attached.\n"_fmt); + } + + pc_addeventtimer(sd, tick, event); } /*========================================== @@ -4736,7 +4748,7 @@ BuiltinFunction builtin_functions[] = BUILTIN(areamonster, "Mxyxysmi?"_s, '\0'), BUILTIN(killmonster, "ME"_s, '\0'), BUILTIN(donpcevent, "E"_s, '\0'), - BUILTIN(addtimer, "tE"_s, '\0'), + BUILTIN(addtimer, "tE?"_s, '\0'), BUILTIN(addnpctimer, "tE"_s, '\0'), BUILTIN(initnpctimer, "?"_s, '\0'), BUILTIN(startnpctimer, "?"_s, '\0'), -- cgit v1.2.3-60-g2f50