From 24c4d531b150863caed448fbbf4a9964dadbb63e Mon Sep 17 00:00:00 2001 From: Guilherme Menaldo Date: Sat, 1 Jun 2019 14:37:42 -0300 Subject: Add identify script command Signed-off-by: Haru --- doc/script_commands.txt | 9 +++++++++ src/map/script.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 3d22914b9..567d0ad56 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -3370,6 +3370,15 @@ enable (true) or disable (false) the effect on the player. --------------------------------------- +*identify() + +This function identifies the first item in attached player's inventory. + +Returns -2 if an error happens, -1 if no unidentified was found. +Otherwise, returns the idx of the identified item. + +--------------------------------------- + *identifyidx() This will identify item at attached player's inventory index. diff --git a/src/map/script.c b/src/map/script.c index ba5412588..c1e210d27 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -25515,6 +25515,42 @@ static BUILDIN(openrefineryui) return true; } +/** + * identify() + * Identifies the first unidentified item on player's inventory. + * Returns -2 on error, -1 if no item to identify was found, identified idx otherwise. + */ +static BUILDIN(identify) +{ + struct map_session_data *sd = script_rid2sd(st); + + if (sd == NULL) { + script_pushint(st, -2); + return true; + } + + int itemid = script_getnum(st, 2); + if (itemdb->exists(itemid) == NULL) { + ShowError("buildin_identify: Invalid item ID (%d)\n", itemid); + script_pushint(st, -2); + return true; + } + + int idx = -1; + ARR_FIND(0, sd->status.inventorySize, idx, (sd->status.inventory[idx].nameid == itemid && sd->status.inventory[idx].identify == 0)); + + if (idx < 0 || idx >= sd->status.inventorySize) { + script_pushint(st, -1); + return true; + } + + sd->status.inventory[idx].identify = 1; + clif->item_identified(sd, idx, 0); + script_pushint(st, idx); + + return true; +} + /** * identifyidx(idx) * Identifies item at idx. @@ -26309,6 +26345,7 @@ static void script_parse_builtin(void) BUILDIN_DEF(setfavoriteitemidx, "ii"), BUILDIN_DEF(autofavoriteitem, "ii"), + BUILDIN_DEF(identify, "i"), BUILDIN_DEF(identifyidx, "i"), }; int i, len = ARRAYLENGTH(BUILDIN); -- cgit v1.2.3-60-g2f50