Skip to content

Commit

Permalink
Adds BUILDIN(equipidx), which attempts to equip and item at given index.
Browse files Browse the repository at this point in the history
  • Loading branch information
bWolfie committed Jan 23, 2019
1 parent 51483b4 commit 0b21090
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
21 changes: 21 additions & 0 deletions doc/script_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5622,6 +5622,27 @@ Examples:

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

*equipidx(<index>{,<item id>})

The equipidx function will attempt to equip the item at the given inventory
inventory index. This feature is only really useful when multiple instances
of an Item ID exist in the player's inventory.

If item id is specified, the item id at the specified index must be of that
item id.

Returns 1 if the item was successfully equipped.
Returns 0 if the item failed to equip.

See getinventorylist() for an explanation on retrieving an inventory index.

Examples:

//This will attempt to equip the item at inventory index 45.
equipidx(45);

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

*buyingstore(<slots>)

Invokes buying store preparation window like the skill 'Open Buying
Expand Down
48 changes: 48 additions & 0 deletions src/map/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -16515,6 +16515,53 @@ static BUILDIN(autoequip)
return true;
}

/**
* equipidx(<index>{, <item id>})
*/
static BUILDIN(equipidx)
{
int nameid = 0, i = script_getnum(st, 2);
struct item_data *item_data;
struct map_session_data *sd = script->rid2sd(st);

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

if (i < 0 || i >= sd->status.inventorySize) {
ShowError("buildin_equipidx: Index (%d) should be from 0-%d.\n", i, sd->status.inventorySize);
script_pushint(st, 0);
return false;
}

if (i < sd->status.inventorySize) {
if (script_hasdata(st, 3))
nameid = script_getnum(st, 3);
else
nameid = sd->status.inventory[i].nameid == nameid;

if ((item_data = itemdb->exists(nameid)) == NULL) {
ShowError("buildin_equipidx: Invalid Item ID (%d).\n", nameid);
script_pushint(st, 0);
return false;
}

if (sd->status.inventory[i].nameid == nameid && sd->status.inventory[i].equip == 0) {
script_pushint(st, pc->equipitem(sd, i, item_data->equip));
return true;
}

if (sd->status.inventory[i].nameid != nameid)
ShowWarning("buildin_equipidx: Item ID (%d) not found at index (%d) (found Item ID %d).\n", nameid, i, sd->status.inventory[i].nameid);
else if (sd->status.inventory[i].equip != 0)
ShowWarning("buildin_equipidx: Item ID (%d) at index (%d) cannot be equipped.\n", sd->status.inventory[i].nameid, i);
}

script_pushint(st, 0);
return true;
}

/*=======================================================
* Equip2
* equip2 <item id>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>;
Expand Down Expand Up @@ -25491,6 +25538,7 @@ static void script_parse_builtin(void)
BUILDIN_DEF(equip,"i"),
BUILDIN_DEF(autoequip,"ii"),
BUILDIN_DEF(equip2,"iiiiiii"),
BUILDIN_DEF(equipidx, "i?"),
BUILDIN_DEF(setbattleflag,"si"),
BUILDIN_DEF(getbattleflag,"s"),
BUILDIN_DEF(setitemscript,"is?"), //Set NEW item bonus script. Lupus
Expand Down

0 comments on commit 0b21090

Please sign in to comment.