소스 검색

Updated instance_warpall script command (#7591)

* Added a parameter to the instance_warpall script command to prevent dead players from being warped

Thanks to @aleos89, @Lemongrass3110 and @vstumpf for the reviews!
Atemo 2 년 전
부모
커밋
bc7b9cdd2e
4개의 변경된 파일34개의 추가작업 그리고 9개의 파일을 삭제
  1. 7 1
      doc/script_commands.txt
  2. 18 8
      src/map/script.cpp
  3. 5 0
      src/map/script.hpp
  4. 4 0
      src/map/script_constants.hpp

+ 7 - 1
doc/script_commands.txt

@@ -9697,12 +9697,18 @@ Examples:
 
 ---------------------------------------
 
-*instance_warpall "<map name>",<x>,<y>{,<instance id>};
+*instance_warpall "<map name>",<x>,<y>{,<instance id>,{<flag>}};
 
 Warps all players in the <instance id> to <map name> to the given coordinates.
 If no ID is specified, the IM_PARTY instance the invoking player is attached
 to is used. If that fails, the script will come to a halt.
 
+<flag> bitmask allows to add restrictions.
+
+Available values for the <flag> bitmask:
+ IWA_NONE			No restriction. (default)
+ IWA_NOTDEAD		If dead players are warped or not
+
 ---------------------------------------
 
 *instance_announce <instance id>,"<text>",<flag>{,<fontColor>{,<fontType>{,<fontSize>{,<fontAlign>{,<fontY>}}}}};

+ 18 - 8
src/map/script.cpp

@@ -21528,6 +21528,7 @@ static int buildin_instance_warpall_sub(struct block_list *bl, va_list ap)
 	int x = va_arg(ap,int);
 	int y = va_arg(ap,int);
 	int instance_id = va_arg(ap, int);
+	int flag = va_arg(ap, int);
 	map_session_data *sd;
 
 	nullpo_retr(0, bl);
@@ -21537,6 +21538,9 @@ static int buildin_instance_warpall_sub(struct block_list *bl, va_list ap)
 
 	sd = (TBL_PC *)bl;
 
+	if ((flag & IWA_NOTDEAD) != 0 && pc_isdead(sd))
+		return 0;
+
 	std::shared_ptr<s_instance_data> idata = util::umap_find(instances, instance_id);
 
 	if (!idata)
@@ -21572,19 +21576,18 @@ BUILDIN_FUNC(instance_warpall)
 {
 	int16 m;
 	int instance_id;
-	const char *mapn;
-	int x, y;
 
-	mapn = script_getstr(st,2);
-	x    = script_getnum(st,3);
-	y    = script_getnum(st,4);
+	const char *mapn = script_getstr(st,2);
+
 	if( script_hasdata(st,5) )
 		instance_id = script_getnum(st,5);
 	else
 		instance_id = script_instancegetid(st, IM_PARTY);
 
-	if( instance_id <= 0 || (m = map_mapname2mapid(mapn)) < 0 || (m = instance_mapid(m, instance_id)) < 0)
+	if( instance_id <= 0 || (m = map_mapname2mapid(mapn)) < 0 || (m = instance_mapid(m, instance_id)) < 0) {
+		ShowError("buildin_instance_warpall: Instance map for instance ID %d is not found.\n", instance_id);
 		return SCRIPT_CMD_FAILURE;
+	}
 
 	std::shared_ptr<s_instance_data> idata = util::umap_find(instances, instance_id);
 
@@ -21593,8 +21596,15 @@ BUILDIN_FUNC(instance_warpall)
 		return SCRIPT_CMD_FAILURE;
 	}
 
+	int flag = IWA_NONE;
+	int x = script_getnum(st,3);
+	int y = script_getnum(st,4);
+
+	if( script_hasdata(st, 6) )
+		flag = script_getnum(st, 6);
+
 	for(const auto &it : idata->map)
-		map_foreachinmap(buildin_instance_warpall_sub, it.m, BL_PC, map_id2index(m), x, y, instance_id);
+		map_foreachinmap(buildin_instance_warpall_sub, it.m, BL_PC, map_id2index(m), x, y, instance_id, flag);
 
 	return SCRIPT_CMD_SUCCESS;
 }
@@ -27447,7 +27457,7 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(instance_enter,"s????"),
 	BUILDIN_DEF(instance_npcname,"s?"),
 	BUILDIN_DEF(instance_mapname,"s?"),
-	BUILDIN_DEF(instance_warpall,"sii?"),
+	BUILDIN_DEF(instance_warpall,"sii??"),
 	BUILDIN_DEF(instance_announce,"isi?????"),
 	BUILDIN_DEF(instance_check_party,"i???"),
 	BUILDIN_DEF(instance_check_guild,"i???"),

+ 5 - 0
src/map/script.hpp

@@ -2090,6 +2090,11 @@ enum e_convertpcinfo_type : uint8 {
 	CPC_ACCOUNT   = 2
 };
 
+enum e_instance_warpall_flag{
+	IWA_NONE    = 0x00,
+	IWA_NOTDEAD = 0x01,
+};
+
 /**
  * Player blocking actions related flags.
  */

+ 4 - 0
src/map/script_constants.hpp

@@ -9489,6 +9489,10 @@
 	export_constant(CPC_CHAR);
 	export_constant(CPC_ACCOUNT);
 
+	/* instance_warpall flags */
+	export_constant(IWA_NONE);
+	export_constant(IWA_NOTDEAD);
+
 	/* skill hit */
 	export_constant(DMG_SINGLE);
 	export_constant(DMG_MULTI_HIT);