Przeglądaj źródła

Added a new script command unitexists
* Small follow up to 4f16d82.
* Checks to see if a unit exists or not.

aleos89 9 lat temu
rodzic
commit
67e26c885d
2 zmienionych plików z 25 dodań i 0 usunięć
  1. 7 0
      doc/script_commands.txt
  2. 18 0
      src/map/script.c

+ 7 - 0
doc/script_commands.txt

@@ -7145,6 +7145,13 @@ For the position, the x and y are given in the UnitSkillUsePos.
 
 ---------------------------------------
 
+*unitexists <GID>;
+
+Checks if the given Game ID exists. Returns false if the object doesn't exist, or true if
+it does.
+
+---------------------------------------
+
 *getunittype <GID>;
 
 Returns the type of object from the given Game ID. Returns -1 if the given GID does not

+ 18 - 0
src/map/script.c

@@ -16712,6 +16712,23 @@ BUILDIN_FUNC(pcstopfollow)
 // <--- [zBuffer] List of player cont commands
 // [zBuffer] List of unit control commands --->
 
+/// Checks to see if the unit exists.
+///
+/// unitexists <unit id>;
+BUILDIN_FUNC(unitexists)
+{
+	struct block_list* bl;
+
+	bl = map_id2bl(script_getnum(st, 2));
+
+	if (!bl)
+		script_pushint(st, false);
+	else
+		script_pushint(st, true);
+
+	return SCRIPT_CMD_SUCCESS;
+}
+
 /// Gets the type of the given Game ID.
 ///
 /// getunittype <unit id>;
@@ -21690,6 +21707,7 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(pcblockmove,"ii"),
 	// <--- [zBuffer] List of player cont commands
 	// [zBuffer] List of unit control commands --->
+	BUILDIN_DEF(unitexists,"i"),
 	BUILDIN_DEF(getunittype,"i"),
 	BUILDIN_DEF(getunitname,"i"),
 	BUILDIN_DEF(setunitname,"is"),