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

Get killer

Comments in 'Plugin Development' started by Sensej, Sep 2, 2014.

  1. Sensej
    Offline

    Sensej New Member

    Joined:
    Aug 5, 2014
    Posts:
    64
    Hello Coder,
    I was searching a methode to get the killer of a player. I saw something in the src code on Pocketmine but dont understand that.
    If i take the EntityDamageByEntityEvent
    i only can get the damager where the normal player is alive. But i want to get the damager and normal player where the normal player got killed by the damger (sorry for bad description)
    -Sensej
  2. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    PHP:
    <?php
        
    public function onDeath(EntityDeathEvent $event){
            
    $entity $event->getEntity();
            
    $cause $entity->getLastDamageCause(); //get the last damage cause
            
    if($cause instanceof EntityDamageByEntityEvent){ //if the cause is by an another entity
                
    $killer $cause->getDamager(); //gets the event damager
                
    if($killer instanceof Player){
                    
    $entity->sendMessage($killer." is your killer");
                }
            }
        }

    Should be something like this :)
    Comedyman937 and Sensej like this.
  3. Sensej
    Offline

    Sensej New Member

    Joined:
    Aug 5, 2014
    Posts:
    64
    Yes Thank you but i think you forgot to get the name ;)
    PHP:
    public function onDeath(EntityDeathEvent $event){
            
    $entity $event->getEntity();
            
    $cause $entity->getLastDamageCause(); //get the last damage cause
            
    if($cause instanceof EntityDamageByEntityEvent){ //if the cause is by an another entity
                
    $killer $cause->getDamager(); //gets the event damager
                
    if($killer instanceof Player){
                    
    $entity->sendMessage($killer->getName()." is your killer"); //;)
                
    }
            }
        }
  4. tnpxxsheepdog
    Offline

    tnpxxsheepdog Notable Member

    Joined:
    Dec 31, 2013
    Posts:
    356
    Minecraft User:
    TNPXXSHEEPDOG
    $killer should define the player name.
  5. Minetox
    Offline

    Minetox New Member

    Joined:
    Jun 23, 2014
    Posts:
    34
    Minecraft User:
    Minetox
    Nope. The Output would be Player(1) or player(2...)
    Sensej is rigth :) you have to use getName() if you want the Player Name
    Dutok and Sensej like this.
  6. tnpxxsheepdog
    Offline

    tnpxxsheepdog Notable Member

    Joined:
    Dec 31, 2013
    Posts:
    356
    Minecraft User:
    TNPXXSHEEPDOG
    Gotcha! Thanks for helping out :)
  7. Dutok
    Offline

    Dutok Notable Member Plugin Developer

    Joined:
    Jun 20, 2014
    Posts:
    372
    Plugins:
    3
    Minecraft User:
    Dutok
    Isn't $killer in this situation the Player object? Wouldn't it spit out an error? :p
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Entity::__toString()
    Dutok and 64FF00 like this.

Share This Page

Advertisement