From b3643bfe45ac49dcced13bff43498af33546caa1 Mon Sep 17 00:00:00 2001 From: Lemongrass3110 Date: Sun, 1 Jul 2018 22:28:56 +0200 Subject: [PATCH] Added a 'force' option to attachrid (#3261) Fixes #1763 --- doc/script_commands.txt | 11 ++++++++--- src/map/script.cpp | 21 ++++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index d3ccbdf710..9f61c38855 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -3904,7 +3904,7 @@ not. ============================== ------------------------- -*attachrid() +*attachrid({,force}) *detachrid; These commands allow the manipulation of the script's currently attached player. @@ -3912,8 +3912,13 @@ While 'attachrid' allows attaching of a different player by using its account id for the parameter RID, 'detachrid' makes the following commands run as if the script was never invoked by a player. -The command returns 0 if the player cannot be attached (if the account is offline -or does not exist), and 1 upon success. +The command returns false if the player cannot be attached (if the account is offline +or does not exist), and true upon success. + +By default the command is executed with force, which causes to attach the player +even if he is currently attached to another script. Since this is not always the +desired behavior you can also specify false to the command and it will only return +true if the player is online and was not attached to another script. ------------------------- diff --git a/src/map/script.cpp b/src/map/script.cpp index 180f9baaf9..947d2ee66c 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -12198,15 +12198,26 @@ BUILDIN_FUNC(addrid) BUILDIN_FUNC(attachrid) { int rid = script_getnum(st,2); + bool force; - if (map_id2sd(rid) != NULL) { + if( script_hasdata(st,3) ){ + force = script_getnum(st,3) != 0; + }else{ + force = true; + } + + struct map_session_data* sd = map_id2sd(rid); + + if( sd != NULL && ( !sd->npc_id || force ) ){ script_detach_rid(st); st->rid = rid; script_attach_state(st); - script_pushint(st,1); - } else - script_pushint(st,0); + script_pushint(st,true); + }else{ + script_pushint(st,false); + } + return SCRIPT_CMD_SUCCESS; } /*========================================== @@ -24237,7 +24248,7 @@ struct script_function buildin_func[] = { BUILDIN_DEF2(disablewaitingroomevent,"disablearena",""), // Added by RoVeRT BUILDIN_DEF(getwaitingroomstate,"i?"), BUILDIN_DEF(warpwaitingpc,"sii?"), - BUILDIN_DEF(attachrid,"i"), + BUILDIN_DEF(attachrid,"i?"), BUILDIN_DEF(addrid,"i?????"), BUILDIN_DEF(detachrid,""), BUILDIN_DEF(isloggedin,"i?"),