diff options
author | mekolat <mekolat@users.noreply.github.com> | 2016-05-02 15:18:33 -0400 |
---|---|---|
committer | mekolat <mekolat@users.noreply.github.com> | 2016-05-02 15:18:33 -0400 |
commit | b155404944cdf3bb500b7d2978fa2ecd34c14c3c (patch) | |
tree | 776d4aa82ad2d017f613be784d1625aa1584395e /src/map/script-fun.cpp | |
parent | 360614b270acb47643fcf6216dd32b10dfab81dd (diff) | |
parent | b2599f6595558840632bbabf4f91692900536d65 (diff) | |
download | tmwa-b155404944cdf3bb500b7d2978fa2ecd34c14c3c.tar.gz tmwa-b155404944cdf3bb500b7d2978fa2ecd34c14c3c.tar.bz2 tmwa-b155404944cdf3bb500b7d2978fa2ecd34c14c3c.tar.xz tmwa-b155404944cdf3bb500b7d2978fa2ecd34c14c3c.zip |
Merge pull request #219 from mekolat/attachrid
revert attachrid modification
Diffstat (limited to 'src/map/script-fun.cpp')
-rw-r--r-- | src/map/script-fun.cpp | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 0b1e7e6..98c07ed 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -1065,7 +1065,7 @@ void builtin_foreach(ScriptState *st) { int x0, y0, x1, y1, bl_num; - dumb_ptr<block_list> caster = map_id2bl(st->rid); + dumb_ptr<block_list> sd; bl_num = conv_num(st, &AARG(0)); MapName mapname = stringish<MapName>(ZString(conv_str(st, &AARG(1)))); x0 = conv_num(st, &AARG(2)); @@ -1096,8 +1096,17 @@ void builtin_foreach(ScriptState *st) default: return; } + if (HARG(7)) + sd = map_id_is_player(wrap<BlockId>(conv_num(st, &AARG(7)))); + else if (st->rid) + sd = script_rid2sd(st); + + if (sd == nullptr) + { + PRINTF("builtin_foreach: player not attached.\n"_fmt); + } - map_foreachinarea(std::bind(builtin_foreach_sub, ph::_1, event, caster->bl_id), + map_foreachinarea(std::bind(builtin_foreach_sub, ph::_1, event, sd->bl_id), m, x0, y0, x1, y1, @@ -2640,11 +2649,23 @@ void builtin_donpcevent(ScriptState *st) static void builtin_addtimer(ScriptState *st) { + dumb_ptr<map_session_data> sd; interval_t tick = static_cast<interval_t>(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<BlockId>(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); } /*========================================== @@ -3222,17 +3243,10 @@ void builtin_resetstatus(ScriptState *st) static void builtin_attachrid(ScriptState *st) { - dumb_ptr<map_session_data> sd = map_id2sd(st->rid); - BlockId newid = wrap<BlockId>(conv_num(st, &AARG(0))); - - if (sd && newid != st->rid) - sd->npc_id = BlockId(); - - st->rid = newid; + st->rid = wrap<BlockId>(conv_num(st, &AARG(0))); push_int<ScriptDataInt>(st->stack, (map_id2sd(st->rid) != nullptr)); } - /*========================================== * RIDのデタッチ *------------------------------------------ @@ -3240,9 +3254,6 @@ void builtin_attachrid(ScriptState *st) static void builtin_detachrid(ScriptState *st) { - dumb_ptr<map_session_data> sd = map_id2sd(st->rid); - if (sd) - sd->npc_id = BlockId(); st->rid = BlockId(); } @@ -4746,7 +4757,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'), @@ -4813,7 +4824,7 @@ BuiltinFunction builtin_functions[] = BUILTIN(getlook, "i"_s, 'i'), BUILTIN(getsavepoint, "i"_s, '.'), BUILTIN(areatimer, "MxyxytEi"_s, '\0'), - BUILTIN(foreach, "iMxyxyE"_s, '\0'), + BUILTIN(foreach, "iMxyxyE?"_s, '\0'), BUILTIN(isin, "Mxyxy"_s, 'i'), BUILTIN(iscollision, "Mxy"_s, 'i'), BUILTIN(shop, "s"_s, '\0'), |