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

PlayerDeathEvent

Discussion in 'Development' started by SavionLegendZzz, Jan 7, 2017.

  1. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    PHP:
    public function onDeath(PlayerDeathEvent $ev){
            
    $victim $ev->getEntity();
            
    $ev->setDeathMessage(null);
            if(
    $victim instanceof Player){
                
    $player $victim;
                
    $cause $player->getLastDamageCause();
                if(
    $cause instanceof EntityDamageByEntityEvent){
                    
    $killer $cause->getDamager();
                    if(!
    $this->getPlugin()->isInMatch($killer)) return;
                        
    $match $this->getPlugin()->getMatch($killer);
                        
    $match->removePlayer($player);
                        
    $this->getPlugin()->win($killer);
                }
            }
        }
    When ever a player dies and they are in a match it dosent seem to call the event(it wont remove the player that died or call the win function)
     
  2. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Why do u use getEntity?
     
  3. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    Always have and always will i know they added "getPlayer()" but it's more of a natural reaction to type "getEntity()"
     
  4. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Do u have any error?
     
    applqpak likes this.
  5. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
  6. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Do u imported PlayerDeathEvent?
     
    applqpak likes this.
  7. Lambo

    Lambo Spider

    Messages:
    14
    GitHub:
    Lambo16
    Debug it. You can't really expect us to help when we don't understand how the methods you're using work. I suppose that the isInMatch method is returning false and you use return after that so it stopped. But I actually have no clue.
    tl;dr echo the values of the methods you are using in the if statements and see which wrongs should be different.
     
    Thunder33345 and applqpak like this.
  8. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    is this in the main file?
     
  9. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    try adding echo before every IF statements
     
  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.