Pārlūkot izejas kodu

Fixed return value of unitattack for players

Fixes #2345

Thanks to @anacondaqq
Lemongrass3110 7 gadi atpakaļ
vecāks
revīzija
4cb4d60fee
2 mainītis faili ar 16 papildinājumiem un 8 dzēšanām
  1. 7 2
      doc/script_commands.txt
  2. 9 6
      src/map/script.c

+ 7 - 2
doc/script_commands.txt

@@ -7356,12 +7356,17 @@ Examples:
 *unitattack <GID>,<Target ID>{,<action type>};
 *unitattack <GID>,"<Target Name>"{,<action type>};
 
-This command will make a <GID> attack the specified target. It returns 1 upon
-success and 0 for all failures.
+This command will make a <GID> attack the specified target. It returns true upon
+success and false for all failures.
 
 If <GID> is a player and a non-zero <action type> is given, the unit will perform a
 continuous attack instead of a single attack.
 
+Note:
+Using unitattack with <GID> 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 <GID>;

+ 9 - 6
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;
 	}