Cuberite Forum
Inventory - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html)
+--- Forum: Discussion (https://forum.cuberite.org/forum-5.html)
+--- Thread: Inventory (/thread-1534.html)



Inventory - Seadragon91 - 07-19-2014

Hello!

Small question, how can I remove a item from a inventory easily?
Every method where I looked trough in the api, let me think that I need to loop over all the slots in the inventory Undecided

Edit: Why is there no method in cInventory, like RemoveItem(cItem)?

Ty,
Seadragon91


RE: Inventory - xoft - 07-19-2014

If you're looking for a particular item to remove, then yes, you need to iterate over the entire inventory. That's mostly because no-one has yet needed such a function, so no-one wrote it. Be the hero, write it and export it to the API Smile


RE: Inventory - Seadragon91 - 07-19-2014

I found a "way" to remove a item or change the amount over the method AddItem(cItem)
1) Copy the item
2) Make the variable m_ItemCount negativ (item.m_ItemCount = item.m_ItemCount * -1)
3) Add the item over AddItem

Nice it accepts negative integersBig Grin
Only problem sometimes the items amount is not changing and this cause sync errors Sad

Edit: But yes a remove method would be much better.


RE: Inventory - Seadragon91 - 08-29-2014

I think it would be a nice idea to add a hook for the slot changing (player takes the item), where you can get the player, the clicked slot and the possibility to cancel it.

Because then it would be possible to run code, if the player clicks on a item.

regards,
Seadragon91


RE: Inventory - NiLSPACE - 08-29-2014

We already have an issue for it: https://github.com/mc-server/MCServer/issues/813 Smile


RE: Inventory - Seadragon91 - 08-29-2014

(08-29-2014, 03:55 AM)STR_Warrior Wrote: We already have an issue for it: https://github.com/mc-server/MCServer/issues/813 Smile

Ah okay, tyBig Grin


RE: Inventory - Bobstergaming - 11-17-2015

Here I have a bit of code:
function HandleSellall(Player)
    removedamout = cInventory(RemoveItem(cItem(E_BLOCK_STONE)))
    
      end true

The idea is that when the player does /sellall, then it removes stone and returns the removed amount of stone as removedamount.

There aren`t any examples on cInventory, although by looking at the API of cItem I figured this out.


RE: Inventory - worktycho - 11-19-2015

Adding negative counts needs to be looked at. Because at the moment it is possible for a plugin to remove more items from a player than they have, causing the player to have negative items.