Page 1 of 1

Deleting Item from Inventory

Posted: Mon Aug 31, 2015 11:09 pm
by sonicblazer
Need help in figuring out how to delete an item from inventory. Looking at the charutils.cpp, how do I modify the addItem (into delItem) so that the same parameters still apply and will remove an item with specified quantity? Appreciate the response!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uint8 AddItem(CCharEntity* PChar, uint8 LocationID, uint16 ItemID, uint32 quantity, bool silence)
{
if (PChar->getStorage(LocationID)->GetFreeSlotsCount() == 0 || quantity == 0)
{
return ERROR_SLOTID;
}

CItem* PItem = itemutils::GetItem(ItemID);

if (PItem != nullptr)
{
PItem->setQuantity(quantity);
return AddItem(PChar, LocationID, PItem, silence);
}
ShowWarning(CL_YELLOW"charplugin::AddItem: Item <%i> is not found in a database\n" CL_RESET, ItemID);
return ERROR_SLOTID;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Re: Deleting Item from Inventory

Posted: Tue Sep 01, 2015 12:46 am
by kjLotus
You delete items by using UpdateItem to set its quantity to 0

Re: Deleting Item from Inventory

Posted: Mon Sep 07, 2015 2:09 pm
by sonicblazer
Sorry another noob question. How do I call the UpdateItem function in a lua script?

Re: Deleting Item from Inventory

Posted: Mon Sep 07, 2015 2:18 pm
by kjLotus
what do you need it for? I think every time an item is deleted via script would be done by trade

Re: Deleting Item from Inventory

Posted: Mon Sep 07, 2015 2:33 pm
by tabitaru
!

Re: Deleting Item from Inventory

Posted: Mon Sep 07, 2015 5:37 pm
by sonicblazer
Scenario: A GM was giving items away and accidentally gave one to an incorrect person. Just want to remove the item using the same syntax as giveitem <player> <itemID> <quantity> - assuming the location is in the inventory bag.

Re: Deleting Item from Inventory

Posted: Mon Sep 07, 2015 7:11 pm
by whasf
sonicblazer wrote:Scenario: A GM was giving items away and accidentally gave one to an incorrect person. Just want to remove the item using the same syntax as giveitem <player> <itemID> <quantity> - assuming the location is in the inventory bag.
How do you know that person didn't trade off the item already, or move it to a storage location? Might have to go into the db

Re: Deleting Item from Inventory

Posted: Mon Sep 07, 2015 7:21 pm
by kjLotus
oh.. I'd just log them out and then delete the entry from the db table. It's very annoying to do something like that because you don't know the slot id. While you can just say "delete the first item of this ID that I find", there's no guarantee that it's the actual one you added. you'll have to write the lua binding yourself if you want to do that - iterate over the inventory and remove the first item matching the id