1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How do you spawn an NPC and run commands with it

Discussion in 'Development' started by Levi, Jun 29, 2018.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    How do you spawn an NPC and run commands with it like if i tap the npc it'll spawn human
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
  3. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    These should work:
    1. Create custom human class
    2. Spawn Entity
    3. Create a event call EntityDamageEvent instance $event to EntityDamagbyEntity
    4. Check entity name
    5. Execute your code or command stuff there

    Should be like this

    Class:

    PHP:
    <?php

    namespace class;

    use 
    pocketmine\entity\Human;

    class 
    Entity extends Human{
    }
    Spawn:

    PHP:
    $nbt Entity::createBaseNBT($playernull$player->getYaw(), $player->getPitch());
    Event:

    PHP:
    public function onDamage(EntityDamageEvent $event): void{
    $entity $event->getEntity();

    if(!
    $entity instanceof Entity) return;
    if(
    $event instanceof EntityDamageByEntity){
    $damager $event->getDamager();

    if(
    $entity->getNameTag() == "Hello"$damager->sendMessage("Hello");
    }
    }
     
    NTT, DerCooleVonDem and Levi like this.
  4. Azonuno

    Azonuno Spider

    Messages:
    12
    Also make sure to add entity damage event
     
  5. Axon

    Axon Zombie

    Messages:
    276
    Please don’t bump threads that are older that 1 year.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.