Skip to content

Commit 24c4d53

Browse files
guilherme-gmMishimaHaruna
authored andcommittedJun 30, 2019
Add identify script command
Signed-off-by: Haru <haru@dotalux.com>
1 parent 462f1d0 commit 24c4d53

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
 

‎doc/script_commands.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3370,6 +3370,15 @@ enable (true) or disable (false) the effect on the player.
33703370

33713371
---------------------------------------
33723372

3373+
*identify(<Item ID>)
3374+
3375+
This function identifies the first <Item ID> item in attached player's inventory.
3376+
3377+
Returns -2 if an error happens, -1 if no unidentified <Item ID> was found.
3378+
Otherwise, returns the idx of the identified item.
3379+
3380+
---------------------------------------
3381+
33733382
*identifyidx(<Inventory Index>)
33743383

33753384
This will identify item at attached player's <Inventory Index> inventory index.

‎src/map/script.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25515,6 +25515,42 @@ static BUILDIN(openrefineryui)
2551525515
return true;
2551625516
}
2551725517

25518+
/**
25519+
* identify(<item id>)
25520+
* Identifies the first unidentified <item id> item on player's inventory.
25521+
* Returns -2 on error, -1 if no item to identify was found, identified idx otherwise.
25522+
*/
25523+
static BUILDIN(identify)
25524+
{
25525+
struct map_session_data *sd = script_rid2sd(st);
25526+
25527+
if (sd == NULL) {
25528+
script_pushint(st, -2);
25529+
return true;
25530+
}
25531+
25532+
int itemid = script_getnum(st, 2);
25533+
if (itemdb->exists(itemid) == NULL) {
25534+
ShowError("buildin_identify: Invalid item ID (%d)\n", itemid);
25535+
script_pushint(st, -2);
25536+
return true;
25537+
}
25538+
25539+
int idx = -1;
25540+
ARR_FIND(0, sd->status.inventorySize, idx, (sd->status.inventory[idx].nameid == itemid && sd->status.inventory[idx].identify == 0));
25541+
25542+
if (idx < 0 || idx >= sd->status.inventorySize) {
25543+
script_pushint(st, -1);
25544+
return true;
25545+
}
25546+
25547+
sd->status.inventory[idx].identify = 1;
25548+
clif->item_identified(sd, idx, 0);
25549+
script_pushint(st, idx);
25550+
25551+
return true;
25552+
}
25553+
2551825554
/**
2551925555
* identifyidx(idx)
2552025556
* Identifies item at idx.
@@ -26309,6 +26345,7 @@ static void script_parse_builtin(void)
2630926345
BUILDIN_DEF(setfavoriteitemidx, "ii"),
2631026346
BUILDIN_DEF(autofavoriteitem, "ii"),
2631126347

26348+
BUILDIN_DEF(identify, "i"),
2631226349
BUILDIN_DEF(identifyidx, "i"),
2631326350
};
2631426351
int i, len = ARRAYLENGTH(BUILDIN);

0 commit comments

Comments
 (0)