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

How can I get the player that killed the other player?

Discussion in 'Development' started by Minetron26, Sep 20, 2018.

  1. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    Hello there any way to get the player has killed other, ie to make a minigame two players and that when I ended can get the player that killed the other and place it in a variable.
     
  2. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    PHP:
    public function onDeath(PlayerDeathEvent $event)
    {
        
    $player $event->getPlayer();
        
    $lastDamageCause $player->getLastDamageCause();
        if (
    $lastDamageCause instanceof EntityDamageByEntityEvent) {
            
    $killer $lastDamageCause->getDamager();
            if (
    $killer instanceof Player) {
                
    //Killer is a player, set wherever you need it!
            
    }
        }
    }
     
  3. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    Thank you.
     
  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.