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

Spawn an entity

Discussion in 'Plugin Help' started by NiLen, Jul 1, 2021.

  1. NiLen

    NiLen Spider

    Messages:
    8
    Where is the mistake?

    ArgumentCountError: "Too few arguments to function NiLen\NPC\NPC::npc6(), 1 passed in /srv/data/plugins/NPC_plugin/src/NiLen/NPC/NPC.php on line 76 and exactly 2 expected

    public function npc6($type, Player $player){
    $nbt = new CompoundTag("", [
    "Pos" => new ListTag("Pos", [
    new DoubleTag ("", $player->x),
    new DoubleTag ("", $player->y + $player->getEyeHeight()),
    new DoubleTag ("", $player->z)
    ]),
    "Motion" => new ListTag("Motion", [
    new DoubleTag("", 0),
    new DoubleTag("", 0),
    new DoubleTag("", 0)
    ]),
    "Rotation" => new ListTag("Rotation", [
    new FloatTag ("", $player->yaw),
    new FloatTag ("", $player->pitch)
    ]),
    ]);

    $snowball = Entity::createEntity("Cow", $player->getLevel(), $type, $nbt);


    $snowball->spawnToAll(true);
    }

    Spawn code:

    $this->npc6($player);
     
  2. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    PHP:
    public function npc6(Player $player){
                                
    $nbt = new CompoundTag("", [
                                    
    "Pos" => new ListTag("Pos", [
                                    new 
    DoubleTag (""$player->x),
                                    new 
    DoubleTag (""$player->$player->getEyeHeight()),
                                    new 
    DoubleTag (""$player->z)
                                    ]),
                                    
    "Motion" => new ListTag("Motion", [
                                    new 
    DoubleTag(""0),
                                    new 
    DoubleTag(""0),
                                    new 
    DoubleTag(""0)
                                    ]),
                                    
    "Rotation" => new ListTag("Rotation", [
                                    new 
    FloatTag (""$player->yaw),
                                    new 
    FloatTag (""$player->pitch)
                                ]),
                                    ]);
                  
                                    
    $snowball Entity::createEntity("Cow"$player->getLevel(), $type$nbt);
                                  
                                  
                    
    $snowball->spawnToAll(true);
                                    }

     
  3. NiLen

    NiLen Spider

    Messages:
    8
    new mistake:
    Error: "Call to a member function spawnToAll() on null" (EXCEPTION) in "plugins/NPC_plugin/src/NiLen/NPC/NPC" at line 213
    [13:28:47] [Server thread/CRITICAL]: #0 plugins/NPC_plugin/src/NiLen/NPC/NPC(76): NiLen\NPC\NPC->npc6(object pocketmine\Player)
     
  4. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    You need to register the Cow entity
     
    Agent likes this.
  5. NiLen

    NiLen Spider

    Messages:
    8
    how to register this entity?
     
  6. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
  7. NiLen

    NiLen Spider

    Messages:
    8
  8. NiLen

    NiLen Spider

    Messages:
    8
  9. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    you need to implement the cow entity
     
    Agent likes this.
  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.