Direct Damage

Discussion in 'Plugin Development' started by Coopah, May 30, 2015.

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

    Coopah

    How would I inflict direct damage to a player ignoring their armor and enchantments on it.

    I've tried the player.damage(damageD) feature but seem to have issues. I've also tried event.setDamage(0D) then tried to set the damage getting their health and subtracting damage only to find errors.

    Any help will be much appreciated :)
     
  2. Offline

    seanliam2000

    What is wrong with something like this:

    Code:
         event.getPlayer.setHealth(event.getPlayer.getHealth() - 8); 
    Works for me
     
  3. Offline

    Konato_K

    @Coopah What seanliam2000 said, just take in account that setting health lower than 0 throws and exception, so you need to check that, also use Player#playerEffect to play the hurt effect
     
  4. Offline

    Coopah

    @Konato_K @seanliam2000
    I'm using this code but it doesn't work. It just keeps setting their health to the same amount. It puts them on 2 hearts instead of subtracting 2 hearts from their health and then every shot following that will keep them on 2 hearts.

    Isn't #getHealth just getting their total health and not current?

    Code:
    Code:
    @EventHandler
        public void onArrowLand(EntityDamageByEntityEvent e) {
    
            Entity damagerE = e.getDamager();
            Entity damagedE = e.getEntity();
    
            if (damagerE instanceof Arrow && damagedE instanceof Player) {
    
                Player damaged = (Player) damagedE;
                final Arrow arw = (Arrow) damagerE;
    
                if (arw.getShooter() instanceof Player) {
    
                    final Player damager = (Player) arw.getShooter();
    
                    e.setDamage(0D);
    
                    if (ArrowToggles.CripplingArrows.contains(damager.getName())) {
    
                        damaged.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 60, 1));
                        e.setDamage(6D);
    
                    } else if (ArrowToggles.PiercingArrows.contains(damager.getName())) {
    
                        damaged.damage(damaged.getHealth() - 8);
    
                    } else {
    
                        e.setDamage(6D);
    
                    }
                }
            }
        }
    
     
  5. Offline

    teej107

    Yes. I don't see you setting the player's health in your code as
    @seanliam2000 suggested
     
    seanliam2000 likes this.
Thread Status:
Not open for further replies.

Share This Page