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

what i did wrong

Discussion in 'Development' started by VCraft, Dec 19, 2016.

  1. VCraft

    VCraft Witch

    Messages:
    60
    GitHub:
    VCraftMCPE
    Call to a member function getDamager() on null" (EXCEPTION) in "/KillerTime.phar/src/VCraft/KT/Main" at line 22

    PHP:
    $ca $entity->getLastDamageCause();
                    
    $ks $ca->getDamager();
                if(
    $ks instanceof Player){
     
    Last edited by a moderator: Dec 19, 2016
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Because $ca is null?

    Please provide your scope for the event.
    You may want to think about whether the entity really must have just been damaged. If he might not, check if $ca === null and do appropriate actions and stop code execution after handling this exceptional case.
     
    VCraft and Palente like this.
  3. VCraft

    VCraft Witch

    Messages:
    60
    GitHub:
    VCraftMCPE
    Okay The full code is
    PHP:
    public function onPlayerDeath(EntityDeathEvent $event){
                  
    $entity $event->getEntity();
                
    $ca $entity->getLastDamageCause();
                    
    $ks $ca->getDamager();
                if(
    $ks instanceof Player){
            
    $this->mcmmo->addskills($ks->getName(),1);
     
  4. VCraft

    VCraft Witch

    Messages:
    60
    GitHub:
    VCraftMCPE
    so i didnt anything wrong?
     
  5. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    you should check if the last damage cause was caused by php/evp.
     
  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.