diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 66b7e9a2cd8..1c4bb8aa3ab 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -4147,33 +4147,23 @@ Example: --------------------------------------- -*getguildmember({, }); +*getguildmember(, , ); -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 -of temporary global variables. - -Upon executing this, - -$@guildmembername$[] is a global temporary string array which contains all the - names of these guild members. - (only set when type is 0 or not specified) - -$@guildmembercid[] is a global temporary number array which contains the - character id of these guild members. - (only set when type is 1) +This command will find all members of a specified , copy their +names (or character id or account id) depending on the into +and returns the number of guild members that were found. -$@guildmemberaid[] is a global temporary number array which contains the - account id of these guild members. - (only set when type is 2) +Valid are: -$@guildmembercount is the number of guild members that were found. + GD_MEMBER_NAME - Guild member names + GD_MEMBER_CHARID - Guild member character ID + GD_MEMBER_ACCID - Guild member account ID The guild members will be found regardless of whether they are online or offline. -Note that the names come in no particular order. +Note that the results 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(). +Make sure to use string variable for GD_MEMBER_NAME and +int variable for GD_MEMBER_CHARID and GD_MEMBER_ACCID For usage examples, see getpartymember(). diff --git a/src/map/script.c b/src/map/script.c index 4654a7124b1..8ecddd7fc43 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -10128,44 +10128,76 @@ static BUILDIN(getguildinfo) /*========================================== * Get the information of the members of a guild by type. - * getguildmember {,}; - * @param guild_id: ID of guild - * @param type: - * 0 : name (default) - * 1 : character ID - * 2 : account ID + * getguildmember(, , ); *------------------------------------------*/ static BUILDIN(getguildmember) { - struct guild *g = NULL; - int j = 0; + struct map_session_data *sd = NULL; + struct guild *g = guild->search(script_getnum(st, 2)); + enum guildmember_type type = script_getnum(st, 3); + struct script_data *data = script_getdata(st, 4); + const char *varname = reference_getname(data); + int id = reference_getid(data); + int num = 0; - g = guild->search(script_getnum(st,2)); + if (!data_isreference(data) || reference_toconstant(data)) { + ShowError("buildin_getguildmember: Target argument is not a variable\n"); + script->reportdata(data); + st->state = END; + return false; + } + + if (type < GD_MEMBER_NAME || type > GD_MEMBER_ACCID) { + ShowError("buildin_getguildmember: Invalid type argument\n"); + script->reportdata(data); + st->state = END; + return false; + } - if (g) { - int i, type = 0; + if (!is_int_variable(varname) && (type == GD_MEMBER_CHARID || type == GD_MEMBER_ACCID)) { + ShowError("buildin_getguildmember: Target argument is not an int variable\n"); + script->reportdata(data); + st->state = END; + return false; + } + + if (!is_string_variable(varname) && type == GD_MEMBER_NAME) { + ShowError("buildin_getguildmember: Target argument is not a string variable\n"); + script->reportdata(data); + st->state = END; + return false; + } - if (script_hasdata(st,3)) - type = script_getnum(st,3); + if (not_server_variable(*varname)) { + sd = script->rid2sd(st); + + if (sd == NULL) { + script_pushint(st, 0); + return true; // player variable but no player attached + } + } - for ( i = 0; i < MAX_GUILD; i++ ) { - if ( g->member[i].account_id ) { + if (g != NULL) { + for (int i = 0; i < MAX_GUILD; i++) { + if (g->member[i].account_id != 0) { switch (type) { - case 2: - mapreg->setreg(reference_uid(script->add_variable("$@guildmemberaid"), j),g->member[i].account_id); + case GD_MEMBER_NAME: + script->set_reg(st, sd, reference_uid(id, num), varname, (const void *)h64BPTRSIZE(g->member[i].name), reference_getref(data)); break; - case 1: - mapreg->setreg(reference_uid(script->add_variable("$@guildmembercid"), j), g->member[i].char_id); + case GD_MEMBER_CHARID: + script->set_reg(st, sd, reference_uid(id, num), varname, (const void *)h64BPTRSIZE(g->member[i].char_id), reference_getref(data)); break; - default: - mapreg->setregstr(reference_uid(script->add_variable("$@guildmembername$"), j), g->member[i].name); + case GD_MEMBER_ACCID: + script->set_reg(st, sd, reference_uid(id, num), varname, (const void *)h64BPTRSIZE(g->member[i].account_id), reference_getref(data)); break; } - j++; + num++; } } } - mapreg->setreg(script->add_variable("$@guildmembercount"), j); + + script_pushint(st, num); + return true; } @@ -28903,7 +28935,7 @@ static void script_parse_builtin(void) BUILDIN_DEF(getpartyname,"i"), BUILDIN_DEF(getpartymember,"iir"), BUILDIN_DEF(getpartyleader,"i?"), - BUILDIN_DEF(getguildmember,"i?"), + BUILDIN_DEF(getguildmember,"iir"), BUILDIN_DEF(getguildinfo,"i?"), BUILDIN_DEF(getguildonline, "i?"), BUILDIN_DEF(strcharinfo,"i??"), @@ -30155,7 +30187,12 @@ static void script_hardcoded_constants(void) script->set_constant("SIEGE_TYPE_SE", SIEGE_TYPE_SE, false, false); script->set_constant("SIEGE_TYPE_TE", SIEGE_TYPE_TE, false, false); - script->constdb_comment("partymember types"); + script->constdb_comment("guildmember types"); + script->set_constant("GD_MEMBER_NAME", GD_MEMBER_NAME, false, false); + script->set_constant("GD_MEMBER_CHARID", GD_MEMBER_CHARID, false, false); + script->set_constant("GD_MEMBER_ACCID", GD_MEMBER_ACCID, false, false); + + script->constdb_comment("partymember types"); script->set_constant("PT_MEMBER_NAME", PT_MEMBER_NAME, false, false); script->set_constant("PT_MEMBER_CHARID", PT_MEMBER_CHARID, false, false); script->set_constant("PT_MEMBER_ACCID", PT_MEMBER_ACCID, false, false); diff --git a/src/map/script.h b/src/map/script.h index 78e70b0080d..e74b5169262 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -619,6 +619,12 @@ enum script_hominfo_types { HOMINFO_MAX }; +enum guildmember_type { + GD_MEMBER_NAME, + GD_MEMBER_CHARID, + GD_MEMBER_ACCID, +}; + enum partymember_type { PT_MEMBER_NAME, PT_MEMBER_CHARID,