From b4b69a2cc1c6b89831b175a337a8b1d3bc16ebaf Mon Sep 17 00:00:00 2001 From: Atemo Date: Fri, 12 May 2023 00:34:36 +0200 Subject: [PATCH] Fixed an issue where mobs instantly walked after being spotted (#7738) * Fixed an issue where mobs instantly walked after being spotted MIN_RANDOMWALKTIME was initialized too early * This behavior is only applied on the monster script command --- src/map/mob.cpp | 6 ++++++ src/map/script.cpp | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/map/mob.cpp b/src/map/mob.cpp index c007d96379..bde792c746 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -1571,6 +1571,12 @@ int mob_randomwalk(struct mob_data *md,t_tick tick) nullpo_ret(md); + // Initialize next_walktime + if (md->next_walktime == INVALID_TIMER) { + md->next_walktime = tick+rnd()%1000+MIN_RANDOMWALKTIME; + return 1; + } + if(DIFF_TICK(md->next_walktime,tick)>0 || status_has_mode(&md->status,MD_NORANDOMWALK) || !unit_can_move(&md->bl) || diff --git a/src/map/script.cpp b/src/map/script.cpp index e6114ac9a7..ef0cb6b0ba 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -11157,11 +11157,18 @@ BUILDIN_FUNC(monster) else m = map_mapname2mapid(mapn); + TBL_MOB* md; + for(i = 0; i < amount; i++) { //not optimised int mobid = mob_once_spawn(sd, m, x, y, str, class_, 1, event, size, ai); - if (mobid) + if (mobid > 0) { + md = map_id2md(mobid); + if (md) + md->next_walktime = INVALID_TIMER; + mapreg_setreg(reference_uid(add_str("$@mobid"), i), mobid); + } } return SCRIPT_CMD_SUCCESS; @@ -11274,11 +11281,18 @@ BUILDIN_FUNC(areamonster) else m = map_mapname2mapid(mapn); + TBL_MOB* md; + for(i = 0; i < amount; i++) { //not optimised int mobid = mob_once_spawn_area(sd, m, x0, y0, x1, y1, str, class_, 1, event, size, ai); - if (mobid) + if (mobid > 0) { + md = map_id2md(mobid); + if (md) + md->next_walktime = INVALID_TIMER; + mapreg_setreg(reference_uid(add_str("$@mobid"), i), mobid); + } } return SCRIPT_CMD_SUCCESS;