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:
@@ -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"),
|
||||
|
||||
Reference in New Issue
Block a user