Skip to content

Commit

Permalink
Add identifyidx 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 33b0658 commit 462f1d0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/script_commands.txt
Expand Up @@ -3368,6 +3368,15 @@ cards or if it's signed.
This will set a Hat Effect onto the player. The state field allows you to
enable (true) or disable (false) the effect on the player.

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

*identifyidx(<Inventory Index>)

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

Returns true if the item was identified, false otherwise.
Note: If the item was already identified, it returns false.

---------------------------------------
//=====================================
2.1 - End of Item-Related Commands
Expand Down
35 changes: 35 additions & 0 deletions src/map/script.c
Expand Up @@ -25515,6 +25515,39 @@ static BUILDIN(openrefineryui)
return true;
}

/**
* identifyidx(idx)
* Identifies item at idx.
* Returns true if item is identified, false otherwise.
*/
static BUILDIN(identifyidx)
{
struct map_session_data *sd = script_rid2sd(st);

if (sd == NULL) {
script_pushint(st, false);
return true;
}

int idx = script_getnum(st, 2);
if (idx < 0 || idx >= sd->status.inventorySize) {
ShowError("buildin_identifyidx: Invalid inventory index (%d), expected a value between 0 and %d\n", idx, sd->status.inventorySize);
script_pushint(st, false);
return true;
}

if (sd->status.inventory[idx].nameid <= 0 || sd->status.inventory[idx].identify != 0) {
script_pushint(st, false);
return true;
}

sd->status.inventory[idx].identify = 1;
clif->item_identified(sd, idx, 0);
script_pushint(st, true);

return true;
}

/**
* Adds a built-in script function.
*
Expand Down Expand Up @@ -26275,6 +26308,8 @@ static void script_parse_builtin(void)
BUILDIN_DEF(openrefineryui, ""),
BUILDIN_DEF(setfavoriteitemidx, "ii"),
BUILDIN_DEF(autofavoriteitem, "ii"),

BUILDIN_DEF(identifyidx, "i"),
};
int i, len = ARRAYLENGTH(BUILDIN);
RECREATE(script->buildin, char *, script->buildin_count + len); // Pre-alloc to speed up
Expand Down

0 comments on commit 462f1d0

Please sign in to comment.