From 5fae7c26c191d3096e739eed1bc2c44c7f2ede01 Mon Sep 17 00:00:00 2001 From: Atemo Date: Mon, 1 Jul 2019 21:06:55 +0200 Subject: [PATCH] convertpcinfo script command (#3924) Implemented convertpcinfo script command * The command allows to convert more easily a player data to another. * It fails silently if the character is not found/online. Thanks to @aleos89, @Normynator, @cydh ! --- doc/script_commands.txt | 16 +++++++++++ src/map/script.cpp | 54 ++++++++++++++++++++++++++++++++++++ src/map/script.hpp | 6 ++++ src/map/script_constants.hpp | 5 ++++ 4 files changed, 81 insertions(+) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 234363946a..67694907a8 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -2338,6 +2338,22 @@ returned when requesting that information. --------------------------------------- +*convertpcinfo(,) +*convertpcinfo(,) +*convertpcinfo(,) + +This function will return the information for the +specified character. Whatever it returns is determined by type. + + CPC_NAME - Character's name. + CPC_CHAR - Character ID. + CPC_ACCOUNT - Account ID. + +If a character is not found (or not online) when requesting that information, +an empty string will be returned for CPC_NAME, 0 for other . + +--------------------------------------- + *strnpcinfo() This function will return the various parts of the name of the calling NPC. diff --git a/src/map/script.cpp b/src/map/script.cpp index 6acc449592..604274ecde 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -24447,6 +24447,59 @@ BUILDIN_FUNC(getvariableofinstance) return SCRIPT_CMD_SUCCESS; } +/* + convertpcinfo(,) + convertpcinfo(,) + convertpcinfo(,) +*/ +BUILDIN_FUNC(convertpcinfo) { + TBL_PC *sd; + + if (script_isstring(st, 2)) + sd = map_nick2sd(script_getstr(st, 2),false); + else { + int id = script_getnum(st, 2); + sd = map_id2sd(id); + if (!sd) + sd = map_charid2sd(id); + } + + int type = script_getnum(st, 3); + + switch (type) { + case CPC_NAME: + case CPC_CHAR: + case CPC_ACCOUNT: + break; + default: + ShowError("buildin_convertpcinfo: Unknown type %d.\n", type); + script_pushnil(st); + st->state = END; + return SCRIPT_CMD_FAILURE; + } + + if (!sd) { + if (type == CPC_NAME) + script_pushstrcopy(st, ""); + else + script_pushint(st, 0); + return SCRIPT_CMD_SUCCESS; + } + + switch (type) { + case CPC_NAME: + script_pushstrcopy(st, sd->status.name); + break; + case CPC_CHAR: + script_pushint(st, sd->status.char_id); + break; + case CPC_ACCOUNT: + script_pushint(st, sd->status.account_id); + break; + } + return SCRIPT_CMD_SUCCESS; +} + #include "../custom/script.inc" // declarations that were supposed to be exported from npc_chat.cpp @@ -25116,6 +25169,7 @@ struct script_function buildin_func[] = { BUILDIN_DEF(achievement_condition,"i"), BUILDIN_DEF(getvariableofinstance,"ri"), + BUILDIN_DEF(convertpcinfo,"vi"), #include "../custom/script_def.inc" {NULL,NULL,NULL}, diff --git a/src/map/script.hpp b/src/map/script.hpp index 5d7490afe6..82aeb39cde 100644 --- a/src/map/script.hpp +++ b/src/map/script.hpp @@ -1942,6 +1942,12 @@ enum e_hat_effects { HAT_EF_MAX }; +enum e_convertpcinfo_type : uint8 { + CPC_NAME = 0, + CPC_CHAR = 1, + CPC_ACCOUNT = 2 +}; + /** * Player blocking actions related flags. */ diff --git a/src/map/script_constants.hpp b/src/map/script_constants.hpp index 42cc9e049f..2cf5138c4d 100644 --- a/src/map/script_constants.hpp +++ b/src/map/script_constants.hpp @@ -7281,6 +7281,11 @@ export_constant(PCBLOCK_EMOTION); export_constant(PCBLOCK_ALL); + /* convertpcinfo command */ + export_constant(CPC_NAME); + export_constant(CPC_CHAR); + export_constant(CPC_ACCOUNT); + #undef export_constant #undef export_constant2 #undef export_parameter