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

get killer on Death event

Comments in 'Plugin Development' started by Creeperface, Jul 28, 2015.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    what is wrong?
    PHP:
    $lastDmg $p->getLastDamageCause();
            if(
    $lastDmg instanceof EntityDamageEvent){
                if(
    $lastDmg instanceof EntityDamageByEntityEvent){
                
    $killer $lastDmg->getDamager();
                if(
    $killer instanceof Player){
                    
    //somethimg
                    
    return;
                }
                if(
    $killer instanceof \pocketmine\entity\Projectile){
                       
    $damager $killer->shootingEntity;
                }
                return;
                }
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Actually, if you checked it is EntityDamageByEntityEvent, it must be an EntityDamageEvent. No need to check both.

    If Alice sends an arrow to kill Bob, getEntity returns Bob, getDamager is Alice and getChild is arrow. The event is instanceof EntityDamageByChildEntityEvent.
    CraftYourBukkit likes this.
  3. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace

Share This Page

Advertisement