Hi, is it possible to do an action on EntityDamageByEntityEvent if I hit an entity with a specified entityID like: If I hit an entity with the ID 10 [Chicken] I'll get a message "Wow you hitted a chicken"
Make sure to use EntityDamageEvent and then get if the event is an instance of an EntityDamageByEntityEvent. $entity = $event->getEntity(); if($entity instanceof Chicken){ /*code here */ }
Looked at http://docs.pocketmine.net/d9/d0b/c...hicken.html#ad83d873f703ba299ba402302c3ef6cbf $entity->getId() exists
$entity->getId() is the entity ID, which is unique for every instance of entity in one server runtime, and reset per server restart (probably even changes when their chunks is reloaded). This thread asks for the entity type ID, not the entity ID. According to somewhere in PocketMine source code, you can use $entity::NETWORK_ID for the type ID.
That quote is actually about string variables. My usage was to use object variables. http://stackoverflow.com/documentat...t-and-class-operators#t=201608071814465224089
There are three possible things you're wanting to find/know as far as I can tell from reading this thread. The most probable answer I think would be one where you are able to get the name of an entity as a string, not the EID. Get an entities name (string): PHP: // Getting an entities name regardless of it's type/EID$entity->getName(); I'll post the other answers in case you or someone else wants to know them. Get an entities type/EID (int): PHP: // Get the EID of any entity$entity::NETWORK_ID; Get an entities unique identifier: PHP: // Get the unique identifier of an entity$entity->getId(); These are the three answers I could see you seeking, if the answer you're searching for isn't here please explain in more detail what you are wanting to know.
You're half right, if you wanted to send to damager/attacker a message telling them the name of the mob they'd hit you would simply do: PHP: public function onDamage(pocketmine\event\entity\EntityDamageEvent $event) { $victim = $event->getEntity(); $cause = $victim->getCause(); if($cause instance of pocketmine\event\entity\EntityDamageByEntityEvent) { $damager = $event->getDamager(); $damager->sendMessage("You dealt " . $event->getFinalDamage() / 2 . " hearts of damage to " . $victim->getName()); }} Within a registered event listener class of course.