Explorar o código

Suggestion: checkwall script command (#3393)

* Added checkwall script command
- Included the checkwall in npc folder
Atemo %!s(int64=6) %!d(string=hai) anos
pai
achega
3d8104d7fb

+ 6 - 0
doc/script_commands.txt

@@ -8660,6 +8660,12 @@ same as NPC sprite facing directions: 0=north, 1=northwest, 2=west, etc.
 
 ---------------------------------------
 
+*checkwall "<name>";
+
+This command will return true if the wall with the given name exists, false otherwise.
+
+---------------------------------------
+
 *readbook <book id>,<page>;
 
 This command will open a book item at the specified page.

+ 4 - 2
npc/battleground/tierra/tierra01.txt

@@ -208,7 +208,8 @@ OnEnable:
 
 OnKill:
 	killmonster "bat_a01","barricade#bat_a01_a::OnMyMobDead";
-	delwall "bat_a01_c1";
+	if (checkwall("bat_a01_c1") == true)
+		delwall "bat_a01_c1";
 	end;
 
 OnMyMobDead:
@@ -230,7 +231,8 @@ OnEnable:
 
 OnKill:
 	killmonster "bat_a01","barricade#bat_a01_b::OnMyMobDead";
-	delwall "bat_a01_g1";
+	if (checkwall("bat_a01_g1") == true)
+		delwall "bat_a01_g1";
 	end;
 
 OnMyMobDead:

+ 4 - 2
npc/battleground/tierra/tierra02.txt

@@ -207,7 +207,8 @@ OnEnable:
 
 OnKill:
 	killmonster "bat_a02","barricade#bat_a02_a::OnMyMobDead";
-	delwall "bat_a02_c1";
+	if (checkwall("bat_a02_c1") == true)
+		delwall "bat_a02_c1";
 	end;
 
 OnMyMobDead:
@@ -229,7 +230,8 @@ OnEnable:
 
 OnKill:
 	killmonster "bat_a02","barricade#bat_a02_b::OnMyMobDead";
-	delwall "bat_a02_g1";
+	if (checkwall("bat_a02_g1") == true)
+		delwall "bat_a02_g1";
 	end;
 
 OnMyMobDead:

+ 2 - 1
npc/custom/battleground/unofficial/bg_tierra_01.txt

@@ -275,7 +275,8 @@ OnBuild:
 
 OnDestroy:
 	killmonster "bat_a01","Guillaume_TV1B::OnWall";
-	delwall "bat_a01_g1";
+	if (checkwall("bat_a01_g1") == true)
+		delwall "bat_a01_g1";
 	set .MyMobCount,0;
 	end;
 

+ 2 - 1
npc/custom/battleground/unofficial/bg_tierra_02.txt

@@ -275,7 +275,8 @@ OnBuild:
 
 OnDestroy:
 	killmonster "bat_a02","Guillaume_TV2B::OnWall";
-	delwall "bat_a02_g1";
+	if (checkwall("bat_a02_g1") == true)
+		delwall "bat_a02_g1";
 	set .MyMobCount,0;
 	end;
 

+ 3 - 1
npc/guild2/agit_main_se.txt

@@ -1700,7 +1700,9 @@ OnBarrierDestroyed:
 	end;
 
 OnDisable:
-	delwall substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9)+"_"+strnpcinfo(1);
+	.@wall_name$ = substr(strnpcinfo(2),0,1) + substr(strnpcinfo(2),8,9) + "_" + strnpcinfo(1);
+	if (checkwall(.@wall_name$) == true)
+		delwall .@wall_name$;
 	killmonster strnpcinfo(2),strnpcinfo(0)+"::OnBarrierDestroyed";
 	end;
 }

+ 5 - 0
src/map/map.cpp

@@ -3228,6 +3228,11 @@ void map_setgatcell(int16 m, int16 x, int16 y, int gat)
  *------------------------------------------*/
 static DBMap* iwall_db;
 
+bool map_iwall_exist(const char* wall_name)
+{
+	return strdb_exists(iwall_db, wall_name);
+}
+
 void map_iwall_nextxy(int16 x, int16 y, int8 dir, int pos, int16 *x1, int16 *y1)
 {
 	if( dir == 0 || dir == 4 )

+ 1 - 0
src/map/map.hpp

@@ -1098,6 +1098,7 @@ int cleanup_sub(struct block_list *bl, va_list ap);
 int map_delmap(char* mapname);
 void map_flags_init(void);
 
+bool map_iwall_exist(const char* wall_name);
 bool map_iwall_set(int16 m, int16 x, int16 y, int size, int8 dir, bool shootable, const char* wall_name);
 void map_iwall_get(struct map_session_data *sd);
 bool map_iwall_remove(const char *wall_name);

+ 9 - 0
src/map/script.cpp

@@ -13327,6 +13327,14 @@ BUILDIN_FUNC(delwall)
 	return SCRIPT_CMD_SUCCESS;
 }
 
+BUILDIN_FUNC(checkwall)
+{
+	const char *wall_name = script_getstr(st, 2);
+
+	script_pushint(st, map_iwall_exist(wall_name));
+	return SCRIPT_CMD_SUCCESS;
+}
+
 /// Retrieves various information about the specified guardian.
 ///
 /// guardianinfo("<map_name>", <index>, <type>) -> <value>
@@ -24267,6 +24275,7 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(getfreecell,"srr?????"),
 	BUILDIN_DEF(setwall,"siiiiis"),
 	BUILDIN_DEF(delwall,"s"),
+	BUILDIN_DEF(checkwall,"s"),
 	BUILDIN_DEF(searchitem,"rs"),
 	BUILDIN_DEF(mercenary_create,"ii"),
 	BUILDIN_DEF(mercenary_heal,"ii"),