summaryrefslogtreecommitdiff
path: root/src/map/npc.cpp
diff options
context:
space:
mode:
authorgumi <git@gumi.ca>2018-03-23 16:04:06 -0400
committergumi <git@gumi.ca>2018-03-23 16:04:06 -0400
commit770784082265b83323c2d616ab613ef99b763af9 (patch)
tree411b42a7ec254f79138f867bc1f7ea8f4525cf02 /src/map/npc.cpp
parent6e559e0a621030b51c3590b5e163b4d9554b410a (diff)
downloadtmwa-770784082265b83323c2d616ab613ef99b763af9.tar.gz
tmwa-770784082265b83323c2d616ab613ef99b763af9.tar.bz2
tmwa-770784082265b83323c2d616ab613ef99b763af9.tar.xz
tmwa-770784082265b83323c2d616ab613ef99b763af9.zip
automatically de-attach freed NPCsv18.3.23
Diffstat (limited to 'src/map/npc.cpp')
-rw-r--r--src/map/npc.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/map/npc.cpp b/src/map/npc.cpp
index 0708fc0..88059b9 100644
--- a/src/map/npc.cpp
+++ b/src/map/npc.cpp
@@ -635,6 +635,10 @@ int npc_event(dumb_ptr<map_session_data> sd, NpcEvent eventname,
&& (sd->bl_y < nd->bl_y - ys / 2 || nd->bl_y + ys / 2 < sd->bl_y))
return 1;
}
+
+ if (sd->npc_id && map_id_is_npc(sd->npc_id) == nullptr)
+ npc_event_dequeue(sd); // the NPC was previously freed, so we detach it
+
if (sd->npc_id && sd->npc_pos > -1 && args.size() < 1) // if called from a timer we process async, otherwise sync
{
sd->eventqueuel.push_back(eventname);
@@ -768,9 +772,14 @@ int npc_click(dumb_ptr<map_session_data> sd, BlockId id)
if (sd->npc_id)
{
- if (battle_config.error_log)
- PRINTF("npc_click: npc_id != 0\n"_fmt);
- return 1;
+ if (sd->npc_id && map_id_is_npc(sd->npc_id) == nullptr)
+ npc_event_dequeue(sd); // the NPC was previously freed, so we detach it
+ else
+ {
+ if (battle_config.error_log)
+ PRINTF("npc_click: npc_id != 0\n"_fmt);
+ return 1;
+ }
}
if (npc_checknear(sd, id)) {