How do I get last damager? so I want to make a death message dropped on the void by the damager, how do I get people who dropped enemies on the void.
Try: PHP: public function onEntityDamage(EntityDamageEvent $ev){ $p = $ev->getEntity(); $kill = $p->getLastDamage();}
if the player is dropped to void, so how do I send a message, $player has thrown to the void by $killer? if the player is not in void the message will be changed to $player has been killed by $killer. How do I differentiate between players dropped and killed PHP: case EntityDamageEvent::CAUSE_ENTITY_ATTACK: if($player->getY() < 5){ $message = $player->getName()." has thrown to the void by ".$killer->getDisplayName(); return; } $message = $player->getName()." was killed by".$killer->getName();break; i was tried it but not work
$damager ($killer) can be get from EntityDamageByEntity event... You can check if last damage ($event->getLastDamageCause() is this class using 'instanceof') PHP: $lastDmg = $event->getLastDamageCause();if($lastDmg instanceof EntityDamageByEntityEvent) { $damager = $lastDmg->getDamager(); //code - player was thrown into the void by some entity if($damager instanceof Player) { // player was thrown into the void by player } else { // player was thrown into the void by some entity, not with player (in pmmp almost impossible) }}else { // player jumped into the void} Also you can check void damage if you are checking entity damage... PHP: case EntityDamageEvent::CAUSE_ENTITY_ATTACK: // wrong, just remove the switch