Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Remove specific amount of item

Comments in 'Plugin Development' started by deot, Nov 27, 2015.

  1. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    Hi, im trying to remove a specific amount of item, but idk how...

    NOTE: I defined $inv correctly
    PHP:
    $inv->remove(Item::get(38801))
    Basically, i just want to remove 1 emerald from player's inv, but that code will just remove all

    I searched the forum, and i found that @PEMapModder said dont use remove() as it will remove all items u specified.., he said use removeItem()

    So, i go to docs... and.. heres the API found from docs:
    PHP:
    removeItem($slot)
    Hmmm... so? How can i do that actually? I dont want to remove all item from that slot tho...

    Pls help... :p
    Legoboy0215 likes this.
  2. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Hello! I got the same problem. Found out the docs was wrong. Not exactly wrong, but the variable name confused me. removeItem() accepts Item as a parameter, not the slot :p Hope this helped. GitHub is a better way to check out functions as you may learn how and why it does stuff.
    deot likes this.
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    I basically calculated the amount of the item after removing it. Means
    PHP:
    $newAmount $currentAmount $toRemove;
    if(
    $toRemove 0){
      
    // remove it
      // add the item back with $newAmount as amount
    } else{
      
    // remove it
    }
    AndrewBit likes this.
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    That is what I did before I figured out that the docs was wrong.

Share This Page

Advertisement