Ver código fonte

Fixed #1772 (#1773)

* Fixed #1772

Added support for char_id to readparam
Added a check and error message if get_var is used on a parameter instead of a variable
Lemongrass3110 8 anos atrás
pai
commit
93339212bc
2 arquivos alterados com 25 adições e 5 exclusões
  1. 3 2
      doc/script_commands.txt
  2. 22 3
      src/map/script.c

+ 3 - 2
doc/script_commands.txt

@@ -2311,10 +2311,11 @@ Also useful when passing arrays to functions or accessing another npc's arrays:
 ---------------------------------------
 
 *readparam(<parameter number>{,"<character name>"})
+*readparam(<parameter number>{,<char_id>})
 
 This function will return the specified stat of the invoking character, or, if a
-character name is specified, of that player. The stat can either be a number or
-parameter name, defined in 'src/map/script_constants.h'.
+character name or character id is specified, of that player. The stat can either
+be a number or parameter name, defined in 'src/map/script_constants.h'.
 
 Some example parameters:
 

+ 22 - 3
src/map/script.c

@@ -7791,6 +7791,7 @@ BUILDIN_FUNC(disableitemuse)
  * Returns a character's specified stat.
  * Check pc_readparam for available options.
  * readparam <param>{,"<nick>"}
+ * readparam <param>{,<char_id>}
  *------------------------------------------*/
 BUILDIN_FUNC(readparam)
 {
@@ -7798,9 +7799,18 @@ BUILDIN_FUNC(readparam)
 	struct script_data *data = script_getdata(st, 2);
 	TBL_PC *sd;
 
-	if (!script_nick2sd(3,sd)) {
-		script_pushint(st,-1);
-		return SCRIPT_CMD_FAILURE;
+	if( script_hasdata(st, 3) ){
+		if( script_isint(st, 3) ){
+			if( !script_charid2sd(3, sd) ){
+				script_pushint(st, -1);
+				return SCRIPT_CMD_FAILURE;
+			}
+		}else{
+			if( !script_nick2sd(3, sd) ){
+				script_pushint(st, -1);
+				return SCRIPT_CMD_FAILURE;
+			}
+		}
 	}
 
 	// If you use a parameter, return the value behind it
@@ -21266,6 +21276,15 @@ BUILDIN_FUNC(getvar) {
 	}
 
 	name = reference_getname(data);
+
+	if (reference_toparam(data)) {
+		ShowError("buildin_getvar: '%s' is a parameter - please use readparam instead\n", name);
+		script_reportdata(data);
+		script_pushnil(st);
+		st->state = END;
+		return SCRIPT_CMD_FAILURE;
+	}
+
 	if (name[0] == '.' || name[0] == '$' || name[0] == '\'') { // Not a PC variable
 		ShowError("buildin_getvar: Invalid scope (not PC variable)\n");
 		script_reportdata(data);