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

Solved How to get assassin?

Discussion in 'Development' started by Th3Ang3lo, Dec 21, 2018.

  1. Th3Ang3lo

    Th3Ang3lo Spider Jockey

    Messages:
    32
    GitHub:
    Th3Ang3lo
    Guys, how do I get the killer player? I tried to use
    PHP:
    $killer $ev->getLastDamager();
    but I did not succeed ...

    My PHP is:
    PHP:
    public function onDeath(PlayerDeathEvent $ev){
        
    $vitima $ev->getEntity();
        
    $assasino $ev->getLastDamager();
        if(
    $vitima instanceof Player && $assasino instanceof Player)    {
            
    $vitima->sendMessage(Loader::PREFIX." Você morreu§e ".$assasino->getName());
            
    $assasino->sendMessage(Loader::PREFIX." Você matou§e ".$vitima->getName());
        }
    }
    Error in console is:
    Code:
    [13:34:50] [♥PTK-KienPham♥-CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerDeathEvent' to 'WhinterCORE v1': Call to undefined method pocketmine\event\player\PlayerDeathEvent::getLastDamager() on WNCORE\Plugins\CustomAlerts\CustomAlerts
    [13:34:50] [♥PTK-KienPham♥-CRITICAL]: Error: "Call to undefined method pocketmine\event\player\PlayerDeathEvent::getLastDamager()" (EXCEPTION) in "/WhinterCore PL/src/WNCORE/Plugins/CustomAlerts/CustomAlerts" at line 29
    
    
    My line 29 is variable:
    PHP:
    $assasino $ev->getLastDamager();
     
  2. Enes5519

    Enes5519 Spider Jockey

    Messages:
    28
    GitHub:
    Enes5519
    I didn't test it.
    PHP:
    public function onDeath(PlayerDeathEvent $ev){
        
    $cause $ev->getLastDamageCause();
        if(
    $cause instanceof EntityDamageByEntityEvent and $cause->getDamager() instanceof Player){
            
    $player $ev->getPlayer();
            
    $damager $cause->getDamager();
            
    $player->sendMessage(Loader::PREFIX." Você morreu§e ".$damager->getName());
            
    $damager->sendMessage(Loader::PREFIX." Você matou§e ".$player->getName());
        }
    }
     
  3. Th3Ang3lo

    Th3Ang3lo Spider Jockey

    Messages:
    32
    GitHub:
    Th3Ang3lo
    [
    [21:02:55] [♥PTK-KienPham♥-CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerDeathEvent' to 'WhinterCORE v1': Call t o undefined method pocketmine\event\player\PlayerDeathEvent::getLastDamageCause() on WNCORE\Plugins\CustomAlerts\CustomAlerts
    [21:02:55] [♥PTK-KienPham♥-CRITICAL]: Error: "Call to undefined method pocketmine\event\player\PlayerDeathEvent::getLastDamageCaus e()" (EXCEPTION) in "/WhinterCore PL/src/WNCORE/Plugins/CustomAlerts/CustomAlerts" at line 46


    [
     
  4. Th3Ang3lo

    Th3Ang3lo Spider Jockey

    Messages:
    32
    GitHub:
    Th3Ang3lo
    My plugins is working, i'm used other code.

    Correct is:
    PHP:
    public function onDeath(PlayerDeathEvent $ev){
            
    $p $ev->getPlayer();
            
    $cause $p->getLastDamageCause();
            if(
    $cause instanceof EntityDamageByEntityEvent){
                
    $killer $cause->getDamager();
                
    $ev->setDeathMessage(Loader::PREFIX." §e".$p->getName()." §7foi morto(a) por§e ".$killer->getName());
            }else{
                
    $ev->setDeathMessage("");
            }
        }
     
    xXNiceAssassinlo YT likes this.
  5. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    I was gonna send u this too xd
     
  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.