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

Get player's killer onPlayerDeath

Discussion in 'Facepalm' started by Thouv, Feb 12, 2017.

  1. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
    So, how do I get the player's name or Player object with onPlayerDeath?
    This seemed too short so I'm just adding this random text, and you just wasted 5 seconds of your life reading it. Sorry.
     
  2. TheNewHEROBRINE

    TheNewHEROBRINE Spider

    Messages:
    8
    GitHub:
    thenewherobrinex
    Do you mean the player that died or the player that killed the one who died?
     
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    both i suspect
     
  4. TheNewHEROBRINE

    TheNewHEROBRINE Spider

    Messages:
    8
    GitHub:
    thenewherobrinex
    PHP:
    public function onDeath(PlayerDeathEvent $event) {
            
    $cause $event->getPlayer()->getLastDamageCause();
            if (
    $cause instanceof EntityDamageByEntityEvent and $cause->getDamager() instanceof Player) {
                
    $killer $cause->getDamager();
            }
        }
     
  5. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
    Smart, hadn't though of that
    Thx
     
  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.