Read the title please I'm trying right now to spawn a NPC that when a player interact with it, execute a code, can anyone help?
I try to help.... Spawn NPC, Human. Save it into the variable. And in EntityDamageByEntityEvent, test: $event->getEntity() == $yourvar, if is true cancel event, and execute code. It is an easy)
There is already a plugin like that. You can look into its source code. Check out Slapper by @jojoe77777 . http://forums.pocketmine.net/plugins/slapper.1267/