In an PayerInteractEvent player are able to launch snowball with 10 dommage if snowball hit an other player But how can i get thé $killer and the $victim? PHP: public function onDamage(EntityDamageEvent $event){ $victim = $event->getEntity(); $cause = $event->getCause(); if($cause == EntityDamageEvent::CAUSE_PROJECTILE){ if($event instanceof Player){ $event->setDamage(10); $killer = $event->getDamager(); $welt = $killer->getLevel()->getFolderName(); $arenaname = $this->getConfig()->get("arena"); $this->Title($victim, "§4Death", $killer->getName()); $this->Title($killer, "§2Kill", $victim->getName()); $this->GunItems($victim); $this->GunItems($killer); $deathmsg = $this->getLanguage()->get("player.death"); $deathmsg = str_replace("{player}", $killer->getName(), $deathmsg); $victim->sendMessage($this->prefix . $deathmsg); $killmsg = $this->getLanguage()->get("player.kill"); $killmsg = str_replace("{player}", $victim->getName(), $killmsg); $killer->sendMessage($this->prefix . $killmsg); return; } } }
You do realize $event in this case can never be a Player instance, right? Back to your question, you can always var_dump($event) and get the required cases. In your case, $event->getDamager() should be the projectile and $event->getDamager()->getOwningEntity() should be the entity who fired the projectile (this can also return null at times, so make sure you handle that too. For example when a player fires a projectile and logs out, and the projectile later hits an entity).
try this code it should work fine. PHP: public function onDamage(EntityDamageEvent $event){ $victim = $event->getEntity(); $cause = $event->getCause(); if($cause == EntityDamageEvent::CAUSE_PROJECTILE){ if($victim instanceof Player){ $event->setDamage(10); $killer = $event->getDamager(); $welt = $killer->getLevel()->getFolderName(); $arenaname = $this->getConfig()->get("arena"); $this->Title($victim, "§4Death", $killer->getName()); $this->Title($killer, "§2Kill", $victim->getName()); $this->GunItems($victim); $this->GunItems($killer); $deathmsg = $this->getLanguage()->get("player.death"); $deathmsg = str_replace("{player}", $killer->getName(), $deathmsg); $victim->sendMessage($this->prefix . $deathmsg); $killmsg = $this->getLanguage()->get("player.kill"); $killmsg = str_replace("{player}", $victim->getName(), $killmsg); $killer->sendMessage($this->prefix . $killmsg); return; } } }
PHP: public function onDamage(EntityDamageByEntityEvent $event){ $victim = $event->getEntity(); $cause = $event->getCause(); if($cause == EntityDamageEvent::CAUSE_PROJECTILE){ if($victim instanceof Player){ $event->setDamage(10); $killer = $event->getDamager(); if($killer instanceof Player){ $deathmsg = $this->getLanguage()->get("player.death"); $deathmsg = str_replace("{player}", $killer->getName(), $deathmsg); $victim->sendMessage($this->prefix . $deathmsg); $killmsg = $this->getLanguage()->get("player.kill"); $killmsg = str_replace("{player}", $victim->getName(), $killmsg); $killer->sendMessage($this->prefix . $killmsg); return; } } } }
That won't work, $event->getDamager() is a projectile PHP: $projectile = $event->getDamager();if($projectile instanceof Projectile){//pocketmine/entity/projectile/Projectile $projectileShooter = $projectile->getOwningEntity();//this can be null if the victim was damaged after the shooter logged out.}