summaryrefslogtreecommitdiff
path: root/src/map/script-fun.cpp
diff options
context:
space:
mode:
authorFreeyorp <TheFreeYorp+github@gmail.com>2018-03-23 21:09:32 +1300
committerFreeyorp <TheFreeYorp+github@gmail.com>2018-03-23 21:09:32 +1300
commit6e559e0a621030b51c3590b5e163b4d9554b410a (patch)
treeeaf66831ae7ebc90b60b8aa9c8d72f7c2cac733e /src/map/script-fun.cpp
parent190672e6da2f3fd3bb740ba886693b0e3c3727ba (diff)
downloadtmwa-6e559e0a621030b51c3590b5e163b4d9554b410a.tar.gz
tmwa-6e559e0a621030b51c3590b5e163b4d9554b410a.tar.bz2
tmwa-6e559e0a621030b51c3590b5e163b4d9554b410a.tar.xz
tmwa-6e559e0a621030b51c3590b5e163b4d9554b410a.zip
Fix NPC script softlockv18.3.22
When an NPC called destroy; from an attached script, npc_id, and associated state, was not properly cleared. This meant that the server considered the PC to still be in conversation, preventing many actions including walking, but with an invalid NPC. This clears state for the specific case of the a PC attached to the script instance that called destroy. It is still not safe to call destroy; if other players may be attached to it.
Diffstat (limited to 'src/map/script-fun.cpp')
-rw-r--r--src/map/script-fun.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp
index e1866bc..8292bdb 100644
--- a/src/map/script-fun.cpp
+++ b/src/map/script-fun.cpp
@@ -1121,6 +1121,7 @@ void builtin_foreach(ScriptState *st)
x1, y1,
block_type);
}
+
/*========================================
* Destructs a temp NPC
*----------------------------------------
@@ -1129,6 +1130,8 @@ static
void builtin_destroy(ScriptState *st)
{
BlockId id;
+ dumb_ptr<map_session_data> sd;
+
if (HARG(0))
id = wrap<BlockId>(conv_num(st, &AARG(0)));
else
@@ -1138,6 +1141,14 @@ void builtin_destroy(ScriptState *st)
if(!nd || nd->npc_subtype != NpcSubtype::SCRIPT)
return;
+ /* If we have a player attached, make sure it is cleared. */
+ /* Not safe to call destroy if others may also be paused on this NPC! */
+ if (st->rid) {
+ sd = script_rid2sd(st);
+ nullpo_retv(sd);
+ npc_event_dequeue(sd);
+ }
+
nd = nd->is_script();
npc_free(nd);
st->oid = BlockId();