setdamage not exactly in entitydamagebyentityevent

Discussion in 'Plugin Development' started by GayZoTe, Feb 22, 2017.

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

    GayZoTe

    Hello all, i've made an event to remove 20 health points of a zombie when he's hited by a player


    Code:
      @EventHandler
        public void killzombie(EntityDamageByEntityEvent e) {
            if(e.getDamager() instanceof Player) {
                if(e.getEntity() instanceof Zombie) {
                    Zombie z = (Zombie)e.getEntity();
                    e.setDamage(20);
                    Bukkit.broadcastMessage(z.getHealth()+" - " +(z.getHealth()-20));
                }    
            }
        }
    i hit to kill a zombie with 40 health points, there is the result :

    10588395b9fa7b1b9b6ac116958fa2e3.png

    so the preview in the broadcast is okay, but the result after the hit is different, in the second hit the zombie is supposed to have 20 health points, but he has 21.6.. same in the next hit.

    can you help me pls :D
    thanks
     
  2. Offline

    Zombie_Striker

    @GayZoTe
    Does the zombie have any armor or potion effects (Regneration)? If the zombie is wearing armor, you will need to account for the protection and add some value (Maybe just +1 ) to the damage.
     
  3. Offline

    GayZoTe

    no no, i spawn the zombie with that :
    Code:
    Zombie z = (Zombie) Bukkit.getWorld("Run").spawnCreature(randomloc(), CreatureType.ZOMBIE);
                            if(z.getVehicle() != null) {
                                Entity ee = z.getVehicle();
                                z.leaveVehicle();   
                                ee.remove();
                            }
                            z.setBaby(false);
                            z.setVillager(false);
                            z.getEquipment().clear();
                            z.getEquipment().setItemInHand(new ItemStack(Material.AIR));
                            if(z.getVehicle() != null || z.isBaby() || z.isVillager() || z.getEquipment().getItemInHand().getType().equals(Material.AIR)==false) {
                                z.remove();
                            }
    up :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 22, 2017
  4. Offline

    GayZoTe

Thread Status:
Not open for further replies.

Share This Page