Skip to content

Commit

Permalink
Add *setfavoriteitem script command.
Browse files Browse the repository at this point in the history
- set an item as favorite item or not
- if an item is set to favorite item, it will be moved into favorite
tab, else move out from favorite tab.
- only non-equipped item can adjust the favorite item state.
  • Loading branch information
Emistry committed Apr 11, 2019
1 parent ab81d40 commit 1bbea11
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions doc/script_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3183,6 +3183,17 @@ runs of getcartinventorylist().

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

*setfavoriteitem(<idx>, <value>)

This function will set an item in inventory as favorite or not.
If its favorite item, it will be moved to favorite tab, else move out from favorite tab.

Valid Parameters:
<idx> - inventory index, refer *getinventorylist()
<value> - true/false (true = favorite item, false = otherwise)

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

*cardscnt()

This function will return the number of cards inserted into the weapon
Expand Down
22 changes: 22 additions & 0 deletions src/map/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -24559,6 +24559,26 @@ static BUILDIN(getcalendartime)
return true;
}

static BUILDIN(setfavoriteitem)
{
struct map_session_data *sd = script_rid2sd(st);
int idx = script_getnum(st, 2);
int value = script_getnum(st, 3);

if (sd == NULL) {
ShowError("buildin_setfavoriteitem: No player attached.\n");
return false;
} else if (idx < 0 || idx >= sd->status.inventorySize || sd->inventory_data[idx] == NULL) {
ShowError("buildin_setfavouriteitem: Invalid inventory index %d (min: %d, max: %d).\n", idx, 0, (sd->status.inventorySize - 1));
return false;
} else if (sd->status.inventory[idx].equip == 0) {
sd->status.inventory[idx].favorite = cap_value(value, 0, 1);
clif->favorite_item(sd, idx);
}

return true;
}

/** place holder for the translation macro **/
static BUILDIN(_)
{
Expand Down Expand Up @@ -25902,6 +25922,8 @@ static void script_parse_builtin(void)
BUILDIN_DEF(expandInventoryResult, "i"),
BUILDIN_DEF(expandInventory, "i"),
BUILDIN_DEF(getInventorySize, ""),
BUILDIN_DEF(setfavoriteitem, "ii"),

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

0 comments on commit 1bbea11

Please sign in to comment.