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

Solved EntityDeathEvent setDrops

Comments in 'Plugin Development' started by MikkiMCPE, May 23, 2016.

  1. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    hi, anyone can help me how to use setDrops() on EntityDeathEvent ??

    i write this, but not working when player died

    PHP:
    public function onDeath(EntityDeathEvent $ev){
    $player $ev->getEntity();
    if(
    $player instanceof Player){
    $drop = array(Item::get(Item::IRON_INGOT01));
    $ev->setDrops($drop);
    }
    }
    thank you
  2. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    I think it's the item array, try using the item's id instead of its name:
    PHP:
    $drops = array(Item::get(265));
    Also, make sure you're using pocketmine\item\Item
    Last edited: Jun 6, 2016
    MikkiMCPE likes this.
  3. Yosshi999
    Offline

    Yosshi999 New Member Plugin Developer

    Joined:
    Mar 13, 2014
    Posts:
    29
    Plugins:
    1
    Minecraft User:
    Yosshi999
    use PlayerDeathEvent.
  4. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    can you give me example usage? and i can find setDrops() function on PlayerDeathEvent
  5. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    i'll try
  6. Yosshi999
    Offline

    Yosshi999 New Member Plugin Developer

    Joined:
    Mar 13, 2014
    Posts:
    29
    Plugins:
    1
    Minecraft User:
    Yosshi999
    I think your code will work when you just change "EntityDeathEvent" into "PlayerDeathEvent".
  7. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    That will only break it, he's constructing the item correctly. You should always use the constants as they can easily be updated and no code will break if the ID's change.

    PHP:
     EntityDeathEvent::setDrops(array()); 
    PlayerDeathEvent extends EntityDeathEvent so it inherits all properties and functions.
    Try this
    PHP:
    <?php

    namespace name\space;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerDeathEvent;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\item\Item;

    class 
    Listener implements Listener {

        public function 
    onDeath(PlayerDeathEvent $event) {
            
    $cause $event->getEntity()->getLastDamageCause()->getCause();
            if(
    $cause instanceof EntityDamageByEntityEvent) {
                
    $event->setDrops([Item::get(Item::IRON_IGNOT01)]);
               
            }

        }

    }
    Last edited: May 23, 2016
  8. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    okay,

    sorry for this xD

    PHP:
    class PlayerDeathEvent extends EntityDeathEvent{
  9. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    BTW bro, please read again on PlayerDeathEvent, and EntityDamageEvent, there is no function called getCause()
  10. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Edited :p
  11. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    Okay solved, thanks for everyone was help me, i found my way ;)
  12. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Ugh.. php.net.
    MikkiMCPE likes this.
  13. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    i want said it before, but he have Plugin Developer tag ;)
  14. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Just because he has the plugin developer tag doesn't mean he's an all knowing source of information.
  15. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Why would you use Item::get("265") rather than Item::get(265)?
  16. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    Oh oops, you wouldn't. I missed that lol

Share This Page

Advertisement