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

Trying to spawn an NPC

Discussion in 'Development' started by MalakasPlayzMCPE, Sep 6, 2018.

  1. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Well I am trying to spawn an NPC but I get this error:
    Code:
    06.09 16:56:22 [Server] Server thread/CRITICAL Unhandled exception executing command 'npc' in npc: Argument 1 passed to pocketmine\nbt\tag\CompoundTag::setTag() must be an instance of pocketmine\nbt\tag\NamedTag, null given, called in /plugins/NPC/src/NPC/Main.php on line 233
    06.09 16:56:22 [Server] Server thread/CRITICAL TypeError: "Argument 1 passed to pocketmine\nbt\tag\CompoundTag::setTag() must be an instance of pocketmine\nbt\tag\NamedTag, null given, called in /plugins/NPC/src/NPC/Main.php on line 233" (EXCEPTION) in "vendor/pocketmine/nbt/src/tag/CompoundTag" at line 122
    Code:
    PHP:
            $nbt Entity::createBaseNBT($playernull22);
            
    $nbt->setTag($player->namedtag->getTag("Skin")); //line 233
            
    $npc = new Human($player->getLevel(), $nbt);
            
    $npc->setNameTag("Test");
            
    $npc->setNameTagAlwaysVisible(true);
            
    $npc->spawnToAll();
     
    Last edited: Sep 6, 2018
  2. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    Oh wait I will tell u what is wrong
     
  3. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Before anybody ask I used the latest stable release
    "This server is running PocketMine-MP 3.2.0 for Minecraft: Bedrock Edition v1.6.0 (protocol version 282)"
     
  4. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    Lol
    Try this
    Of course u have to edit it but try this!

    PHP:
        $name implode(" "$args);
                
    $nbt Entity::createBaseNBT($sendernull22);
                
    $nbt->setTag($sender->namedtag->getTag("Skin"));
                
    $npc = new NPC($sender->getLevel(), $nbt);
                
    $npc->setNameTag($name " Health: " round($npc->getHealth()));
                
    $npc->setNameTagAlwaysVisible(true);
                
    $npc->spawnToAll();
                
    $sender->sendMessage("$name bot");
            }
            return 
    true;
        }
     
  5. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    It is the same thing. @dktapps did the name of the skin tag change? Why does it return null?
     
  6. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    No it's doesn't change!
    +
    Null becos we want to spawn the npc next to the player/sender!

    And this command I used in my server it's worked with me
     
  7. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Tell me your pocketmine version please. Type /version or /ver
     
  8. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    Ok wait
     
  9. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    PocketmineMP 3.2.0 Minecraft bedrockedition (protocol 282)
     
  10. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Can anybody explain me what in the world I do wrong?!!?
     
  11. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    Give me all the main file that u code it
     
  12. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Well this is the bad code. We will just wait for a better developer to reply.
     
  13. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    I am a biginnir but I don't understand what happening with u!!
    When I made this code in the first try !
    It didn't work
    But now it's work and I give it for u but why it's didn't woork??????
     
  14. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    PHP:
    $nbt Entity::createBaseNBT(new Vector3($player->getX(), $player->getY(), $player->getZ()), null$player->getYaw(), $player->getPitch());
            
    $sheep Entity::createEntity("EntityName"$player->getLevel()->getName(), $nbt);
            
    $sheep->setMaxHealth(20);
            
    $sheep->setHealth(20);
            
    $sheep->spawnToAll();
    If you want to know more about NPCs see Slapper
     
  15. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    My issue is on setting the skin...
     
  16. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    هلا خالد بربك افحصلي بلوقني ليش ما يشتغل لك قلبت الدنيا عليه
     
  17. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    That's mean when you try to spawn a normal entity it works?

    Ok I will now but talk here in English better xD
     
  18. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
  19. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Well nevermind, both have the same error. Do I have to do that clone thing?
     
  20. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Well I $player->saveNBT(); before I run the code and this part seems to be okay(?). I will let you know if I need further help.
     
  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.