Deleting Item from Inventory

Post Reply
sonicblazer
Posts: 4
Joined: Thu Jul 30, 2015 7:53 am

Deleting Item from Inventory

Post by sonicblazer » Mon Aug 31, 2015 11:09 pm

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;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

User avatar
kjLotus
Lead Developer
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: Deleting Item from Inventory

Post by kjLotus » Tue Sep 01, 2015 12:46 am

You delete items by using UpdateItem to set its quantity to 0

sonicblazer
Posts: 4
Joined: Thu Jul 30, 2015 7:53 am

Re: Deleting Item from Inventory

Post by sonicblazer » Mon Sep 07, 2015 2:09 pm

Sorry another noob question. How do I call the UpdateItem function in a lua script?

User avatar
kjLotus
Lead Developer
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: Deleting Item from Inventory

Post by kjLotus » Mon Sep 07, 2015 2:18 pm

what do you need it for? I think every time an item is deleted via script would be done by trade

User avatar
tabitaru
Posts: 99
Joined: Sun Apr 12, 2015 4:49 am

Re: Deleting Item from Inventory

Post by tabitaru » Mon Sep 07, 2015 2:33 pm

!
Last edited by tabitaru on Sun Oct 18, 2015 7:01 am, edited 1 time in total.

sonicblazer
Posts: 4
Joined: Thu Jul 30, 2015 7:53 am

Re: Deleting Item from Inventory

Post by sonicblazer » Mon Sep 07, 2015 5:37 pm

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.

User avatar
whasf
Site Admin
Posts: 1300
Joined: Thu Jul 19, 2012 9:11 pm

Re: Deleting Item from Inventory

Post by whasf » Mon Sep 07, 2015 7:11 pm

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
-- Whasf

User avatar
kjLotus
Lead Developer
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: Deleting Item from Inventory

Post by kjLotus » Mon Sep 07, 2015 7:21 pm

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

Post Reply