From a4595d7246f9c8ed03b89fd8d6a03665e28bdd15 Mon Sep 17 00:00:00 2001 From: Wolfie Date: Sun, 13 Jan 2019 17:54:51 +1300 Subject: [PATCH] Adds support for param for getcharid(). Deprecates charid2rid(), its functionality now merged into getcharid(). --- doc/script_commands.txt | 15 ++++++++++++++- src/map/script.c | 12 ++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 57d47b1b5d9..7bb0d8883ad 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -2435,10 +2435,18 @@ if any, or else return an empty string. *charid2rid() + @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + @ /!\ 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, ) + --------------------------------------- *getarraysize() @@ -2549,9 +2557,10 @@ bStr, bInt, bLuk --------------------------------------- *getcharid({, ""}) +*getcharid({, }) 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: @@ -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{, }) + For most purposes other than printing it, a number is better to have than a name (people do horrifying things to their character names). diff --git a/src/map/script.c b/src/map/script.c index 25bf59839b1..da73bab2394 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -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 @@ -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]