How To Get Item On Player's Inventory

Discussion in 'Facepalm' started by Bintang Putra, Jun 2, 2017.

  1. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    Hi, I Want To Check If The Player Has An Items That Required By The Plugin

    Example :
    The Plugin Need 2 Feathers , Then The Plugin Check The Player's Inventory, If True Then The Plugins Will Take 2 Feathers From The Player's Inventory

    One More, Is It Possible To Check An Items With Name From The Player's Inventory?
    Example :
    I Want To Check If The Players Have 2 Feathers Named "BirdFeather" , Then The PLugin Take The 2 Feathers Named "BirdFeather"

    Im Sorry For My Bad English
     
  2. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    PHP:
    $player $event->getPlayer(); // Use this if you're using an event
    $inventory $player->getInventory();
    if(
    $inventory->contains(Item::get(28802))) {
        
    $inventory->removeItem(Item::get(28802));
    }
     
    jasonwynn10 likes this.
  3. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    Thanks :D
     
  4. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    but, How To Check If The Item Had A Custom Name ? Coz, I Only Want To Take An Item WIth A Custom Name
     
  5. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Anvils are not added to PocketMine yet (they are, but you cannot use them).

    I don't know any way to do that.
    I tried adding a new item called "Bird Feather" also as a feather item, but it won't work.
     
  6. VampRikka

    VampRikka Shog Chips

    Messages:
    0
    GitHub:
    lolazir1
    What event :)
     
  7. PHP:
    $player $event->getPlayer(); // Use this if you're using an event
    $inventory $player->getInventory();
    $item Item::get(28802);

    if(
    $inventory->contains($item) and $item->getName() === "BirdFeather") {
        
    $inventory->removeItem(Item::get(28802));
    }
    and to set custom item name use
    PHP:
    /* @var $item = Item */

    $item->setCustomName("BirdFeather");
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.