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

NameTag of entities do not visible

Discussion in 'Development' started by Nora1903, Jun 30, 2018.

  1. Nora1903

    Nora1903 Slime

    Messages:
    82
    GitHub:
    cuongvnz
    I just set nametag for entities on EntitySpawnEvent but the nametag of entities do not visible . I have tried to use setNameTagVisible(true) and setNameTagAlwaysVisible(true) but both dont work for me @@ Anyone know how to make nametag of entity visible ?Thanks
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    But when you hover over the entity, is it visible?
     
  3. Nora1903

    Nora1903 Slime

    Messages:
    82
    GitHub:
    cuongvnz
    No :(((
    My code :
    Code:
        public function onEntitySpawn(EntitySpawnEvent $e) {
            $mobs = $e->getEntity();
            if($mobs instanceof Zombie || $mobs instanceof Skeleton || $mobs instanceof Spider){
                foreach($this->main->getServer()->getOnlinePlayers() as $p) {
                    $level = $this->main->getLevel($p);
                    //if($mobs->distance($p) <= 50) {
                        $name = $mobs->getNameTag();
                        $mobs->setNameTag($name."\nLevel ".$level);
                        $mobs->setNameTagVisible(true);
                        $mobs->setNameTagAlwaysVisible(true);
                    //}
                }
            }
        }
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    While I don't know about your nametag display issue, I'd suggest running a check through a different function, like isNearPlayer($mobs), and if the mob is within range, break the foreach loop and return true. That way, in your listener, you could just use
    PHP:
    if($this->main->isNearPlayer($mobs)){
      
    //set the entities nametag once, rather than 2 or 3 times if there are more players within range.
    } else {
      
    //No players are within range of the entity.
    }
    Also, I believe you can use
    PHP:
     if($mobs instanceof (Zombie || Skeleton || Spider)) {
    }
    to make it easier than writing out the $mobs instanceof so many times.
     
  5. Nora1903

    Nora1903 Slime

    Messages:
    82
    GitHub:
    cuongvnz
    I want every entities that spawn with specific nametage
     
  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.