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 !
This commit is contained in:
Atemo
2019-07-01 21:06:55 +02:00
committed by GitHub
parent c1975d7ea3
commit 5fae7c26c1
4 changed files with 81 additions and 0 deletions

View File

@@ -24447,6 +24447,59 @@ BUILDIN_FUNC(getvariableofinstance)
return SCRIPT_CMD_SUCCESS;
}
/*
convertpcinfo(<char_id>,<type>)
convertpcinfo(<account_id>,<type>)
convertpcinfo(<player_name>,<type>)
*/
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},