And now im getting this error: [Server thread/CRITICAL]: pocketmine\utils\PluginException: "pocketmine\event\entity\EntityDamageByEntityEvent does not have a handler list" (EXCEPTION) in "/src/pocketmine/plugin/PluginManager" at line 787 What is this meaning?
You're probably doing this: PHP: public function onDamage(EntityDamageByEntityEvent $event) { //stuff} but it should be: PHP: public function onDamage(EntityDamageEvent $event) { if($event instanceof EntityDamageByEntityEvent) { //stuff }}
This is because EntityDamageEvent can be used as an event listener argument, but not EntityDamageByEntityEvent. You can identify this by the $handlerList property in the file.
Still getting error: [Server thread/CRITICAL]: pocketmine\utils\PluginException: "pocketmine\event\entity\EntityDamageByEntityEvent does not have a handler list" (EXCEPTION) in "/src/pocketmine/plugin/PluginManager" at line 787 Ive no idea why
use PHP: public function onDamage(EntityDamageEvent $event) {$damager = $event->getDamager();$player = $event->getPlayer(); $damager->sendMessage("Your message"); }
Show your code please! This is incorrect. EntityDamageEvent doesn't have a function getDamager(). You should first check if the event is instanceof EntityDamageByEntityEvent.
This is my code: PHP: public function onDeath(EntityDamageByEntityEvent $event){ if($event instanceof EntityDamageByEntityEvent){ $health = $event->getEntity()->getHealth(); $damager = $event->getDamager(); $player = $event->getPlayer(); if($damager instanceof \pocketmine\Player){ if($health === 0){ if($levelofkiller == ""){ $levelofkiller = 1; } if($levelofkilled == ""){ $levelofkilled = 1; } } //Ab hier steht, was passiert wenn der Spieler stirbt :D $levelofkiller = $levelofkiller + 1; $levelofkilled = $levelofkilled - 1; if($levelofkilled === -1){ $levelofkilled = 1; } $this->getServer()->broadcastMessage("The level of killer is $levelofkiller of killed is $levelofkilled"); } } }
Ive changed the code to this PHP: public function onDamage(EntityDamageEvent $event){ $health = $event->getEntity()->getHealth(); $damager = $event->getEntity()->getLastDamageCause(); if($health === 0){ if($damager instanceof \pocketmine\Player){ $damager->sendMessage("You are the Damager!!!"); } } } But event this is not working and i need that the plugin is finished to 90% bug free an 24th.
You should have kept that if statement where you check if the event is instanceof EntityDamageByEntityEvent, if you want to make use of the getDamager() method.
The Damager is getting no Message :/ PHP: public function onDamage(EntityDamageEvent $event){ if($event instanceof EntityDamageByEntityEvent){ $health = $event->getEntity()->getHealth(); $damager = $event->getEntity()->getLastDamageCause(); if($health === 0){ if($damager instanceof \pocketmine\Player){ $damager->sendMessage("You are the Damager!!!"); } } } }
Change the line: $damager = ... to: PHP: $damager = $event->getDamager(); and I'm not sure why you would do the $health === 0, wouldn't you use playerDeathEvent for that?
I found a solution! PHP: public function onDeath(PlayerDeathEvent $event){ $ldc = $event->getPlayer()->getLastDamageCause()->getEntity(); if($ldc instanceof \pocketmine\Player){ $damager = $ldc->getPlayer()->getNameTag(); $iskilled = $event->getPlayer()->getNameTag(); $event->setDeathMessage(TextFormat::RED."$iskilled ".TextFormat::BLUE."wurde von ".TextFormat::GOLD."$damager".TextFormat::BLUE." getötet"); } } THX A LOT
Why $ldc->getPlayer()... Player->getPlayer() returns the player itself... And the $damager should be the dead player according to what you have written.