Skip to content

Commit 5a38450

Browse files
Merge pull request #3305 from jasonch35/getpartymember-upgrade
`getpartymember` upgrade
2 parents 216c752 + 84569df commit 5a38450

File tree

2 files changed

+70
-25
lines changed

2 files changed

+70
-25
lines changed

src/map/script.c

+64-25
Original file line numberDiff line numberDiff line change
@@ -9920,41 +9920,75 @@ 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+
}
99359941

9936-
if (script_hasdata(st,3))
9937-
type=script_getnum(st,3);
9942+
if (type < PT_MEMBER_NAME || type > PT_MEMBER_ACCID) {
9943+
ShowError("buildin_getpartymember: Invalid type argument\n");
9944+
script->reportdata(data);
9945+
st->state = END;
9946+
return false;
9947+
}
9948+
9949+
if (!is_int_variable(varname) && (type == PT_MEMBER_CHARID || type == PT_MEMBER_ACCID)) {
9950+
ShowError("buildin_getpartymember: Target argument is not an int 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 (!is_string_variable(varname) && type == PT_MEMBER_NAME) {
9957+
ShowError("buildin_getpartymember: Target argument is not a string variable\n");
9958+
script->reportdata(data);
9959+
st->state = END;
9960+
return false;
9961+
}
9962+
9963+
if (not_server_variable(*varname)) {
9964+
sd = script->rid2sd(st);
9965+
9966+
if (sd == NULL) {
9967+
script_pushint(st, 0);
9968+
return true; // player variable but no player attached
9969+
}
9970+
}
9971+
9972+
if (p != NULL) {
9973+
for (int i = 0; i < MAX_PARTY; i++) {
9974+
if (p->party.member[i].account_id != 0) {
99439975
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);
9976+
case PT_MEMBER_NAME:
9977+
script->set_reg(st, sd, reference_uid(id, num), varname, (const void *)h64BPTRSIZE(p->party.member[i].name), reference_getref(data));
9978+
break;
9979+
case PT_MEMBER_CHARID:
9980+
script->set_reg(st, sd, reference_uid(id, num), varname, (const void *)h64BPTRSIZE(p->party.member[i].char_id), reference_getref(data));
9981+
break;
9982+
case PT_MEMBER_ACCID:
9983+
script->set_reg(st, sd, reference_uid(id, num), varname, (const void *)h64BPTRSIZE(p->party.member[i].account_id), reference_getref(data));
9984+
break;
99529985
}
9953-
j++;
9986+
num++;
99549987
}
99559988
}
99569989
}
9957-
mapreg->setreg(script->add_variable("$@partymembercount"),j);
9990+
9991+
script_pushint(st, num);
99589992

99599993
return true;
99609994
}
@@ -28867,7 +28901,7 @@ static void script_parse_builtin(void)
2886728901
BUILDIN_DEF(setdialogpos, "ii"),
2886828902
BUILDIN_DEF(setdialogpospercent, "ii"),
2886928903
BUILDIN_DEF(getpartyname,"i"),
28870-
BUILDIN_DEF(getpartymember,"i?"),
28904+
BUILDIN_DEF(getpartymember,"iir"),
2887128905
BUILDIN_DEF(getpartyleader,"i?"),
2887228906
BUILDIN_DEF(getguildmember,"i?"),
2887328907
BUILDIN_DEF(getguildinfo,"i?"),
@@ -30121,6 +30155,11 @@ static void script_hardcoded_constants(void)
3012130155
script->set_constant("SIEGE_TYPE_SE", SIEGE_TYPE_SE, false, false);
3012230156
script->set_constant("SIEGE_TYPE_TE", SIEGE_TYPE_TE, false, false);
3012330157

30158+
script->constdb_comment("partymember types");
30159+
script->set_constant("PT_MEMBER_NAME", PT_MEMBER_NAME, false, false);
30160+
script->set_constant("PT_MEMBER_CHARID", PT_MEMBER_CHARID, false, false);
30161+
script->set_constant("PT_MEMBER_ACCID", PT_MEMBER_ACCID, false, false);
30162+
3012430163
script->constdb_comment("guildinfo types");
3012530164
script->set_constant("GUILDINFO_NAME", GUILDINFO_NAME, false, false);
3012630165
script->set_constant("GUILDINFO_ID", GUILDINFO_ID, 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 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)