Damage Issue

Discussion in 'Plugin Development' started by Coopah, Dec 15, 2014.

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

    Coopah

    So I'm trying to make it so when you're in diamond armor all your damage is substracted by 1 heart and when someone is attacking you their damage is reduced by 1 heart. This means you deal 1 heart damage less but you also take 1 heart of damage less (means your tanky but dont deal as much damage).

    The issue is that when both players are in diamond armor they don't deal damage to each other.

    Code:
    Code:
    @EventHandler
        public void onEntityDmg(EntityDamageByEntityEvent e) {
    
            Entity dmgerE = e.getDamager();
            Entity dmgedE = e.getEntity();
    
            if (dmgerE instanceof Player && dmgedE instanceof Player) {
    
                Player dmger = (Player) e.getDamager();
                Player dmged = (Player) e.getEntity();
               
                if (Guardian.bruteSet(dmged.getEquipment())) {
                   
                    e.setDamage(e.getDamage() - 2);
               
                } else if (Guardian.bruteSet(dmger.getEquipment())) {
                   
                    e.setDamage(e.getDamage() - 2);
                }
            }
        }
     
  2. Offline

    ColonelHedgehog

    Yeah, you're probably going to want to use a different equation with a factor. i.e. e.setDamage(e.getDamage / 2);
     
  3. Offline

    Coopah

    @ColonelHedgehog
    The code seems to heal them, if I set the health of the player then hit them it's healing them?

    Okay so changing the damage the guy in the diamond armor is dealing work from this code:
    Code:
        @EventHandler
        public void onEntityDmg(EntityDamageByEntityEvent e) {
    
            Entity dmgerE = e.getDamager();
            Entity dmgedE = e.getEntity();
    
            if (dmgerE instanceof Player && dmgedE instanceof Player) {
    
                Player dmger = (Player) e.getDamager();
                Player dmged = (Player) e.getEntity();
               
                if (Guardian.bruteSet(dmger.getEquipment())) {
                   
                    int damage = (int) (e.getDamage() - 2);
               
                    e.setDamage(damage);
                   
                    dmger.sendMessage("you have delt " + damage);
                }
            }
        }
    So it's just when I'm trying to change the values of how much damage a player can do to the guy in diamond armor issue.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  4. @Coopah Why are you using ints for damage? Damage is in doubles for a reason, you know. You also want to look into the Damage API in which you can change how armour affects the final damage.
     
  5. Offline

    Coopah

    @AdamQpzm
    I was using ints so I can easily put it in the message for test reasons. I didn't think of that.
     
Thread Status:
Not open for further replies.

Share This Page