Solved How remove all NPC

Discussion in 'Development' started by Error202, Apr 15, 2019.

  1. Error202

    Error202 Silverfish

    Messages:
    23
    I create some human entities...
    How can I remove all it?
    PHP:
    getEntities()
    result is 0
     
  2. Swourire

    Swourire Silverfish

    Messages:
    19
    GitHub:
    swourire
    PHP:
     foreach($this->getServer()->getLevels() as $level){
                                            foreach(
    $level->getEntities() as $entity){
                                                    if(
    $entity instanceof Human){
                                                            
    $entity->close();
                                                    }
                                            }
                                    }
    this is if you want to kill all the entities of all the level:
    explanation,
    You get all the levels of a server through a foreach.
    You get all the entities of all the levels.
    You check and filter the entities that are Humans.
    You kill the entity.
     
  3. Error202

    Error202 Silverfish

    Messages:
    23
    In my case $level->getEntities() return always 0
    I have only one level
     
  4. Swourire

    Swourire Silverfish

    Messages:
    19
    GitHub:
    swourire
    then you have no entities spawwned.
     
  5. Error202

    Error202 Silverfish

    Messages:
    23
    I restart server without plugin - all humans disappeared
    Restart again with plugins and all cleared.... no humans...
     
  6. Swourire

    Swourire Silverfish

    Messages:
    19
    GitHub:
    swourire
    Can you tell me how you spawned Human entities ?
     
  7. Error202

    Error202 Silverfish

    Messages:
    23
    PHP:
    $nbt $this->getServer()::getInstance()->getOfflinePlayerData($player->getName());
            
    $npc = new Human($world$nbt);
            
    $npc->setNameTag($player->getName());
            
    $npc->getInventory()->clearAll();
            
    $npc->setNameTagVisible(false);
            
    $npc->setPosition($player->getPosition());
            
    $npc->setRotation($yaw$pitch);
            
    $npc->spawnToAll();
     

Share This Page

  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.