Changing Mob Attributes? Change health etc.

Discussion in 'Spigot Plugin Development' started by digdiggydigger, Apr 30, 2017.

  1. Hey Spigot!

    Today I'm trying to understand how to spawn a mob with a certain amount of health? I've become more stuck on it that i really should've so I've resorted to posting here! :p

    Heres what i wanted to do but it doesn't work:

    Code (Text):
        public static void warlockBoss(CommandSender sender) {
            Player player = (Player) sender;
            Location loc = player.getLocation();
           
            Entity ent = player.getWorld().spawnEntity(loc, EntityType.ZOMBIE);
            ent.setCustomName("§c§lEvil Warlock");
            ent.setMaxHealth(100); // This line and the line below are the ones that dont work..
            ent.setHealth(100); // Im not sure why because it should work i thought?
        }
     
  2. Hmm, try passing in the 100's as a double.
    I believe using integers for it is both deprecated and invalid.
    Also for the name make sure you set the custom name visible if you wanted it to be seen in game


    Sent from my iPhone using Tapatalk
     
  3. Hi and thanks for your reply, but if you look at my code, where i have written:

    Code (Text):
            // ent.setMaxHealth(100); // This line and the line below are the ones that dont work..
            // ent.setHealth(100); // Im not sure why because it should work i thought?
    I get errors under '.setMaxHealth' and '.setHealth' because they are not part of an Entity event i don't think? So thats my issue and the custom name works just fine :p
     
  4. If you tell us what error the compiler displays we can fix your issue is seconds (in the future).
    You have to cast your Entity into a LivingEntity.
     
  5. Like I said before try casting those values to doubles and see if the error is still there..


    Sent from my iPhone using Tapatalk