Kindly help or guide me on how to include Custom Storage/ Premium Storage to be included in delitem/storagedelitem npc script. Thanks in advance!
/// Deletes items from the target/attached player.
/// Prioritizes ordinary items.
///
/// delitem <item id>,<amount>{,<account id>}
/// delitem "<item name>",<amount>{,<account id>}
/// cartdelitem <item id>,<amount>{,<account id>}
/// cartdelitem "<item name>",<amount>{,<account id>}
/// storagedelitem <item id>,<amount>{,<account id>}
/// storagedelitem "<item name>",<amount>{,<account id>}
/// guildstoragedelitem <item id>,<amount>{,<account id>}
/// guildstoragedelitem "<item name>",<amount>{,<account id>}
BUILDIN_FUNC(delitem)
{
TBL_PC *sd;
struct item it;
uint8 loc = 0;
char* command = (char*)script_getfuncname(st);
if(!strncmp(command, "cart", 4))
loc = TABLE_CART;
else if(!strncmp(command, "storage", 7))
loc = TABLE_STORAGE;
else if(!strncmp(command, "guildstorage", 12))
loc = TABLE_GUILD_STORAGE;
if( !script_accid2sd(4,sd) ){
// In any case cancel script execution
st->state = END;
return SCRIPT_CMD_SUCCESS;
}
if (loc == TABLE_CART && !pc_iscarton(sd)) {
ShowError("buildin_cartdelitem: player doesn't have cart (CID=%d).\n", sd->status.char_id);
script_pushint(st, -1);
return SCRIPT_CMD_FAILURE;
}
if (loc == TABLE_GUILD_STORAGE) {
struct s_storage *gstor = guild2storage2(sd->status.guild_id);
if (gstor == nullptr || sd->state.storage_flag) {
script_pushint(st, -1);
return SCRIPT_CMD_FAILURE;
}
}
if( script_isstring(st, 2) )
{
const char* item_name = script_getstr(st, 2);
std::shared_ptr<item_data> id = item_db.searchname(item_name);
if( id == nullptr ){
ShowError("buildin_%s: unknown item \"%s\".\n", command, item_name);
st->state = END;
return SCRIPT_CMD_FAILURE;
}
it.nameid = id->nameid;// "<item name>"
}
else
{
it.nameid = script_getnum(st, 2);// <item id>
if( !item_db.exists( it.nameid ) )
{
ShowError("buildin_%s: unknown item \"%u\".\n", command, it.nameid);
st->state = END;
return SCRIPT_CMD_FAILURE;
}
}
it.amount=script_getnum(st,3);
if( it.amount <= 0 )
return SCRIPT_CMD_SUCCESS;// nothing to do
if( buildin_delitem_search(sd, &it, 0, loc) )
{// success
return SCRIPT_CMD_SUCCESS;
}
ShowError("buildin_%s: failed to delete %d items (AID=%d item_id=%u).\n", command, it.amount, sd->status.account_id, it.nameid);
st->state = END;
st->mes_active = 0;
clif_scriptclose( *sd, st->oid );
return SCRIPT_CMD_FAILURE;
}