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

Help for create NPC

Discussion in 'Help' started by ken4erka, Aug 6, 2021.

  1. ken4erka

    ken4erka Creeper

    Messages:
    2
    If you open Entity.php you can see the base NBT for creating the entity. In turn, I want to spawn the NPC.
    I found a ready-made code to spawn the NPC, but I don't know where to get these NBT tags such as "Skin". I would like to get the entire list of tags and find out how to set displayname npc thx)

    PHP:
    /**
         * Helper function which creates minimal NBT needed to spawn an entity.
         */
        
    public static function createBaseNBT(Vector3 $pos, ?Vector3 $motion nullfloat $yaw 0.0float $pitch 0.0) : CompoundTag{
            return new 
    CompoundTag("", [
                new 
    ListTag("Pos", [
                    new 
    DoubleTag(""$pos->x),
                    new 
    DoubleTag(""$pos->y),
                    new 
    DoubleTag(""$pos->z)
                ]),
                new 
    ListTag("Motion", [
                    new 
    DoubleTag(""$motion !== null $motion->0.0),
                    new 
    DoubleTag(""$motion !== null $motion->0.0),
                    new 
    DoubleTag(""$motion !== null $motion->0.0)
                ]),
                new 
    ListTag("Rotation", [
                    new 
    FloatTag(""$yaw),
                    new 
    FloatTag(""$pitch)
                ])
            ]);
        }

    PHP:
    public function spawnNPC(Player $player){
            
    $nbt = new CompoundTag("", [
                new 
    ListTag("Pos", [
                    new 
    DoubleTag(""$player->getX()),
                    new 
    DoubleTag(""$player->getY()),
                    new 
    DoubleTag(""$player->getZ())
                ]),
                new 
    ListTag("Motion", [
                    new 
    DoubleTag(""0),
                    new 
    DoubleTag(""0),
                    new 
    DoubleTag(""0)
                ]),
                new 
    ListTag("Rotation", [
                    new 
    FloatTag(""$player->getYaw()),
                    new 
    FloatTag(""$player->getPitch())
                ]),
                new 
    CompoundTag("Skin", [
                    new 
    StringTag("Data"$player->getSkin()->getSkinData()),
                    new 
    StringTag("Name"$player->getSkin()->getSkinId()),
                ])
            ]);
            
    $npc = new Human($player->getLevel(), $nbt);
            foreach(
    $this->getServer()->getOnlinePlayers() as $plr) {
                
    $npc->spawnTo($plr);
            }
        }
     
  2. zOmArRD

    zOmArRD Creeper

    Messages:
    1
    GitHub:
    zomarrd
    use this.
    PHP:
    <?php
    /*
    * Created by PhpStorm
    *
    * User: zOmArRD
    * Date: 11/8/2021
    *
    * Copyright © 2021 - All Rights Reserved.
    */
    namespace here;

    use 
    pocketmine\entity\Human;
    use 
    pocketmine\entity\Skin;
    use 
    pocketmine\nbt\tag\CompoundTag;
    use 
    pocketmine\nbt\tag\DoubleTag;
    use 
    pocketmine\nbt\tag\FloatTag;
    use 
    pocketmine\nbt\tag\ListTag;
    use 
    pocketmine\nbt\tag\StringTag;
    use 
    pocketmine\Player;

    class 
    Example
    {
        public function 
    spawnHuman(Player $player): void
        
    {
            
    $position $player->getPosition();
            
    $plSkinData $player->getSkin();
            
    $nbt = new CompoundTag("", [
                new 
    ListTag("Pos", [
                    new 
    DoubleTag(""$position->getX()),
                    new 
    DoubleTag(""$position->getY()),
                    new 
    DoubleTag(""$position->getZ())
                ]),
                new 
    ListTag("Motion", [
                    new 
    DoubleTag(""0),
                    new 
    DoubleTag(""0),
                    new 
    DoubleTag(""0)
                ]),
                new 
    ListTag("Rotation", [
                    new 
    FloatTag(""$player->getYaw()),
                    new 
    FloatTag(""$player->getPitch())
                ]),
                new 
    CompoundTag("Skin", [
                    new 
    StringTag("Data"$plSkinData->getSkinData()),
                    new 
    StringTag("Name"$plSkinData->getSkinId()),
                ]),
            ]);
            
    $human = new Human($player->getLevel(), $nbt);
            
    $human->setScale(1);
            
    $human->setSkin(new Skin($player->getName(), $plSkinData->getSkinData(), $plSkinData->getCapeData(), $plSkinData->getGeometryName(), $plSkinData->getGeometryData()));
            
    $human->setNametagVisible(true);
            
    $human->setNameTagAlwaysVisible(true);
            
    $human->setImmobile(true);
            
    $human->spawnToAll();
        }
    }
     

    Attached Files:

  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.