I looked at the API and there is no getDamager(), it's only for EntityDamageEvent. If I want to define $killer as the killer of someone, how do I do it? Thankyou
You can do it by using EntityDeathEvent::getEntity()->getLastDamageCause()->getDamager(), HOWEVER, it will only work if the last damage is an instance of EntityDamageByEntityEvent, so you should perform a check for that.
Ich denke das funktioniert PHP: $lastDmg = $spieler-> getLastDamageCause (); If ($lastDmg instanceof EntityDamageEvent) { If ($lastDmg Instanz von EntityDamageByEntityEvent) { $Killer = $lastDmg->getDamager (); [/ PHP] [/ PHP] [/ PHP]
You don't need to check for both EntityDamageEvent and EntityDamageByEntityEvent in this case. An event can only be an instance of EntityDamageByEntityEvent if it is also an instance of EntityDamageEvent, because the first extends the latter. So you only need to perform the second check.
I could, but I'll just redirect you to a good example somebody else already made here. You can use PlayerDeathEvent or EntityDeathEvent, although PlayerDeathEvent removes the need for some checks on what $event->getEntity() may be. This has already been asked in at least two or three other places, too, so you can look around if you are still unclear.