From 7efd696af7da0f46bf291a3ed25509dbb9e164d2 Mon Sep 17 00:00:00 2001 From: Atemo Date: Wed, 27 May 2020 15:52:37 +0200 Subject: [PATCH] Added several check for OnTouch and OnTouch_ before running the event (#5009) * Check if the player is still in npc range * Check if the player is still able to interact with the npc * Check if the npc is cloaked --- src/map/npc.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/map/npc.cpp b/src/map/npc.cpp index f86995f35e..e4524f276a 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -989,6 +989,26 @@ int npc_event_sub(struct map_session_data* sd, struct event_data* ev, const char npc_event_dequeue(sd); return 2; } + + char ontouch_event_name[EVENT_NAME_LENGTH]; + char ontouch2_event_name[EVENT_NAME_LENGTH]; + + safesnprintf(ontouch_event_name, ARRAYLENGTH(ontouch_event_name), "%s::%s", ev->nd->exname, script_config.ontouch_event_name); + safesnprintf(ontouch2_event_name, ARRAYLENGTH(ontouch2_event_name), "%s::%s", ev->nd->exname, script_config.ontouch2_event_name); + + // recheck some conditions for OnTouch/OnTouch_ + if (strcmp(eventname, ontouch_event_name) == 0 || strcmp(eventname, ontouch2_event_name) == 0) { + int xs = ev->nd->u.scr.xs; + int ys = ev->nd->u.scr.ys; + int x = ev->nd->bl.x; + int y = ev->nd->bl.y; + + if (x > 0 && y > 0 && (xs > -1 && ys > -1) && ((sd->bl.x < x - xs) || (sd->bl.x > x + xs) || (sd->bl.y < y - ys) || (sd->bl.y > y + ys)) || + (sd->state.block_action & PCBLOCK_NPCCLICK) || npc_is_cloaked(ev->nd, sd)) { + npc_event_dequeue(sd); + return 2; + } + } run_script(ev->nd->u.scr.script,ev->pos,sd->bl.id,ev->nd->bl.id); return 0; }