Entity Name Tag

Discussion in 'Plugin Development' started by PHILLIPS_71, Apr 18, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    PHILLIPS_71

    I have started coding a plugin that when a entity spawn it sets a name tag but im not sure how to get the entity and set the name i have tried

    Code:
    if(event.getEntityType() == Entity.ZOMBIE.setCustomName(ChatColor.AQUA + "Zombie"));
    But ZOMBIE is not working i have got it to set all Entity's to change there name but it wont set animals name (Pigs, Cows, Chicken etc) how to get i get the entity type and set the name also is there a way on setting there health as well i have got this code but it is not working also i'm not getting any errors with the code but i'm not sure if it just works for players also how do i make it so if the player is 20 blocks away from the entity is does not how the name?

    This is he name tagging code here:

    Code:
        @EventHandler
        public void spawn(CreatureSpawnEvent event) {
            EntityType entity = event.getEntityType();
            if ((entity.isAlive()) && (entity.isSpawnable())) {
                event.getEntity().setCustomName(ChatColor.AQUA + "Zombie");
                event.getEntity().setCustomNameVisible(true);
            }
        }
    
    This is the health over player/entity's head:

    Code:
        public void HealthScoreboard() {
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
            board.registerNewObjective("showhealth", "health");
     
            Objective objective = board.getObjective("showhealth");
            objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
            objective.setDisplayName("/ 20");
     
            for(Player online : Bukkit.getOnlinePlayers()){
                online.setScoreboard(board);
            }
        }
    }
    
     
  2. Offline

    Spikes

    So far as i know, you can set the scoreborad only to a player not a Entity
     
  3. Offline

    PHILLIPS_71

    Spikes
    So you cant get the mob type and change the name?
     
  4. Offline

    mrCookieSlime

    No, you can change the name tag of mobs and you can also get the mob type
     
  5. Offline

    Spikes

    You can set the name but not set the scoreborad to a mob
     
  6. Offline

    PHILLIPS_71

    Spikes
    Oh ok do you know how I get the entity type and change the name?
     
  7. Offline

    mrCookieSlime

    No, you can :p
    You can display a specified name above a specifiec mob type
     
  8. Offline

    PHILLIPS_71

  9. He said you can't set a SCOREBOARD on a mob, it would also be totally pointless since it's a HUD element and nobody is controlling mobs since they're Non-Playable Characters therefore nobody will see it...

    PHILLIPS_71
    Code:
    if(event.getEntityType() == Entity.ZOMBIE.setCustomName(ChatColor.AQUA + "Zombie"));
    That's not even valid code...

    I suggest you use a Map<EntityType, String> to asign names in your onEnable (or load them from a config) then just:
    Code:
        @EventHandler
        public void spawn(CreatureSpawnEvent event) {
            String name = map.get(event.getEntityType());
    
            if(name != null) {
                event.getEntity().setCustomName(name);
            }
        }
    Also, you don't need setCustomNameVisible(), the name is still visible without it if you aim at the entity.
    If you set setCustomNameVisible to true it will force the tag to be always visible regardless of aiming at the entity or not.
     
  10. Offline

    mrCookieSlime

    No, trust me, you can display Scoreboards on mobs and everybody can see them!

    Here's an example:
    http://dev.bukkit.org/server-mods/health-bar/
     
  11. Offline

    ZeusAllMighty11

    Actually that uses scoreboards for players, custom names for mobs
     
  12. mrCookieSlime
    I didn't say anything about name plates, I belive you don't understand the diference between a "scoreboard" and a "name plate" :p
    In the game a "scoreboard" is the HUD element from the right-side of the screen which tracks score, a "name plate" is the floating name above entities.
    I belive you got confused about this because you can use the scoreboard system to edit player's name plates, but they're not the same thing.
     
  13. Offline

    mrCookieSlime

    I think YOU didn't understand the scoreboard mechanic :p

    There are 3 types of scoreboards:
    1. TABLIST
    2. NAME TAG
    3. SIDEBAR

    The Server sends the packets of the scoreboard of the mobs to the clients which decodes the package and displays the name above a mobs/players heads.

    These Name Tags are the Same scoreboard as the scoreboard on the side except the Display location and some meta datas, but it's also a scoreboard!
     
  14. Offline

    PHILLIPS_71

    I still have not solved this issue anyone have any idea on what may be the issue?
     
  15. It is called:
    There are 3 types of scoreboards:
    1. BELOW_NAME
    2. PLAYER_LIST
    3. SIDEBAR

    http://jd.bukkit.org/rb/doxygen/df/dd4/DisplaySlot_8java_source.html
     
  16. Offline

    mrCookieSlime

    Matho97

    Yea, I know I just called them like this, so he understands what I mean :)
     
  17. Offline

    Hectorg98

    mrCookieSlime how do we set the name of a mob, as in a tag of a mob right away when it spawns.
     
  18. Offline

    mrCookieSlime

    Why did you bump an old Thread for this... D:
    And it is LivingEntity#setCustomName(String name)
    and LivingEntity#setCustomNameVisible(boolean visible)
     
Thread Status:
Not open for further replies.

Share This Page