Skip to content

Commit c00541d

Browse files
Merge pull request #3308 from jasonch35/update-getpartymember-doc
Update getpartymember doc
2 parents 5a38450 + a31f32c commit c00541d

File tree

1 file changed

+20
-93
lines changed

1 file changed

+20
-93
lines changed

doc/script_commands.txt

+20-93
Original file line numberDiff line numberDiff line change
@@ -3000,118 +3000,45 @@ Lets say the ID of a party was saved as a global variable:
30003000

30013001
---------------------------------------
30023002

3003-
*getpartymember(<party id>{, <type>})
3003+
*getpartymember(<party_id>, <type>, <array>)
30043004

3005-
This command will find all members of a specified party and returns their
3006-
names (or character id or account id depending on the value of "type")
3007-
into an array of temporary global variables. There's actually quite a few
3008-
commands like this which will fill a special variable with data upon
3009-
execution and not do anything else.
3005+
This command will find all members of a specified <party_id>, copy their
3006+
names (or character id or account id) depending on the <type> into <array>
3007+
and returns the number of party members that were found.
30103008

3011-
Upon executing this,
3012-
3013-
$@partymembername$[] is a global temporary string array which contains all
3014-
the names of these party members.
3015-
(only set when type is 0 or not specified)
3016-
3017-
$@partymembercid[] is a global temporary number array which contains the
3018-
character id of these party members.
3019-
(only set when type is 1)
3020-
3021-
$@partymemberaid[] is a global temporary number array which contains the
3022-
account id of these party members.
3023-
(only set when type is 2)
3024-
3025-
$@partymembercount is the number of party members that were found.
3009+
Valid <type> are:
30263010

3027-
The party members will (apparently) be found regardless of whether they
3028-
are online or offline. Note that the names come in no particular order.
3011+
PT_MEMBER_NAME - Party member names
3012+
PT_MEMBER_CHARID - Party member character ID
3013+
PT_MEMBER_ACCID - Party member account ID
30293014

3030-
Be sure to use $@partymembercount to go through this array, and not
3031-
'getarraysize', because it is not cleared between runs of 'getpartymember'.
3032-
If someone with 7 party members invokes this script, the array would have
3033-
7 elements. But if another person calls up the NPC, and he has a party of
3034-
5, the server will not clear the array for you, overwriting the values
3035-
instead. So in addition to returning the 5 member names, the 6th and 7th
3036-
elements from the last call remain, and you will get 5+2 members, of which
3037-
the last 2 don't belong to the new guy's party. $@partymembercount will
3038-
always contain the correct number, (5) unlike 'getarraysize()' which will
3039-
return 7 in this case.
3015+
Make sure to use string variable for PT_MEMBER_NAME and
3016+
int variable for PT_MEMBER_CHARID and PT_MEMBER_ACCID
30403017

3041-
Example 1: list party member names
3018+
Example 1: Listing party member names
30423019

30433020
// get the party member names
3044-
getpartymember(getcharid(CHAR_ID_PARTY), 0);
3045-
3046-
// It's a good idea to copy the global temporary $@partymember*****
3047-
// variables to your own scope variables because if you have pauses in
3048-
// this script (sleep, sleep2, next, close2, input, menu, select, or
3049-
// prompt), another player could click this NPC, trigger
3050-
// 'getpartymember', and overwrite the $@partymember***** variables.
3051-
.@count = $@partymembercount;
3052-
copyarray(.@name$[0], $@partymembername$[0], $@partymembercount);
3021+
.@count = getpartymember(getcharid(CHAR_ID_PARTY), PT_MEMBER_NAME, .@name$);
30533022

30543023
// list the party member names
30553024
for (.@i = 0; .@i < .@count; ++.@i) {
30563025
mes((.@i +1) + ". ^0000FF" + .@name$[.@i] + "^000000");
30573026
}
30583027
close();
30593028

3060-
3061-
Example 2: check party count (with a next() pause), before warping to event
3062-
3063-
.register_num = 5; // How many party members are required?
3029+
Example 2: Get online count
30643030

30653031
// get the charID and accountID of character's party members
3066-
getpartymember(getcharid(CHAR_ID_PARTY), 1);
3067-
getpartymember(getcharid(CHAR_ID_PARTY), 2);
3068-
3069-
if ($@partymembercount != .register_num) {
3070-
mes("Please form a party of "+ .register_num +" to continue");
3071-
close();
3072-
}
3032+
// we only need to count the member once so we assign that
3033+
// to the our second command call
3034+
getpartymember(getcharid(CHAR_ID_PARTY), PT_MEMBER_CHARID, .@charid);
3035+
.@count = getpartymember(getcharid(CHAR_ID_PARTY), PT_MEMBER_ACCID, .@accid);
30733036

3074-
// loop through both and use 'isloggedin' to count online party members
3075-
for (.@i = 0; .@i < $@partymembercount; ++.@i)
3076-
if (isloggedin($@partymemberaid[.@i], $@partymembercid[.@i]))
3037+
for (.@i = 0; .@i < .@count; ++.@i) {
3038+
if (isloggedin(.@accid[.@i], .@charid[.@i]))
30773039
.@count_online++;
3078-
// We search accountID & charID because a single party can have
3079-
// multiple characters from the same account. Without searching
3080-
// through the charID, if a player has 2 characters from the same
3081-
// account inside the party but only 1 char online, it would count
3082-
// their online char twice.
3083-
3084-
if (.@count_online != .register_num) {
3085-
mes("All your party members must be online to continue");
3086-
close();
3087-
}
3088-
3089-
// copy the array to prevent players cheating the system
3090-
copyarray(.@partymembercid, $@partymembercid, .register_num);
3091-
3092-
mes("Are you ready?");
3093-
next(); // careful here
3094-
select("Yes");
3095-
3096-
// When a script hits a next, menu, sleep or input that pauses the
3097-
// script, players can invite or /leave and make changes in their
3098-
// party. To prevent this, we call getpartymember again and compare
3099-
// with the original values.
3100-
3101-
getpartymember(getcharid(CHAR_ID_PARTY), 1);
3102-
if ($@partymembercount != .register_num) {
3103-
mes("You've made changes to your party !");
3104-
close();
31053040
}
3106-
for (.@i = 0; .@i < $@partymembercount; ++.@i) {
3107-
if (.@partymembercid[.@i] != $@partymembercid[.@i]) {
3108-
mes("You've made changes to your party !");
3109-
close();
3110-
}
3111-
}
3112-
3113-
// Finally, it's safe to start the event!
3114-
warpparty("event_map", 0, 0, getcharid(CHAR_ID_PARTY), true);
3041+
end;
31153042

31163043
---------------------------------------
31173044

0 commit comments

Comments
 (0)