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

PlayerDeathEvent troubles

Comments in 'Plugin Development' started by Hotshot_9930, Jun 28, 2015.

  1. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    So I am trying to make something happen when a player is killed by another player. The code works, except the server crashes f the player is killed by a block, fire, TNT etc. The code looks something like
    PHP:
    Public function playerDeath(PlayerDeathEvent $event) {
    $victim $event->getEntity();
    $cause $victim->getLastDamageCause();
    $killer $cause->getDamager();

    if(
    $killer instanceof Player) {
    //Blah blah;
    }
    }
    The console gives an error message saying "Call to undefined function EntityDamageEvent::getDamager()"

    Any tips or suggestions?
    Last edited: Jun 28, 2015
  2. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    What line does it say is the problem?
  3. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    The fourth line
  4. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    I think the reason is some cause didn't have damager
  5. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    add
    PHP:
    if($cause instanceof EntityDamageByEntityEvent){
    }
    Before the instanceof Player code.
  6. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    I'm still getting
    Code:
     Fatal error: Call to undefined method pocketmine\event\entity\EntityDamageEvent::getDamager()
    for line 4
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What, $if?
  8. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    That was just a typo on here. Its not in the actual plugin
  9. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    You did it wrong,
    PHP:
    public function onDeath(PlayerDeathEvent $event) {
        
    $victim $event->getEntity();
        
    $c $victim->getLastDamageCause();
        if(
    $c instanceof EntityDamageByEntityEvent) {
            
    $killer $c->getDamager();
            
    //Your stuff goes here
        
    }
    }
    Last edited: Jun 28, 2015
    CraftYourBukkit likes this.
  10. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    Omg. First you start with $c then you use $cause
  11. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    whoops, I cant read over what I've typed properly on my phone.
  12. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    thank you so much :) it works perfectly now

Share This Page

Advertisement