Hi. How i'm can get Entity in CommandSender?? e.g in EntityDamageEvent: $entity = $event->getEntity();
but I know how to add life but i need code to get the entity. e.g to get player i use: $sender->getPlayer(); But i need to get the zombie entity
if($sender instanceof Player){ $sender->setMaxHealth(/*health*/); } Is the entity you want supposed to be a player?
He wants to get a entity by some identifier, you can use entity name, like 'Zombie' but that's not unique. PHP: $eName = "zombie";foreach($this->getServer()->getLoadedLevels() as $level){ foreach($level->getEntities() as $en){ if(strtolower($en->getName()) === $eName) $en->setHealth($en->getMaxHealth()); }} deficiency of php knowledge is your only problem.
If its another entity, yes you could do that. But I do not lack knowledge in PHP, while everyday I learn something new about PHP, there will always be something you can learn.
My bad, I thought it was aimed at me. Well how would a Zombie run a command? I mean if they did something you could dispatch a command, but I don't think it would label them as running the command.
Yes they can. You can set a zombie as the command sender. PHP: $server->dispatchCommand($zombieObject, $commandString);
"$sender->getPlayer()" is useless in this case. PHP: if($sender instanceof Player){ $sender->sendMessage('Hey, you are a player, and we do not need do $sender->getPlayer() because you are already one!');}elseif($sender instanceof Zombie){ $sender->sendMessage("OMG! A zombie!!");}