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

NPC

Discussion in 'Development' started by xXNiceAssassinlo YT, Mar 15, 2018.

  1. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    NPC didnt save after server restart

    PHP:
        public function NPC(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())]);

            
    $npc = new Human($player->getLevel(), $nbt);
            
    $npc->setNameTag(C::YELLOW "Test");
            
    $npc->setNameTagVisible(false);
            
    $npc->spawnToAll();
        }
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
  3. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Well, replace "Test" with $entity and $sender with $player (for your code snippet up there at least) and it should work
     
  5. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    I need put that onEnable right?
     
  6. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    nope, just into the code you posted above.
    like this:
    PHP:
     public function NPC(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())]);

            
    $npc = new Human($player->getLevel(), $nbt);
            
    $npc->setNameTag(C::YELLOW "Test");
            
    $npc->setNameTagVisible(false);
            
    $player->getLevel()->addEntity($npc);
            
    $npc->spawnToAll();
        }
     
  7. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    thx btw is there away to kill this npc too?
     
  8. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Out of my mind it would be $npc->setHealth(0); or simply $npc->kill();
     
  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.