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

Solved Spawn NPC (no slapper)

Discussion in 'Development' started by ethaniccc, Mar 6, 2020.

  1. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    Hi, so I want to make a server core for my own server. I have set up the core and everything, but I want to make my own NPC's. I don't want to use the slapper plugin, because I want it to be a complete core (I guess). Can anyone help me?

    (BTW, I tried searching this up, but when I attempted the method, it was no longer supported. The last post about this was a year ago so yeah...)

    Thanks in advance!
    ~Ethaniccc
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    $human = new Human($level, $nbt);
    $human->spawnToAll();
     
    ethaniccc likes this.
  3. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    When I was making the variable $nbt, it gave me this error:

    Code:
     [Server thread/CRITICAL]: RuntimeException: "Cannot access dynamic field "Pos": Dynamic field access on pocketmine\nbt\tag\CompoundTag is no longer supported" (EXCEPTION) in "vendor/pocketmine/nbt/src/tag/NoDynamicFieldsTrait" at line 31
    My code:

    PHP:
    $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(true);
                    
    $human->spawnTo($player);
     
  4. Emirhan Akpınar

    Emirhan Akpınar Slime

    Messages:
    90
    PHP:
    $nbt Entity::createBaseNBT($position);
     
    ethaniccc likes this.
  5. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    I did everything, but I don't know how to set the Skin for the NPC

    Error:
    Code:
     [Server thread/CRITICAL]: InvalidStateException: "Human must have a valid skin set" (EXCEPTION) in "src/pocketmine/entity/Human" at line 110
     
  6. Emirhan Akpınar

    Emirhan Akpınar Slime

    Messages:
    90
    PHP:
    $nbt->setTag($player->namedtag->getTag("Skin"));
     
  7. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    Wow, thanks alot!
     
  8. Emirhan Akpınar

    Emirhan Akpınar Slime

    Messages:
    90
  9. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    One more question, how do you set the way the NPC is facing?
     
  10. Emirhan Akpınar

    Emirhan Akpınar Slime

    Messages:
    90
    I dont understand, can you explain?
     
  11. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    So like, the way or direction the NPC is facing, so it's not just looking straight
     
  12. Emirhan Akpınar

    Emirhan Akpınar Slime

    Messages:
    90
    If i didn't remember wrong, Entity class has a
    PHP:
    $entity->lookAt($position);
    function. Can you try?
     
  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.