Hey I was doing this custom death thingie, I want the player who killed a player to be sent a message 'You killed {player} + 5 coins' and then with economy be sent 5$ I think Iv'e almost got it but I'm getting a bit stuck :/ here is the console error: Code: [16:24:33] [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\entity\EntityDamageByEntityEvent' to 'DeathView v0.0.2': Call to a member function sendMessage() on boolean on TheDiamondYT\DeathView\Loader [16:24:33] [Server thread/CRITICAL]: Error: "Call to a member function sendMessage() on boolean" (EXCEPTION) in "/plugins/DeathView-master/src/TheDiamondYT/DeathView/Loader" at line 67 here is the code: PHP: public function onEntityDamage(EntityDamageEvent $ev) { if($ev->isCancelled()) { return; } $entity = $ev->getEntity(); if($entity instanceof Player and $entity->getHealth() - $ev->getDamage() <= 0) { if($entity->getGamemode() === Player::SPECTATOR){ return; } $ev->setCancelled(true); $entity->setGamemode(Player::SPECTATOR); $this->getServer()->getScheduler()->scheduleDelayedTask(new SpectateTask($this, $entity), $this->config["time"] * 20); $entity->addTitle("§c§lYOU DIED!!§r", "§fRespawning..", 15, 15, 15); $level = $entity->getLevel(); $x = $entity->getX(); $y = $entity->getY(); $z = $entity->getZ(); $pos1 = new Vector3($x, $y, $z); $pos = new Vector3($x, $y + 2, $z); $level->addSound(new AnvilFallSound($pos1)); $level->addParticle(new HeartParticle($pos)); $killer = $entity->getLastDamageCause()->getDamager instanceof EntityDamageByEntityEvent; $killer->sendMessage("You killed " . $entity->getNameTag() . " + 5 coins") instanceof EntityDamageByEntityEvent; $money = $this->getServer()->getPluginManager()->getPlugin("EconomyAPI")->addMoney(5)->$player->getName()); return; } (line 67 is: PHP: $killer->sendMessage("You killed " . $entity->getNameTag() . " + 5 coins") instanceof EntityDamageByEntityEvent; ) could anyone help me with this? thanks
The error mentions you try to call sendMessage on a boolean, which is exactly the case. You assign: PHP: $killer = $entity->getLastDamageCause()->getDamager instanceof EntityDamageByEntityEvent So the killer is: Last damage cause instanceof EntityDamageByEntityEvent? Which there is only a boolean to answer. You could do the following to fix this: PHP: if($ev instanceof EntityDamageByEntityEvent) { $killer = $ev->getDamager();} else { return;} That way you assign $killer correctly, and have the check if it is an EntityDamageByEntityEvent.
PHP: public function onEntityDamage(EntityDamageEvent $ev) { if($ev->isCancelled()) { return; } $entity = $ev->getEntity(); if($entity instanceof Player and $entity->getHealth() - $ev->getDamage() <= 0) { if($entity->getGamemode() === Player::SPECTATOR){ return; } if ($ev instanceof \pocketmine\event\entity\EntityDamageByEntityEvent) { $ev->setCancelled(true); $entity->setGamemode(Player::SPECTATOR); $this->getServer()->getScheduler()->scheduleDelayedTask(new SpectateTask($this, $entity), $this->config["time"] * 20); $entity->addTitle("§c§lYOU DIED!!§r", "§fRespawning..", 15, 15, 15); $level = $entity->getLevel(); $x = $entity->getX(); $y = $entity->getY(); $z = $entity->getZ(); $pos1 = new Vector3($x, $y, $z); $pos = new Vector3($x, $y + 2, $z); $level->addSound(new AnvilFallSound($pos1)); $level->addParticle(new HeartParticle($pos)); $killer = $ev->getDamager(); $killer->sendMessage("You killed " . $entity->getName() ." + 5 coins") $money = $this->getServer()->getPluginManager()->getPlugin("EconomyAPI")->addMoney(5, $entity); }