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();
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()); }}
[ [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 [
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(""); } }