I'm trying to make a simple system of when to kill the entity and earn MobCoins But I made a code and it didn't catch can you help me and see what's wrong? It doesn't give any error on the console, it just doesn't catch NO CONSOLE ERROR. IT JUST DOESN'T CATCH PHP: <?phpnamespace MasterFeio\Events;use pocketmine\event\Listener;use pocketmine\plugin\PluginBase;use pocketmine\event\entity\EntityDeathEvent;use pocketmine\event\entity\{EntityDamageEvent, EntityDamageByEntityEvent};use MasterFeio\Main;class MobCoins implements Listener { private $owner; public function __construct(Main $owner){ $this->owner = $owner; $this->mobc = $this->owner->getServer()->getPluginManager()->getPlugin("MobCoins"); } public function onDeath(EntityDeathEvent $e){ $p = $e->getEntity(); if($p->getLastDamageCause() instanceof EntityDamageByEntityEvent){ $killer = $p->getLastDamageCause(); if($killer instanceof Player){ $killer->sendMessage("test"); $this->mobc->addmobc($killer, 1); } }}}
It would be a lot easier to handle this inside of the Entity's class itself. If you are implementing the entity ofcourse... Otherwise you could listen for EntityDamageByEntityEvent and make sure the event->getEntity() is not an instance of a player and check if the difference between the entities health and the events final damage is less than 0.1. Than just run the code because the entity is dead. Psuedocode: PHP: public function onDamage(EntityDamageByEntityEvent $event) { $damager = $event->getDamager(); if ($damager instanceof Player) { $entity = $event->getEntity(); if (!$entity instanceof Player) { if (($entity->getHealth() - $event->getFinalDamage()) < 0.1) { // Give MobCoins Here to $damager } } }}
I think this code might actually work if you just paste it in lol... Haven't done PHP or Pocketmine in awhile tho...