1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

i want help in my plugin

Discussion in 'Development' started by kingryian, Sep 6, 2017.

  1. kingryian

    kingryian Creeper

    Messages:
    3
    GitHub:
    kingryian
    Hi guys i want to make if player died drop item how i can do it ?

    thanx for help <3
     
  2. Aviv

    Aviv Baby Zombie

    Messages:
    156
    PHP:
    public function onEntityDeath(\pocketmine\event\entity\EntityDeathEvent $event){
      if((
    $player $event->getEntity()) instanceof \pocketmine\Player){
        
    $event->setDrops(array_push($event->getDrops(), \pocketmine\item\Item::get($id$meta$count)));
      }
    }
     
    Sandertv likes this.
  3. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    There are a few errors in this code...
    EntityDeathEvent::getDrops() returns the drops array, but you cannot push a value into the array through the function
    array_push() returns an integer, not the drops array.
    If we are checking for a player's death, then why dont we use a PlayerDeathEvent?
    PHP:
    public function onPlayerDeath(\pocketmine\event\player\PlayerDeathEvent $event){
        
    $drops $event->getDrops(); //get the current drops array
        
    $drops[] = \pocketmine\item\Item::get(\pocketmine\item\Item::AIR01); // Add a new Item to the array
        
    $event->setDrops($drops); // Set the new drops array
    }
     
    Az928, Enes5519 and PocketKiller like this.
  4. NickTehUnicorn

    NickTehUnicorn Zombie

    Messages:
    200
    GitHub:
    unickorn
    As far as I understand, this will drop the player's inventory + the added item.

    How do we, for example, drop a cookie and nothing else when a player dies?
     
  5. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    PHP:
    $event->setDrops([Item::get(Item::COOKIE01)]);
     
    NickTehUnicorn and jasonwynn10 like this.
  6. Aviv

    Aviv Baby Zombie

    Messages:
    156
    yeah I just didn't want ppl to copy pasta XD
     
    jasonwynn10 likes this.
  7. Aviv

    Aviv Baby Zombie

    Messages:
    156
    PlayerDeathEvent exists?! I thought it was renamed to EntityDeathEvent
    I learnt 2 things in 1 day o_O
     
    jasonwynn10 likes this.
  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.