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

How I spawn a simple npc?

Discussion in 'Development' started by Enrico Angelon, Feb 22, 2018.

  1. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Try this code
    PHP:
    public function spawnNPC(Player $player)  {
                    
    $nbt = new CompoundTag;
                    
    $nbt->Pos = new ListTag("Pos", [
                        new 
    DoubleTag(""$player->getX()),
                        new 
    DoubleTag(""$player->getY()),
                        new 
    DoubleTag(""$player->getZ())
                    ]);
                    
    $nbt->Motion = new ListTag("Motion", [
                        new 
    DoubleTag(""0),
                        new 
    DoubleTag(""0),
                        new 
    DoubleTag(""0)
                    ]);
                    
    $nbt->Rotation = new ListTag("Rotation", [
                        new 
    FloatTag(""$player->getYaw()),
                        new 
    FloatTag(""$player->getPitch())
                    ]);
                    
    $nbt->Health = new ShortTag("Health"20);
                    
    $nbt->Skin = new CompoundTag("Skin", [
                        
    "Data" => new StringTag("Data"$player->getSkin()->getSkinData()),
                        
    "Name" => new StringTag("Name"$player->getSkin()->getSkinId())]);

                    
    $human = new Human($player->getLevel(), $nbt);
                    
    $human->setNameTag($player->getName());
                    
    $human->setNameTagVisible(false);
                    
    $human->spawnTo($player);
    }
     
  2. Enrico Angelon

    Enrico Angelon Spider Jockey

    Messages:
    37
    GitHub:
    herryyt
    this works too, now im working definitely on this, i'm adding a cmd to this using EntityDamageEvent
     
  3. Draglor56

    Draglor56 Silverfish

    Messages:
    24
    Use this:

    PHP:
    $this->spawnNPC($player)
     
  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.