Earlier today, I had the help of another dev and they helped me spawn an NPC. My main issue now is that the npc can be killed. I’ve tried the $npc->setMaxHealth(9999); and $npc->setHealth(9999); it works for the first join but once the server reboots, it resets it back down to 20hp. Is there anyway to make it so that the NPC cannot be hit/hurt.
PHP: public function damage(EntityDamageEvent $event) : void { if($event->getEntity()::NETWORK_ID == Entity::NPC) { $event->setCancelled(true); } }
Tried this, it still takes damage... I’m using this to spawn it in. https://github.com/xXNiceYT/NPC-Test
You could $npc->setInvulnerable(true), then cancel EntityDamageEvent when $event->getEntity()->isInvulnerable()? I'm not sure why pocketmine doesn't do the isInvulnerable() check itself, perhaps #blameshoghi.
Thanks, i’ve figure it out. I put it into the EntityDamageEvent function and I called for its nametag. I can now have it not take damage and also execute a command.