Browse Source

Fixed a bug with getarraysize

When the attached rid of the script was actually not a player, but a monster or something else the script was terminated. A good example for this was to use getarraysize on a OnTouchNPC event.

Thanks to MasterOfMuppets(@Locien) for reporting this.
Lemongrass3110 8 năm trước cách đây
mục cha
commit
d13acf3886
1 tập tin đã thay đổi với 11 bổ sung1 xóa
  1. 11 1
      src/map/script.c

+ 11 - 1
src/map/script.c

@@ -6217,6 +6217,8 @@ BUILDIN_FUNC(copyarray)
 BUILDIN_FUNC(getarraysize)
 {
 	struct script_data* data;
+	const char* name;
+	struct map_session_data* sd = NULL;
 
 	data = script_getdata(st, 2);
 	if( !data_isreference(data) )
@@ -6228,7 +6230,15 @@ BUILDIN_FUNC(getarraysize)
 		return SCRIPT_CMD_FAILURE;// not a variable
 	}
 
-	script_pushint(st, script_array_highest_key(st, st->rid ? script_rid2sd(st) : NULL, reference_getname(data), reference_getref(data)));
+	name = reference_getname(data);
+
+	if( not_server_variable(*name) ){
+		sd = script_rid2sd(st);
+		if (sd == NULL)
+			return SCRIPT_CMD_SUCCESS;// no player attached
+	}
+
+	script_pushint(st, script_array_highest_key(st, sd, reference_getname(data), reference_getref(data)));
 	return SCRIPT_CMD_SUCCESS;
 }