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

RemoveItem

Comments in 'Plugin Development' started by Kripak, Nov 22, 2015.

  1. Kripak
    Offline

    Kripak New Member

    Joined:
    Jul 17, 2015
    Posts:
    45
    Minecraft User:
    Kripak
    How in removeItem make items disappear only one number, but not immediately a 64 ?
    $item->setCount(1); or $item = Item::get(263, 0, 1); //doesn't work
    Last edited: Nov 22, 2015
  2. Kripak
    Offline

    Kripak New Member

    Joined:
    Jul 17, 2015
    Posts:
    45
    Minecraft User:
    Kripak
    No one knows ?
  3. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    $player->getInventory()->removeItem(Item::get(263,0,1));
    zombie_Power likes this.
  4. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    A little more information would have assisted him, understanding how this works :).

    So basically, the code, @wolfdale posted above gets the Inventory of $player (in this case, you can define $player with whatever event you want to define it as, Example: Lets say, I decided to utilise PlayerDeathEvent, and define $player as $event->getPlayer();, this basically means that your code will be activated as soon as the players dies, as we made a public function and defined $event with PlayerDeath Event).

    You can tell (with basic knowledge) that getInventory() would get the Inventory of the player that died. removeItem is also quite as it seems, as you are using it to remove a certain item from that players inventory. When @wolfdale utilised Item::get(), (also known as getItem() ), it allowed him to get a specified item. Finally, the numbers inside Item::get are basically id, meta, amount, so therefore, in this case, the 1 of the items with the id 263, would be removed, after a player dies (Meta is usually 0).

    Final code, if I decided to use PlayerDeathEvent
    PHP:
    public function(PlayerDeathEvent $event){
    $player $event->getPlayer();
    $player->getInventory()->removeItem(Item::get(26301);
    }
    If you want more information, on how these functions work together to produce a final working code (Example: Player extends Human etc..), you can simply message me here, or on the contact methods listed below :)
    Last edited: Nov 24, 2015
    LDX likes this.
  5. Kripak
    Offline

    Kripak New Member

    Joined:
    Jul 17, 2015
    Posts:
    45
    Minecraft User:
    Kripak
    I wrote. It does not work because it is consumed immediately stack (64), and I need to consume one coal.
  6. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    Item::get() and getItem() have the same function, but you have to use ->getItem(), unlike Item::get, whereas Item::get is certainly more efficient than ->getItem()

Share This Page

Advertisement