Inventory
#1
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
Reply
Thanks given by:
#2
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
Reply
Thanks given by:
#3
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.
Reply
Thanks given by:
#4
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
Reply
Thanks given by:
#5
We already have an issue for it: https://github.com/mc-server/MCServer/issues/813 Smile
Reply
Thanks given by:
#6
(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
Reply
Thanks given by: NiLSPACE
#7
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.
Reply
Thanks given by:
#8
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.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)