Skip to content

Commit 9c48f4f

Browse files
committed
getpartymember update
getpartymember(<party_id>, <type>, <array>); Will now accept any array as argument Value returned is the member count Uses constants: PT_MEMBER_NAME PT_MEMBER_CHARID PT_MEMBER_ACCID sample usage: .@count = getpartymember(getcharid(CHAR_ID_PARTY, PT_MEMBER_NAME, .@name$);
1 parent 5f7eaa4 commit 9c48f4f

File tree

2 files changed

+63
-25
lines changed

2 files changed

+63
-25
lines changed

src/map/script.c

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9920,41 +9920,68 @@ static BUILDIN(getpartyname)
99209920

99219921
/*==========================================
99229922
* Get the information of the members of a party by type
9923-
* @party_id, @type
9924-
* return by @type :
9925-
* - : nom des membres
9926-
* 1 : char_id des membres
9927-
* 2 : account_id des membres
9923+
* getpartymember(<party_id>, <type>, <array>);
99289924
*------------------------------------------*/
99299925
static BUILDIN(getpartymember)
99309926
{
9931-
struct party_data *p;
9932-
int j=0,type=0;
9927+
struct map_session_data *sd = NULL;
9928+
struct party_data *p = party->search(script_getnum(st, 2));
9929+
enum partymember_type type = script_getnum(st, 3);
9930+
struct script_data *data = script_getdata(st, 4);
9931+
const char *varname = reference_getname(data);
9932+
int id = reference_getid(data);
9933+
int num = 0;
99339934

9934-
p=party->search(script_getnum(st,2));
9935+
if (!data_isreference(data) || reference_toconstant(data)) {
9936+
ShowError("buildin_getpartymember: Target argument is not a variable\n");
9937+
script->reportdata(data);
9938+
st->state = END;
9939+
return false;
9940+
}
9941+
9942+
if (!is_int_variable(varname) && (type == PT_MEMBER_CHARID || type == PT_MEMBER_ACCID)) {
9943+
ShowError("buildin_getpartymember: Target argument is not an int variable\n");
9944+
script->reportdata(data);
9945+
st->state = END;
9946+
return false;
9947+
}
99359948

9936-
if (script_hasdata(st,3))
9937-
type=script_getnum(st,3);
9949+
if (!is_string_variable(varname) && type == PT_MEMBER_NAME) {
9950+
ShowError("buildin_getpartymember: Target argument is not a string variable\n");
9951+
script->reportdata(data);
9952+
st->state = END;
9953+
return false;
9954+
}
99389955

9939-
if ( p != NULL) {
9940-
int i;
9941-
for (i = 0; i < MAX_PARTY; i++) {
9942-
if(p->party.member[i].account_id) {
9956+
if (not_server_variable(*varname)) {
9957+
sd = script->rid2sd(st);
9958+
9959+
if (sd == NULL) {
9960+
script_pushint(st, 0);
9961+
return true; // player variable but no player attached
9962+
}
9963+
}
9964+
9965+
if (p) {
9966+
for (int i = 0; i < MAX_PARTY; i++) {
9967+
if (p->party.member[i].account_id) {
99439968
switch (type) {
9944-
case 2:
9945-
mapreg->setreg(reference_uid(script->add_variable("$@partymemberaid"), j),p->party.member[i].account_id);
9946-
break;
9947-
case 1:
9948-
mapreg->setreg(reference_uid(script->add_variable("$@partymembercid"), j),p->party.member[i].char_id);
9949-
break;
9950-
default:
9951-
mapreg->setregstr(reference_uid(script->add_variable("$@partymembername$"), j),p->party.member[i].name);
9969+
case PT_MEMBER_NAME:
9970+
script->set_reg(st, sd, reference_uid(id, num), varname, (const void *)h64BPTRSIZE(p->party.member[i].name), reference_getref(data));
9971+
break;
9972+
case PT_MEMBER_CHARID:
9973+
script->set_reg(st, sd, reference_uid(id, num), varname, (const void *)h64BPTRSIZE(p->party.member[i].char_id), reference_getref(data));
9974+
break;
9975+
case PT_MEMBER_ACCID:
9976+
script->set_reg(st, sd, reference_uid(id, num), varname, (const void *)h64BPTRSIZE(p->party.member[i].account_id), reference_getref(data));
9977+
break;
99529978
}
9953-
j++;
9979+
num++;
99549980
}
99559981
}
99569982
}
9957-
mapreg->setreg(script->add_variable("$@partymembercount"),j);
9983+
9984+
script_pushint(st, num);
99589985

99599986
return true;
99609987
}
@@ -28867,7 +28894,7 @@ static void script_parse_builtin(void)
2886728894
BUILDIN_DEF(setdialogpos, "ii"),
2886828895
BUILDIN_DEF(setdialogpospercent, "ii"),
2886928896
BUILDIN_DEF(getpartyname,"i"),
28870-
BUILDIN_DEF(getpartymember,"i?"),
28897+
BUILDIN_DEF(getpartymember,"iir"),
2887128898
BUILDIN_DEF(getpartyleader,"i?"),
2887228899
BUILDIN_DEF(getguildmember,"i?"),
2887328900
BUILDIN_DEF(getguildinfo,"i?"),
@@ -30121,6 +30148,11 @@ static void script_hardcoded_constants(void)
3012130148
script->set_constant("SIEGE_TYPE_SE", SIEGE_TYPE_SE, false, false);
3012230149
script->set_constant("SIEGE_TYPE_TE", SIEGE_TYPE_TE, false, false);
3012330150

30151+
script->constdb_comment("partymember types");
30152+
script->set_constant("PT_MEMBER_NAME", PT_MEMBER_NAME, false, false);
30153+
script->set_constant("PT_MEMBER_CHARID", PT_MEMBER_CHARID, false, false);
30154+
script->set_constant("PT_MEMBER_ACCID", PT_MEMBER_ACCID, false, false);
30155+
3012430156
script->constdb_comment("guildinfo types");
3012530157
script->set_constant("GUILDINFO_NAME", GUILDINFO_NAME, false, false);
3012630158
script->set_constant("GUILDINFO_ID", GUILDINFO_ID, false, false);

src/map/script.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,12 @@ enum script_hominfo_types {
619619
HOMINFO_MAX
620620
};
621621

622+
enum partymember_type {
623+
PT_MEMBER_NAME,
624+
PT_MEMBER_CHARID,
625+
PT_MEMBER_ACCID,
626+
};
627+
622628
/**
623629
* Structures
624630
**/

0 commit comments

Comments
 (0)