Skip to content

Commit

Permalink
Add identify script command
Browse files Browse the repository at this point in the history
Signed-off-by: Haru <haru@dotalux.com>
  • Loading branch information
guilherme-gm authored and MishimaHaruna committed Jun 30, 2019
1 parent 462f1d0 commit 24c4d53
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/script_commands.txt
Expand Up @@ -3370,6 +3370,15 @@ enable (true) or disable (false) the effect on the player.

---------------------------------------

*identify(<Item ID>)

This function identifies the first <Item ID> item in attached player's inventory.

Returns -2 if an error happens, -1 if no unidentified <Item ID> was found.
Otherwise, returns the idx of the identified item.

---------------------------------------

*identifyidx(<Inventory Index>)

This will identify item at attached player's <Inventory Index> inventory index.
Expand Down
37 changes: 37 additions & 0 deletions src/map/script.c
Expand Up @@ -25515,6 +25515,42 @@ static BUILDIN(openrefineryui)
return true;
}

/**
* identify(<item id>)
* Identifies the first unidentified <item id> 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.
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 24c4d53

Please sign in to comment.