From 4cb4d60feedc4552e69e8e8fc2b917569d11cb6b Mon Sep 17 00:00:00 2001 From: Lemongrass3110 Date: Wed, 16 Aug 2017 11:33:35 +0200 Subject: [PATCH] Fixed return value of unitattack for players Fixes #2345 Thanks to @anacondaqq --- doc/script_commands.txt | 9 +++++++-- src/map/script.c | 15 +++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index d89bb0a889..6046c5a0ea 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -7356,12 +7356,17 @@ Examples: *unitattack ,{,}; *unitattack ,""{,}; -This command will make a attack the specified target. It returns 1 upon -success and 0 for all failures. +This command will make a attack the specified target. It returns true upon +success and false for all failures. If is a player and a non-zero is given, the unit will perform a continuous attack instead of a single attack. +Note: +Using unitattack with 0 means that it will use the currently attached unit. +For players any attack requests will fail, because talking to an NPC prevents attacking a monster. +Therefore you need to detach the player from the NPC before using this command. + --------------------------------------- *unitkill ; diff --git a/src/map/script.c b/src/map/script.c index ea5309eede..419c7e7e07 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -18316,7 +18316,7 @@ BUILDIN_FUNC(unitattack) int actiontype = 0; if (!script_rid2bl(2,unit_bl)) { - script_pushint(st, 0); + script_pushint(st, false); return SCRIPT_CMD_FAILURE; } @@ -18331,7 +18331,7 @@ BUILDIN_FUNC(unitattack) target_bl = map_id2bl(conv_num(st, data)); if (!target_bl) { - script_pushint(st, 0); + script_pushint(st, false); return SCRIPT_CMD_FAILURE; } @@ -18339,10 +18339,13 @@ BUILDIN_FUNC(unitattack) actiontype = script_getnum(st,4); switch(unit_bl->type) { - case BL_PC: - clif_parse_ActionRequest_sub(((TBL_PC *)unit_bl), actiontype > 0 ? 0x07 : 0x00, target_bl->id, gettick()); - script_pushint(st, 1); + case BL_PC: { + struct map_session_data* sd = (struct map_session_data*)unit_bl; + + clif_parse_ActionRequest_sub(sd, actiontype > 0 ? 0x07 : 0x00, target_bl->id, gettick()); + script_pushint(st, sd->ud.target == target_bl->id); return SCRIPT_CMD_SUCCESS; + } case BL_MOB: ((TBL_MOB *)unit_bl)->target_id = target_bl->id; break; @@ -18351,7 +18354,7 @@ BUILDIN_FUNC(unitattack) break; default: ShowError("buildin_unitattack: Unsupported source unit type %d.\n", unit_bl->type); - script_pushint(st, 0); + script_pushint(st, false); return SCRIPT_CMD_FAILURE; }