How to prevent melee damage? Only take damage from the shot

Discussion in 'Spigot Plugin Development' started by JunoMC, Nov 9, 2019 at 6:07 AM.

  1. i have a problem with my plugin! pls help me :v
     
  2. Very informative!
    Tell about the problem, show what you have tried already and what doesn't work.
     
  3. You can always on some EntityDamageByEntityEvent and check did is projectile

    Code (Java):
    @EventHandler
        public void onDamage(EntityDamageByEntityEvent event) {
            if(event.getCause() != EntityDamageEvent.DamageCause.PROJECTILE) {
                 event.setCancelled(true);

            }
        }
     
  4. I use ((LivingEntity)victim).damage(0.5, p);
    DamageCause is ENTITY_ATTACK
     
  5. you said that is shot, but ok, just check did is ENTITY_ATTACK and take 0,5 dmg
     
  6. Shot by Particles xD!
    And how to anti melee damage?
     
  7. melee damage is also ENTITY_ATTACK
     
  8. what? create a projectile and deal damage with it..
     
  9. The easiest option is to just set a boolean field to true before the damage call, and false afterwards. Then when an EntityDamageEvent is fired and the boolean field is false, cancel the event.
     
  10. But damage of particles is custom from config!
     
    #10 JunoMC, Nov 9, 2019 at 10:49 AM
    Last edited: Nov 9, 2019 at 10:57 AM
  11. Can u give me some examples?
     
  12. That doesn't matter. The boolean field would simply be to detect whether you caused the damage or not.
     
  13. So, how to distinguish melee and damage from shot?
     
  14. I didn’t ever use particles but why don’t you check if the particle location is the same as the player’s and then deal damage? If that’s how it works
     
  15. Yes!
     
  16. Yes what? :)
    Did it work?
     
  17. My problem is when location of particle same player, the player will be damaged! But how to anti melee damage! Just use damage of shot
     
  18. Cancel player damage event if the particles aren’t in the same place as the player, else damage the player