Przeglądaj źródła

* Fixed #607:
* Added array variable option in 3rd param of `getguildmember` and `getpartymember`, so the script will returns the result in reserved array instead using temporary global variable.
* Also, the script returns the member found directly.

Signed-off-by: Cydh Ramdh <cydh@pservero.com>

Cydh Ramdh 9 lat temu
rodzic
commit
31505d1423
2 zmienionych plików z 77 dodań i 22 usunięć
  1. 8 2
      doc/script_commands.txt
  2. 69 20
      src/map/script.c

+ 8 - 2
doc/script_commands.txt

@@ -3041,7 +3041,7 @@ Example:
 
 ---------------------------------------
 
-*getguildmember <guild id>{,<type>};
+*getguildmember <guild id>{,<type>{,<array_variable>}};
 
 This command will find all members of a specified guild and returns their names 
 (or character id or account id depending on the value of "type") into an array
@@ -3069,6 +3069,9 @@ Note that the names come in no particular order.
 Be sure to use $@guildmembercount to go through this array, and not 
 'getarraysize', because it is not cleared between runs of 'getguildmember'.
 
+If 'array_variable' is set, the result will be stored to that variable instead
+using global variable.
+
 For usage examples, see 'getpartymember'.
 
 ---------------------------------------
@@ -8515,7 +8518,7 @@ Lets say the ID of a party was saved as a global variable:
 
 ---------------------------------------
 
-*getpartymember <party id>{,<type>};
+*getpartymember <party id>{,<type>{,<array_variable>}};
 
 This command will find all members of a specified party and returns their names 
 (or character id or account id depending on the value of "type") into an array
@@ -8552,6 +8555,9 @@ call remain, and you will get 5+2 members, of which the last 2 don't belong to
 the new guy's party. $@partymembercount will always contain the correct number, 
 (5) unlike 'getarraysize()' which will return 7 in this case.
 
+If 'array_variable' is set, the result will be stored to that variable instead
+using global variable.
+
 Example 1: list party member names
 
 	// get the party member names

+ 69 - 20
src/map/script.c

@@ -7860,28 +7860,51 @@ BUILDIN_FUNC(getpartyname)
 BUILDIN_FUNC(getpartymember)
 {
 	struct party_data *p;
-	unsigned char j = 0;
+	uint8 j = 0;
 
 	p = party_search(script_getnum(st,2));
 
 	if (p != NULL) {
-		int type = 0;
-		unsigned char i;
+		uint8 i, type = 0;
+		struct script_data *data = NULL;
+		char *varname = NULL;
 
 		if (script_hasdata(st,3))
  			type = script_getnum(st,3);
 
+		if (script_hasdata(st,4)) {
+			data = script_getdata(st, 4);
+			if (!data_isreference(data)) {
+				ShowError("buildin_getpartymember: Error in argument! Please give a variable to store values in.\n");
+				return SCRIPT_CMD_FAILURE;
+			}
+			varname = reference_getname(data);
+			if (type <= 0 && varname[strlen(varname)-1] != '$') {
+				ShowError("buildin_getpartymember: The array %s is not string type.\n", varname);
+				return SCRIPT_CMD_FAILURE;
+			}
+		}
+
 		for (i = 0; i < MAX_PARTY; i++) {
 			if (p->party.member[i].account_id) {
 				switch (type) {
 					case 2:
-						mapreg_setreg(reference_uid(add_str("$@partymemberaid"), j),p->party.member[i].account_id);
+						if (data)
+							setd_sub(st, NULL, varname, j, (void *)__64BPRTSIZE(p->party.member[i].account_id), data->ref);
+						else
+							mapreg_setreg(reference_uid(add_str("$@partymemberaid"), j),p->party.member[i].account_id);
 						break;
 					case 1:
-						mapreg_setreg(reference_uid(add_str("$@partymembercid"), j),p->party.member[i].char_id);
+						if (data)
+							setd_sub(st, NULL, varname, j, (void *)__64BPRTSIZE(p->party.member[i].char_id), data->ref);
+						else
+							mapreg_setreg(reference_uid(add_str("$@partymembercid"), j),p->party.member[i].char_id);
 						break;
 					default:
-						mapreg_setregstr(reference_uid(add_str("$@partymembername$"), j),p->party.member[i].name);
+						if (data)
+							setd_sub(st, NULL, varname, j, (void *)__64BPRTSIZE(p->party.member[i].name), data->ref);
+						else
+							mapreg_setregstr(reference_uid(add_str("$@partymembername$"), j),p->party.member[i].name);
 						break;
 				}
 
@@ -7891,6 +7914,7 @@ BUILDIN_FUNC(getpartymember)
 	}
 
 	mapreg_setreg(add_str("$@partymembercount"),j);
+	script_pushint(st, j);
 	return SCRIPT_CMD_SUCCESS;
 }
 
@@ -20246,35 +20270,60 @@ BUILDIN_FUNC(disable_command) {
  */
 BUILDIN_FUNC(getguildmember)
 {
-	unsigned char j = 0;
 	struct guild *g = NULL;
+	uint8 j = 0;
 
 	g = guild_search(script_getnum(st,2));
 
 	if (g) {
-		unsigned char i, type = 0;
+		uint8 i, type = 0;
+		struct script_data *data = NULL;
+		char *varname = NULL;
 
 		if (script_hasdata(st,3))
-			type = (unsigned char)script_getnum(st,3);
+ 			type = script_getnum(st,3);
+
+		if (script_hasdata(st,4)) {
+			data = script_getdata(st, 4);
+			if (!data_isreference(data)) {
+				ShowError("buildin_getguildmember: Error in argument! Please give a variable to store values in.\n");
+				return SCRIPT_CMD_FAILURE;
+			}
+			varname = reference_getname(data);
+			if (type <= 0 && varname[strlen(varname)-1] != '$') {
+				ShowError("buildin_getguildmember: The array %s is not string type.\n", varname);
+				return SCRIPT_CMD_FAILURE;
+			}
+		}
 
 		for (i = 0; i < MAX_GUILD; i++) {
 			if (g->member[i].account_id) {
 				switch (type) {
-				case 2:
-					mapreg_setreg(reference_uid(add_str("$@guildmemberaid"), j),g->member[i].account_id);
-					break;
-				case 1:
-					mapreg_setreg(reference_uid(add_str("$@guildmembercid"), j), g->member[i].char_id);
-					break;
-				default:
-					mapreg_setregstr(reference_uid(add_str("$@guildmembername$"), j), g->member[i].name);
-					break;
+					case 2:
+						if (data)
+							setd_sub(st, NULL, varname, j, (void *)__64BPRTSIZE(g->member[i].account_id), data->ref);
+						else
+							mapreg_setreg(reference_uid(add_str("$@guildmemberaid"), j),g->member[i].account_id);
+						break;
+					case 1:
+						if (data)
+							setd_sub(st, NULL, varname, j, (void *)__64BPRTSIZE(g->member[i].char_id), data->ref);
+						else
+							mapreg_setreg(reference_uid(add_str("$@guildmembercid"), j), g->member[i].char_id);
+						break;
+					default:
+						if (data)
+							setd_sub(st, NULL, varname, j, (void *)__64BPRTSIZE(g->member[i].name), data->ref);
+						else
+							mapreg_setregstr(reference_uid(add_str("$@guildmembername$"), j), g->member[i].name);
+						break;
 				}
 				j++;
 			}
 		}
 	}
 	mapreg_setreg(add_str("$@guildmembercount"), j);
+	script_pushint(st, j);
 	return SCRIPT_CMD_SUCCESS;
 }
 
@@ -20725,7 +20774,7 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(getcharid,"i?"),
 	BUILDIN_DEF(getnpcid,"i?"),
 	BUILDIN_DEF(getpartyname,"i"),
-	BUILDIN_DEF(getpartymember,"i?"),
+	BUILDIN_DEF(getpartymember,"i??"),
 	BUILDIN_DEF(getpartyleader,"i?"),
 	BUILDIN_DEF(getguildname,"i"),
 	BUILDIN_DEF(getguildmaster,"i"),
@@ -21159,7 +21208,7 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(getgroupitem,"i"),
 	BUILDIN_DEF(enable_command,""),
 	BUILDIN_DEF(disable_command,""),
-	BUILDIN_DEF(getguildmember,"i?"),
+	BUILDIN_DEF(getguildmember,"i??"),
 	BUILDIN_DEF(addspiritball,"ii?"),
 	BUILDIN_DEF(delspiritball,"i?"),
 	BUILDIN_DEF(countspiritball,"?"),