Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for <account id> param for getcharid(). Deprecates charid2rid. #2350

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion doc/script_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2435,10 +2435,18 @@ if any, or else return an empty string.

*charid2rid(<char id>)

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ /!\ This command is deprecated @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

This function returns the RID of the character with the given character ID.

If the character is offline or doesn't exist, 0 is returned.

This command is deprecated and it should not be used in new scripts, as it is
likely to be removed at a later time. Please use getcharid instead,
ie: getcharid(CHAR_ID_ACCOUNT, <char id>)

---------------------------------------

*getarraysize(<array name>)
Expand Down Expand Up @@ -2549,9 +2557,10 @@ bStr, bInt, bLuk
---------------------------------------

*getcharid(<type>{, "<character name>"})
*getcharid(<type>{, <account id>})

This function will return a unique ID number of the invoking character,
or, if a character name is specified, of that player.
or, if a character name or account id is specified, of that player.

Type is the kind of associated ID number required:

Expand All @@ -2562,6 +2571,10 @@ Type is the kind of associated ID number required:
(4) CHAR_ID_BG - Battle ground ID
(5) CHAR_ID_CLAN - Clan ID number.

If type is (3) CHAR_ID_ACCOUNT, the optional parameter will check
char id instead of account id.
I.e. getcharid(CHAR_ID_ACCOUNT{, <char id>})

For most purposes other than printing it, a number is better to have than
a name (people do horrifying things to their character names).

Expand Down
12 changes: 8 additions & 4 deletions src/map/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -8660,10 +8660,14 @@ static BUILDIN(getcharid)
int num = script_getnum(st, 2);
struct map_session_data *sd;

if (script_hasdata(st, 3))
sd = map->nick2sd(script_getstr(st, 3));
else
if (script_hasdata(st, 3)) {
if (num == 3 && script_isinttype(st, 3))
sd = script->charid2sd(st, script_getnum(st, 3));
else
sd = script_isstringtype(st, 3) ? script->nick2sd(st, script_getstr(st, 3)) : script->id2sd(st, script_getnum(st, 3));
} else {
sd = script->rid2sd(st);
}

if (sd == NULL) {
script_pushint(st, 0); //return 0, according docs
Expand Down Expand Up @@ -25150,7 +25154,7 @@ static void script_parse_builtin(void)
BUILDIN_DEF(getguildmember,"i?"),
BUILDIN_DEF(strcharinfo,"i??"),
BUILDIN_DEF(strnpcinfo,"i??"),
BUILDIN_DEF(charid2rid,"i"),
BUILDIN_DEF_DEPRECATED(charid2rid, "i"),
BUILDIN_DEF(getequipid,"i"),
BUILDIN_DEF(getequipname,"i"),
BUILDIN_DEF(getbrokenid,"i"), // [Valaris]
Expand Down