PHP: <?php namespace MyPlugin\ZaydPE;use pocketmine\plugin\PluginBase;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\entity\EntityDamageByChildEvent;use pocketmine\entity\Entityclass Main extends PluginBase{ public function onEntityDamageByEntityEvent; $damager->sendMessage("$entity has $health/$maxHealth hearts left!"); } The code is here; bare in mind this is my first plugin and i have just learnt php
You are missing a ";" at "use pocketmine\entity\Entity". That's an invalid function. No variables were defined. The class must implement \pocketmine\event\Listener if you are going to call event functions from it.
Thankyou. By adding the use use pocketmine\entity\Entity; Isn't the $health + $damager variable already defined?
Oh dear. You didn't understand anything about scope of variables are and what classes are. You might want to go learn that here: http://php.net/manual/en/book.classobj.php http://php.net/manual/en/language.variables.scope.php https://en.wikipedia.org/wiki/Scope_(computer_science)
where in your code does it say PHP: $health = $ev->getEntity->getHealth();$damager = $ev->getDamager();
$ev is actually supposed to be declared in your function please learn how function look&work in php http://php.net/manual/en/language.functions.php Really, your knowledge is too limited to continue here.
I recommend you to start basic of php on http://php.net You have not defined variables $health,$damager Here is correct code your your. PHP: public function onDamage(EntityDamageEvent $e){if($e instanceof EntityDamageByEntityEvent){$damager = $e->getDamager();$health = $e->getEntity()->getHealth();$maxHealth = $entity->getMaxHealth(); //If you are not using $entity->setMaxHealth() You can do $health/20 instead $maxHealth$damager->sendMessage("$entity has $health/$maxHealth hearts left!");}} The most used function are in Player.php https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/Player.php and Server.php https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/Server.ph
It's better to use (') than (") while declaring string. You be the example. It just confused the readers and probably even PHP in understanding whether the / is meant to be a string or a mathematical operator for division of $health by $maxhealth. Better use PHP: $damager->sendMessage($entity.' has '.$health.'/'.$maxHealth.' hearts left!');