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

How to just spawn a Zombie?

Discussion in 'Development' started by Indexfire, Feb 17, 2017.

  1. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    Im trying to spawn a Zombie with a Plugin. Since Pocketmine aint got working AI yet im assuming the mob will forever stay at where it was spawned. But i cant find a method or getter to spawn a mob. Can anyone help?



    Im trying to...
    -Spawn a Zombie
    -Spawn it with custom health
    -Spawn it with a Custom name
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PHP:
        public static function addZombie(Location $pos)
        {
            
    $nbt = new CompoundTag;
            
    $nbt->Pos = new ListTag("Pos", [
                new 
    DoubleTag(""$pos->x),
                new 
    DoubleTag(""$pos->y),
                new 
    DoubleTag(""$pos->z)
            ]);
            
    $nbt->Rotation = new ListTag("Rotation", [
                new 
    FloatTag(""$pos->yaw),
                new 
    FloatTag(""$pos->pitch)
            ]);
            
    $nbt->Health = new ShortTag("Health"20);//HEALTH
            
    $nbt->displayname "Custom Name";
            
    $chunk $player->chunk;
            if (!
    $chunk instanceof Chunk) {
                return;
            }
            
    $entity Entity::createEntity("Zombie"$chunk$nbt);
            
    $entity->spawnToAll();
            
    $entity->saveNBT();
            
    $entity->setNamedTagVisible(true);
            
    $entity->setNamedTagAlwaysVisible(true);
            
    //$entity->setNamedTag($nbt->display name);
        
    }
    PHP:
    /** @var Player $player */
    self::addZombie($player->getLocation());
     
  3. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    But how do i spawn it in a specific location? Eg in a castle only or something
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PHP:
    /** @var int $x */
    /** @var int $y */
    /** @var int $z */
    //Keep $yaw and $pitch 0.0 if you don't know what it is.
    $yaw 0.0;
    $pitch 0.0
    $level 
    Server::getInstance()->getLevelByName("world");//or another level.
    $loc = new Location($x$y$z$yaw$pitch$level);
    self::addZombie($loc);
     
    Indexfire 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.