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

Remove item.

Comments in 'Plugin Development' started by xFlare, Feb 16, 2015.

  1. xFlare
    Offline

    xFlare Active Member Plugin Developer

    Joined:
    Sep 28, 2014
    Posts:
    199
    Plugins:
    1
    Minecraft User:
    xFlare
    How can I remove an item from a players inventory? Thanks!
  2. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    PHP:
    $player->getInventory()->remove(Item $item);
    64FF00 and xFlare like this.
  3. xFlare
    Offline

    xFlare Active Member Plugin Developer

    Joined:
    Sep 28, 2014
    Posts:
    199
    Plugins:
    1
    Minecraft User:
    xFlare
    Item would still be defined like this?
    $item = new Item($id, $damage, $count);
  4. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    Yes! :D
    64FF00 and xFlare like this.
  5. xFlare
    Offline

    xFlare Active Member Plugin Developer

    Joined:
    Sep 28, 2014
    Posts:
    199
    Plugins:
    1
    Minecraft User:
    xFlare
    Thank you :D
    64FF00 likes this.
  6. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    You're always welcome :D
    64FF00 likes this.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $item = Item::get($id, $damage, $cnt)
    PocketKiller, iksaku and 64FF00 like this.
  8. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    Where can i see all these?
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    ?
  10. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    Where can i see all strings for create plugin? Example getInvetory and other..
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Read the docs...
    Or the pocketmine source.
    iksaku and 64FF00 like this.
  12. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    I don't find it
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    64FF00 and Mat like this.
  14. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    64FF00 likes this.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    iksaku and 64FF00 like this.
  16. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    Is the same xD
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No. Item::get() may return a subclass of Item but new Item() always get_class($result) === "pocketmine\item\Item". You should use Item::get() because the subclass does something else.
    iksaku likes this.
  18. Kripto
    Offline

    Kripto New Member

    Joined:
    Mar 2, 2014
    Posts:
    15
    Minecraft User:
    Kripto96
    If you want to remove only 1 or 2 item from the inventory (not the entire slot), I suggest you to use something like this:
    PHP:
    $inventory $player->getInventory();
    for(
    $i=0$i<$inventory->getMaxStackSize(); $i++) {
       if(
    $inventory->getItem($i)->getId() == 46) { //TNT, replace with your ID
          
    $item $inventory->getItem($i);
          if(
    $item->getCount() <= 1) {
             
    $inventory->clear($i);
          } else {
             
    $inventory->setItem($iItem::get(460$item->getCount()-1)); //replace also here with your ID
          
    }
          break;
       }
    }
    atTheDisco likes this.

Share This Page

Advertisement