Skip to content

Commit 05036bf

Browse files
Merge pull request #3318 from HerculesWS/getguildmember
getguildmember updates
2 parents 17cd588 + 7cd029a commit 05036bf

File tree

3 files changed

+79
-46
lines changed

3 files changed

+79
-46
lines changed

doc/script_commands.txt

+11-21
Original file line numberDiff line numberDiff line change
@@ -4147,33 +4147,23 @@ Example:
41474147

41484148
---------------------------------------
41494149

4150-
*getguildmember(<guild id>{, <type>});
4150+
*getguildmember(<guild id>, <type>, <array>);
41514151

4152-
This command will find all members of a specified guild and returns their names
4153-
(or character id or account id depending on the value of "type") into an array
4154-
of temporary global variables.
4155-
4156-
Upon executing this,
4157-
4158-
$@guildmembername$[] is a global temporary string array which contains all the
4159-
names of these guild members.
4160-
(only set when type is 0 or not specified)
4161-
4162-
$@guildmembercid[] is a global temporary number array which contains the
4163-
character id of these guild members.
4164-
(only set when type is 1)
4152+
This command will find all members of a specified <guild_id>, copy their
4153+
names (or character id or account id) depending on the <type> into <array>
4154+
and returns the number of guild members that were found.
41654155

4166-
$@guildmemberaid[] is a global temporary number array which contains the
4167-
account id of these guild members.
4168-
(only set when type is 2)
4156+
Valid <type> are:
41694157

4170-
$@guildmembercount is the number of guild members that were found.
4158+
GD_MEMBER_NAME - Guild member names
4159+
GD_MEMBER_CHARID - Guild member character ID
4160+
GD_MEMBER_ACCID - Guild member account ID
41714161

41724162
The guild members will be found regardless of whether they are online or offline.
4173-
Note that the names come in no particular order.
4163+
Note that the results come in no particular order.
41744164

4175-
Be sure to use $@guildmembercount to go through this array, and not
4176-
getarraysize(), because it is not cleared between runs of getguildmember().
4165+
Make sure to use string variable for GD_MEMBER_NAME and
4166+
int variable for GD_MEMBER_CHARID and GD_MEMBER_ACCID
41774167

41784168
For usage examples, see getpartymember().
41794169

src/map/script.c

+62-25
Original file line numberDiff line numberDiff line change
@@ -10128,44 +10128,76 @@ static BUILDIN(getguildinfo)
1012810128

1012910129
/*==========================================
1013010130
* Get the information of the members of a guild by type.
10131-
* getguildmember <guild_id>{,<type>};
10132-
* @param guild_id: ID of guild
10133-
* @param type:
10134-
* 0 : name (default)
10135-
* 1 : character ID
10136-
* 2 : account ID
10131+
* getguildmember(<guild_id>, <type>, <array>);
1013710132
*------------------------------------------*/
1013810133
static BUILDIN(getguildmember)
1013910134
{
10140-
struct guild *g = NULL;
10141-
int j = 0;
10135+
struct map_session_data *sd = NULL;
10136+
struct guild *g = guild->search(script_getnum(st, 2));
10137+
enum guildmember_type type = script_getnum(st, 3);
10138+
struct script_data *data = script_getdata(st, 4);
10139+
const char *varname = reference_getname(data);
10140+
int id = reference_getid(data);
10141+
int num = 0;
1014210142

10143-
g = guild->search(script_getnum(st,2));
10143+
if (!data_isreference(data) || reference_toconstant(data)) {
10144+
ShowError("buildin_getguildmember: Target argument is not a variable\n");
10145+
script->reportdata(data);
10146+
st->state = END;
10147+
return false;
10148+
}
10149+
10150+
if (type < GD_MEMBER_NAME || type > GD_MEMBER_ACCID) {
10151+
ShowError("buildin_getguildmember: Invalid type argument\n");
10152+
script->reportdata(data);
10153+
st->state = END;
10154+
return false;
10155+
}
1014410156

10145-
if (g) {
10146-
int i, type = 0;
10157+
if (!is_int_variable(varname) && (type == GD_MEMBER_CHARID || type == GD_MEMBER_ACCID)) {
10158+
ShowError("buildin_getguildmember: Target argument is not an int variable\n");
10159+
script->reportdata(data);
10160+
st->state = END;
10161+
return false;
10162+
}
10163+
10164+
if (!is_string_variable(varname) && type == GD_MEMBER_NAME) {
10165+
ShowError("buildin_getguildmember: Target argument is not a string variable\n");
10166+
script->reportdata(data);
10167+
st->state = END;
10168+
return false;
10169+
}
1014710170

10148-
if (script_hasdata(st,3))
10149-
type = script_getnum(st,3);
10171+
if (not_server_variable(*varname)) {
10172+
sd = script->rid2sd(st);
10173+
10174+
if (sd == NULL) {
10175+
script_pushint(st, 0);
10176+
return true; // player variable but no player attached
10177+
}
10178+
}
1015010179

10151-
for ( i = 0; i < MAX_GUILD; i++ ) {
10152-
if ( g->member[i].account_id ) {
10180+
if (g != NULL) {
10181+
for (int i = 0; i < MAX_GUILD; i++) {
10182+
if (g->member[i].account_id != 0) {
1015310183
switch (type) {
10154-
case 2:
10155-
mapreg->setreg(reference_uid(script->add_variable("$@guildmemberaid"), j),g->member[i].account_id);
10184+
case GD_MEMBER_NAME:
10185+
script->set_reg(st, sd, reference_uid(id, num), varname, (const void *)h64BPTRSIZE(g->member[i].name), reference_getref(data));
1015610186
break;
10157-
case 1:
10158-
mapreg->setreg(reference_uid(script->add_variable("$@guildmembercid"), j), g->member[i].char_id);
10187+
case GD_MEMBER_CHARID:
10188+
script->set_reg(st, sd, reference_uid(id, num), varname, (const void *)h64BPTRSIZE(g->member[i].char_id), reference_getref(data));
1015910189
break;
10160-
default:
10161-
mapreg->setregstr(reference_uid(script->add_variable("$@guildmembername$"), j), g->member[i].name);
10190+
case GD_MEMBER_ACCID:
10191+
script->set_reg(st, sd, reference_uid(id, num), varname, (const void *)h64BPTRSIZE(g->member[i].account_id), reference_getref(data));
1016210192
break;
1016310193
}
10164-
j++;
10194+
num++;
1016510195
}
1016610196
}
1016710197
}
10168-
mapreg->setreg(script->add_variable("$@guildmembercount"), j);
10198+
10199+
script_pushint(st, num);
10200+
1016910201
return true;
1017010202
}
1017110203

@@ -28903,7 +28935,7 @@ static void script_parse_builtin(void)
2890328935
BUILDIN_DEF(getpartyname,"i"),
2890428936
BUILDIN_DEF(getpartymember,"iir"),
2890528937
BUILDIN_DEF(getpartyleader,"i?"),
28906-
BUILDIN_DEF(getguildmember,"i?"),
28938+
BUILDIN_DEF(getguildmember,"iir"),
2890728939
BUILDIN_DEF(getguildinfo,"i?"),
2890828940
BUILDIN_DEF(getguildonline, "i?"),
2890928941
BUILDIN_DEF(strcharinfo,"i??"),
@@ -30155,7 +30187,12 @@ static void script_hardcoded_constants(void)
3015530187
script->set_constant("SIEGE_TYPE_SE", SIEGE_TYPE_SE, false, false);
3015630188
script->set_constant("SIEGE_TYPE_TE", SIEGE_TYPE_TE, false, false);
3015730189

30158-
script->constdb_comment("partymember types");
30190+
script->constdb_comment("guildmember types");
30191+
script->set_constant("GD_MEMBER_NAME", GD_MEMBER_NAME, false, false);
30192+
script->set_constant("GD_MEMBER_CHARID", GD_MEMBER_CHARID, false, false);
30193+
script->set_constant("GD_MEMBER_ACCID", GD_MEMBER_ACCID, false, false);
30194+
30195+
script->constdb_comment("partymember types");
3015930196
script->set_constant("PT_MEMBER_NAME", PT_MEMBER_NAME, false, false);
3016030197
script->set_constant("PT_MEMBER_CHARID", PT_MEMBER_CHARID, false, false);
3016130198
script->set_constant("PT_MEMBER_ACCID", PT_MEMBER_ACCID, false, false);

src/map/script.h

+6
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,12 @@ enum script_hominfo_types {
619619
HOMINFO_MAX
620620
};
621621

622+
enum guildmember_type {
623+
GD_MEMBER_NAME,
624+
GD_MEMBER_CHARID,
625+
GD_MEMBER_ACCID,
626+
};
627+
622628
enum partymember_type {
623629
PT_MEMBER_NAME,
624630
PT_MEMBER_CHARID,

0 commit comments

Comments
 (0)