Mobs are still alive at 0 HP?

Discussion in 'Plugin Development' started by redside100, Jul 15, 2015.

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

    redside100

    For SOME reason, when I set a mob's HP to 0, it's still alive.

    Code:
                        e.setHealth(0);
                        manager.getServer().broadcastMessage("" + e.getHealth());
    It broadcasted as 0 hp too.
     
  2. Offline

    teej107

    @redside100 Just wait. Wait and endure the loooong tick that the game has to do in order to do updates.
     
  3. Offline

    redside100

    @teej107 No.... what's really weird is that the mob dies if I run the code a second time.
     
  4. Offline

    teej107

  5. Offline

    redside100

    @teej107 Ok, so I found out that this only occurs if the mob is wearing armor. If the mob isn't, then it automatically dies. Is this a bug?

    Code:
                    if (currentHP - hp <= 0){
                        e.setHealth(0);
                        mobhp.remove(mob);
                        mobmaxhp.remove(mob);
                        mobdef.remove(mob);
                        manager.getServer().broadcastMessage("" + e.getHealth());
                        manager.getServer().broadcastMessage("" + mobhp.size());
                        if (name.contains("Zombie")){
                            mob.setCustomName("§cZombie §6[0] [0%]");
                        }
                        if (name.contains("Skeleton")){
                            mob.setCustomName("§cSkeleton §6[0] [0%]");
                        }
                        if (name.contains("Seeker")){
                            mob.setCustomName("§cSeeker §6[0] [0%]");
                        }
                        if (name.contains("Sharpshooter")){
                            mob.setCustomName("§cSharpshooter §6[0] [0%]");
                        }
                        if (name.contains("Commander")){
                            mob.setCustomName("§cCommander §6[0] [0%]");
                        }
                        return;
                    }
    How I spawned the zombie:
    Code:
                                        Zombie zombie1 = (Zombie) p.getWorld().spawn(p.getLocation(), Zombie.class);
                                        zombie1.setBaby(false);
                                        zombie1.setVillager(false);
                                        if (zombie1.isInsideVehicle()){
                                            Entity chicken = zombie1.getVehicle();
                                            zombie1.getVehicle().eject();
                                            if (chicken instanceof Creature){
                                                Creature chicken1 = (Creature) chicken;
                                                chicken1.setHealth(0);
                                            }
                                        }
                                        zombie1.getEquipment().setHelmet(new ItemStack(Material.IRON_HELMET));
                                        zombie1.getEquipment().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
                                        zombie1.getEquipment().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
                                        zombie1.getEquipment().setBoots(new ItemStack(Material.IRON_BOOTS));
                                        ItemStack sword = new ItemStack(Material.IRON_SWORD, 1);
                                        sword.addEnchantment(Enchantment.DAMAGE_ALL, 1);
                                        zombie1.getEquipment().setItemInHand(new ItemStack(sword));
                                        zombie1.getEquipment().setItemInHandDropChance(0F);
                                        zombie1.getEquipment().setHelmetDropChance(0F);
                                        zombie1.getEquipment().setChestplateDropChance(0F);
                                        zombie1.getEquipment().setLeggingsDropChance(0F);
                                        zombie1.getEquipment().setBootsDropChance(0F);
                                        Entity ent2 = (Entity) zombie1;
                                        Creature creature = (Creature) ent2;
                                        hpmanager.addMob(ent2, hp, hp, def);
                                        manager.setCustomName(creature, "Commander");
    Strange... this kills skeletons with armor, but not zombies.

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Jul 16, 2015
  6. @redside100 try setting the health to -1, if that works.

    EDIT: also, looking at the code example, you set his health to 0 only if his health is lower or equal to 0?
     
  7. Offline

    redside100

    You can only set a mob's health anywhere from 0 to 20. Also, the (currentHP - hp) thing is for customHP, not its actual health.
     
  8. @redside100 I would say go look for some method to despawn entities in craftbukkit, but oh wait.... you can't.
     
  9. Offline

    Konato_K

    @redside100 Why are you using the deprecated integer method instead of the one that takes a double?
     
  10. Offline

    redside100

    You're saying I should do e.setHealth(0D)?
     
  11. Offline

    JetFureur

    Can't you add an instant_dmg potion effect right after ? ^^
     
  12. Offline

    Hawktasard

Thread Status:
Not open for further replies.

Share This Page