Script command "delitemidx" (#6247)

Added new command that allow delete items from inventory by index.

Co-authored-by: Lemongrass3110 <lemongrass@kstp.at>
Co-authored-by: Aleos <aleos89@users.noreply.github.com>
Co-authored-by: Daegaladh <Daegaladh@users.noreply.github.com>
This commit is contained in:
Balfear 2021-09-09 14:02:02 +03:00 committed by GitHub
parent d25ec40a8f
commit c18707bb6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 0 deletions

View File

@ -2903,6 +2903,7 @@ invoking character has in their inventory, including all the data needed to
recreate these items perfectly if they are destroyed. Here's what you get:
@inventorylist_id[] - array of item ids.
@inventorylist_idx[] - array of item inventory index.
@inventorylist_amount[] - their corresponding item amounts.
@inventorylist_equip[] - on which position the item is equipped (see EQP_* constants)
It will contain 0 if the item is not equipped.
@ -4997,6 +4998,30 @@ See 'getitem2' for an explanation of the expanded parameters.
---------------------------------------
*delitemidx <index>{,<amount>{,<char id>}}
This command will remove an item at the given inventory index.
If <amount> is not specified, this will remove all of the items at the specified index.
The only way to get the inventory index is by using 'getinventorylist()'. After deleting
an item at the given index, that index can remain empty until the player relogs, requiring
'getinventorylist()' to be called again. If an item is deleted with an invalid index, the
script will terminate with an error.
This command returns true on success and false if the item at the given index could not be deleted or if
not enough items were available at the given index.
Example:
// This will remove all Red Potions from player's inventory
getinventorylist();
for (.@i = 0; .@i < @inventorylist_count; ++.@i)
if (@inventorylist_id[.@i] == 501)
delitemidx @inventorylist_idx[.@i];
---------------------------------------
*cartdelitem2 <item id>,<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>};
*cartdelitem2 "<item name>",<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>};
*storagedelitem2 <item id>,<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>};

View File

@ -8437,6 +8437,43 @@ BUILDIN_FUNC(delitem2)
return SCRIPT_CMD_FAILURE;
}
/// Deletes items from the target/attached player at given index.
/// delitemidx <index>{,<amount>{,<char id>}};
BUILDIN_FUNC(delitemidx) {
struct map_session_data* sd;
if (!script_charid2sd(4, sd)) {
script_pushint(st, false);
return SCRIPT_CMD_FAILURE;
}
int idx = script_getnum(st, 2);
if (idx < 0 || idx >= MAX_INVENTORY) {
ShowWarning("buildin_delitemidx: Index %d is out of the range 0-%d.\n", idx, MAX_INVENTORY - 1);
script_pushint(st, false);
return SCRIPT_CMD_FAILURE;
}
if (sd->inventory_data[idx] == nullptr) {
ShowWarning("buildin_delitemidx: No item can be deleted from index %d of player %s (AID: %u, CID: %u).\n", idx, sd->status.name, sd->status.account_id, sd->status.char_id);
script_pushint(st, false);
return SCRIPT_CMD_FAILURE;
}
int amount;
if (script_hasdata(st, 3))
amount = script_getnum(st, 3);
else
amount = sd->inventory.u.items_inventory[idx].amount;
if (amount > 0)
script_pushint(st, pc_delitem(sd, idx, amount, 0, 0, LOG_TYPE_SCRIPT) == 0);
else
script_pushint(st, false);
return SCRIPT_CMD_SUCCESS;
}
/*==========================================
* Enables/Disables use of items while in an NPC [Skotlex]
*------------------------------------------*/
@ -14232,6 +14269,7 @@ BUILDIN_FUNC(getinventorylist)
for(i=0;i<MAX_INVENTORY;i++){
if(sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].amount > 0){
pc_setreg(sd,reference_uid(add_str("@inventorylist_id"), j),sd->inventory.u.items_inventory[i].nameid);
pc_setreg(sd,reference_uid(add_str("@inventorylist_idx"), j),i);
pc_setreg(sd,reference_uid(add_str("@inventorylist_amount"), j),sd->inventory.u.items_inventory[i].amount);
pc_setreg(sd,reference_uid(add_str("@inventorylist_equip"), j),sd->inventory.u.items_inventory[i].equip);
pc_setreg(sd,reference_uid(add_str("@inventorylist_refine"), j),sd->inventory.u.items_inventory[i].refine);
@ -25220,6 +25258,7 @@ struct script_function buildin_func[] = {
BUILDIN_DEF2(delitem2,"storagedelitem2","viiiiiiii?"),
BUILDIN_DEF2(delitem2,"guildstoragedelitem2","viiiiiiii?"),
BUILDIN_DEF2(delitem2,"cartdelitem2","viiiiiiii?"),
BUILDIN_DEF(delitemidx,"i??"),
BUILDIN_DEF2(enableitemuse,"enable_items",""),
BUILDIN_DEF2(disableitemuse,"disable_items",""),
BUILDIN_DEF(cutin,"si"),