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

Help, remove the item from the player's inventory

Comments in 'Plugin Development' started by Barrington, Aug 4, 2015.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    So there is not method for that i think
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Try this:
    PHP:
    $item = new Item(108);
    if(
    $player->getInventory()->contains(Item $item)) $player->getInventory()->removeItem($item);
  3. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    I know but when i have item in more slots it doesnt remove it
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    For the last time, use Item::get() instead of new Item().
    Code?
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    lol, do foreach();
  6. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    I know but it is complicated
    PEMapModder likes this.
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    foreach($player->getInventory()->getContents() as $item){
    if(
    $item === Item::get(108)){
    $player->getInventory()->removeItem($item);
    }
    }
  8. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    It is still same
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Wait are you doing this
    [STONE x1],[Stone x5], [Stone x2]
    And trying to remove all if in player's inventory has total 8 stones?
  10. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It won't work. You can't use === to compare two objects unless they are exactly the same one (not structurally the same one). For example, for players and levels, because you won't create new instances of them, two levels of same name are supposedly the same object. However, items are almost instantiated every use. In that case, you can't compare it.
    Creeperface and Legoboy0215 like this.
  12. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Yes new Vector3(1, 1, 1) != new Vector3(1,1,1)
  13. Barrington
    Offline

    Barrington New Member

    Joined:
    Jul 31, 2015
    Posts:
    41
    Minecraft User:
    Berrington
    Woow
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No, use $a->x === $b->x and $a->y === $b->y and $a->z === $b->z
  15. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    i meant that xD
  16. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    this is method when player buy item can it works?
    PHP:
    public function onBuy(Player $pItem $buyItemItem $costItem){
            
    $inv $this->players[strtolower($p->getName())]['items'];
            
    $cost $costItem->getCount();
            foreach(
    $inv->getContents() as $slot => $item){
                if(
    $cost <= 0){
                    if(
    $item->getId() === $costItem->getId() && $item->getDamage() === $costItem->getDamage() && $item->getCount() >= 1){
                        if(
    $item->getCount() > $cost){
                            
    $inv->setItem($slotItem::get($costItem->getId(), $costItem->getDamage(), $item->getCount() - $costItem->getCount()));
                            
    $cost 0;
                            continue;
                        }
                        
    $inv->setItem($slotItem::get(000));
                        
    $cost $cost $item->getCount();
                        continue;
                    }
                }
    else{
                
    $inv->addItem($buyItem);
                
    $p->sendMessage($this->plugin->plugin->getPrefix().TextFormat::GREEN."Bought {$buyItem->getName()}");
                return;
    }
            }
            
    $p->sendMessage($this->plugin->plugin->getPrefix().TextFormat::RED."You don't have enough ".$costItem->getName());
        }
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Wtf $this->plugin->plugin
  18. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Yes it is main class :D
    And what do you think?
  19. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    OMG my code works!!!
  20. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Bravo

Share This Page

Advertisement