Skip to content

Commit

Permalink
getpartymember update
Browse files Browse the repository at this point in the history
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$);
  • Loading branch information
jasonch35 committed Jul 27, 2024
1 parent 5f7eaa4 commit 9c48f4f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 25 deletions.
82 changes: 57 additions & 25 deletions src/map/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -9920,41 +9920,68 @@ static BUILDIN(getpartyname)

/*==========================================
* Get the information of the members of a party by type
* @party_id, @type
* return by @type :
* - : nom des membres
* 1 : char_id des membres
* 2 : account_id des membres
* getpartymember(<party_id>, <type>, <array>);
*------------------------------------------*/
static BUILDIN(getpartymember)
{
struct party_data *p;
int j=0,type=0;
struct map_session_data *sd = NULL;
struct party_data *p = party->search(script_getnum(st, 2));
enum partymember_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;

p=party->search(script_getnum(st,2));
if (!data_isreference(data) || reference_toconstant(data)) {
ShowError("buildin_getpartymember: Target argument is not a variable\n");
script->reportdata(data);
st->state = END;
return false;
}

if (!is_int_variable(varname) && (type == PT_MEMBER_CHARID || type == PT_MEMBER_ACCID)) {
ShowError("buildin_getpartymember: Target argument is not an int variable\n");
script->reportdata(data);
st->state = END;
return false;
}

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

if ( p != NULL) {
int i;
for (i = 0; i < MAX_PARTY; i++) {
if(p->party.member[i].account_id) {
if (not_server_variable(*varname)) {
sd = script->rid2sd(st);

if (sd == NULL) {
script_pushint(st, 0);
return true; // player variable but no player attached
}
}

if (p) {
for (int i = 0; i < MAX_PARTY; i++) {
if (p->party.member[i].account_id) {
switch (type) {
case 2:
mapreg->setreg(reference_uid(script->add_variable("$@partymemberaid"), j),p->party.member[i].account_id);
break;
case 1:
mapreg->setreg(reference_uid(script->add_variable("$@partymembercid"), j),p->party.member[i].char_id);
break;
default:
mapreg->setregstr(reference_uid(script->add_variable("$@partymembername$"), j),p->party.member[i].name);
case PT_MEMBER_NAME:
script->set_reg(st, sd, reference_uid(id, num), varname, (const void *)h64BPTRSIZE(p->party.member[i].name), reference_getref(data));
break;
case PT_MEMBER_CHARID:
script->set_reg(st, sd, reference_uid(id, num), varname, (const void *)h64BPTRSIZE(p->party.member[i].char_id), reference_getref(data));
break;
case PT_MEMBER_ACCID:
script->set_reg(st, sd, reference_uid(id, num), varname, (const void *)h64BPTRSIZE(p->party.member[i].account_id), reference_getref(data));
break;
}
j++;
num++;
}
}
}
mapreg->setreg(script->add_variable("$@partymembercount"),j);

script_pushint(st, num);

return true;
}
Expand Down Expand Up @@ -28867,7 +28894,7 @@ static void script_parse_builtin(void)
BUILDIN_DEF(setdialogpos, "ii"),
BUILDIN_DEF(setdialogpospercent, "ii"),
BUILDIN_DEF(getpartyname,"i"),
BUILDIN_DEF(getpartymember,"i?"),
BUILDIN_DEF(getpartymember,"iir"),
BUILDIN_DEF(getpartyleader,"i?"),
BUILDIN_DEF(getguildmember,"i?"),
BUILDIN_DEF(getguildinfo,"i?"),
Expand Down Expand Up @@ -30121,6 +30148,11 @@ 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->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);

script->constdb_comment("guildinfo types");
script->set_constant("GUILDINFO_NAME", GUILDINFO_NAME, false, false);
script->set_constant("GUILDINFO_ID", GUILDINFO_ID, false, false);
Expand Down
6 changes: 6 additions & 0 deletions src/map/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,12 @@ enum script_hominfo_types {
HOMINFO_MAX
};

enum partymember_type {
PT_MEMBER_NAME,
PT_MEMBER_CHARID,
PT_MEMBER_ACCID,
};

/**
* Structures
**/
Expand Down

0 comments on commit 9c48f4f

Please sign in to comment.