From afba22a2aa237582802dc4cdd517c115bba9af24 Mon Sep 17 00:00:00 2001 From: Atemo Date: Sun, 17 Jul 2022 18:02:27 +0200 Subject: [PATCH] * Removed the warning in unitstopwalk (there is no way to check is the unit is curently walking with npc script command) * Corrected mistakes in unitwalk --- src/map/script.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/map/script.cpp b/src/map/script.cpp index 65f3a175a2..b5db76de54 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -19325,11 +19325,15 @@ BUILDIN_FUNC(unitwalk) status_calc_npc(((TBL_NPC*)bl), SCO_NONE); } + bool can_reach = false; + if (!strcmp(cmd,"unitwalk")) { int x = script_getnum(st,3); int y = script_getnum(st,4); + can_reach = unit_can_reach_pos(bl,x,y,0); + script_pushint(st, can_reach); - if (script_pushint(st, unit_can_reach_pos(bl,x,y,0))) { + if (can_reach) { if (ud != nullptr) ud->state.force_walk = true; add_timer(gettick()+50, unit_delay_walktoxy_timer, bl->id, (x<<16)|(y&0xFFFF)); // Need timer to avoid mismatches @@ -19341,7 +19345,11 @@ BUILDIN_FUNC(unitwalk) ShowError("buildin_unitwalk: Bad target destination.\n"); script_pushint(st, 0); return SCRIPT_CMD_FAILURE; - } else if (script_pushint(st, unit_can_reach_bl(bl, tbl, distance_bl(bl, tbl)+1, 0, NULL, NULL))) { + } + can_reach = unit_can_reach_bl(bl, tbl, distance_bl(bl, tbl)+1, 0, NULL, NULL); + script_pushint(st, can_reach); + + if (can_reach) { if (ud != nullptr) ud->state.force_walk = true; add_timer(gettick()+50, unit_delay_walktobl_timer, bl->id, tbl->id); // Need timer to avoid mismatches @@ -19349,7 +19357,7 @@ BUILDIN_FUNC(unitwalk) off = 4; } - if (ud && script_hasdata(st, off)) { + if (ud && script_hasdata(st, off) && can_reach) { done_label = script_getstr(st, off); check_event(st, done_label); safestrncpy(ud->walk_done_event, done_label, sizeof(ud->walk_done_event)); @@ -19497,11 +19505,6 @@ BUILDIN_FUNC(unitstopwalk) if (ud != nullptr) ud->state.force_walk = false; - if (unit_stop_walking(bl, flag) == 0 && flag != USW_FORCE_STOP) { - ShowWarning("buildin_unitstopwalk: Unable to find unit or unit is not walking.\n"); - return SCRIPT_CMD_FAILURE; - } - return SCRIPT_CMD_SUCCESS; } else { return SCRIPT_CMD_FAILURE;