瀏覽代碼

Added return values for unit script commands (fixes #1143)
* Script commands getunitdata and setunitdata will return -1 when the given GID is not found.
* Script commands getunitname and setunitname will return Unknown when the given GID is not found.

aleos89 9 年之前
父節點
當前提交
4f16d82540
共有 2 個文件被更改,包括 9 次插入1 次删除
  1. 5 1
      doc/script_commands.txt
  2. 4 0
      src/map/script.c

+ 5 - 1
doc/script_commands.txt

@@ -7147,7 +7147,7 @@ For the position, the x and y are given in the UnitSkillUsePos.
 
 *getunittype <GID>;
 
-Returns the type of object from the given Game ID. Returns -1 if the given <GID> does not
+Returns the type of object from the given Game ID. Returns -1 if the given GID does not
 exist.
 
 	UNITTYPE_PC     0
@@ -7177,6 +7177,8 @@ Elemental don't support custom names.
 
 Changing a homunculus or pet name will be permanent.
 
+Returns "Unknown" if unit is not found.
+
 ---------------------------------------
 
 *getunitdata <GID>,<arrayname>;
@@ -7186,6 +7188,8 @@ This is used to get and set special data related to the unit.
 With getunitdata, the array given will be filled with the current data. In setunitdata
 the indexes in the array would be used to set that data on the unit.
 
+Both getunitdata and setunitdata will return -1 if the given GID does not exist.
+
 Note: When adjusting a unit's stat (STR, AGI, etc) the unit's respective statuses are
       recalculated (HIT, FLEE, etc) automatically. Keep in mind that some stats don't
 	  affect a unit's status and will have to directly be modified.

+ 4 - 0
src/map/script.c

@@ -16795,6 +16795,7 @@ BUILDIN_FUNC(getunitdata)
 
 	if (!bl) {
 		ShowWarning("buildin_getunitdata: Error in finding object with given game ID %d!\n", script_getnum(st, 2));
+		script_pushint(st, -1);
 		return SCRIPT_CMD_FAILURE;
 	}
 
@@ -17116,6 +17117,7 @@ BUILDIN_FUNC(setunitdata)
 
 	if (!bl) {
 		ShowWarning("buildin_setunitdata: Error in finding object with given game ID %d!\n", script_getnum(st, 2));
+		script_pushint(st, -1);
 		return SCRIPT_CMD_FAILURE;
 	}
 
@@ -17503,6 +17505,7 @@ BUILDIN_FUNC(getunitname)
 
 	if (!bl) {
 		ShowWarning("buildin_getunitname: Error in finding object with given game ID %d!\n", script_getnum(st, 2));
+		script_pushconststr(st, "Unknown");
 		return SCRIPT_CMD_FAILURE;
 	}
 
@@ -17527,6 +17530,7 @@ BUILDIN_FUNC(setunitname)
 
 	if (!bl) {
 		ShowWarning("buildin_setunitname: Error in finding object with given game ID %d!\n", script_getnum(st, 2));
+		script_pushconststr(st, "Unknown");
 		return SCRIPT_CMD_FAILURE;
 	}