Reduce incoming damage when crouching

Discussion in 'Plugin Development' started by Doodledew, Jun 27, 2013.

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

    Doodledew

    Hi there!
    I was wondering how I can reduce incoming damage when crouching? (like if you get hit by a diamond sword it will only take half a heat damage etc) and when you're crouched you can't attack people! So that balances the kit. (ye, it's a kit)
     
  2. Offline

    Firefly

    1. Listen to the EntityDamageByEntityEvent
    2. Check if both entities involved are instance of Players.
    3. Check if the player being attacked is crouching, and if so reduce the event's damage by half.
    4. Check if the player attacking is crouching, and if so reduce the event's damage to 0.
     
  3. Offline

    CubieX

    Use the "EntityDamageByEntityEvent" for example and look if the player is sneaking.
    (player.isSneaking())
    There you can reduce the damage to your custom value.
     
  4. Offline

    Doodledew

    Thank you so much for the fast reply! :) You're awesome :D
     
  5. Offline

    Rprrr

    Burnett1
    What about ...

    1. Not feeding code.
    2. Knowing that this would not reduce all incoming damage, but only damage done in player versus player (so not player versus environment) situations.
    3. Knowing that you can still crouch and attack non-player entities.
     
  6. Offline

    skipperguy12

    You're looking for the EntityDamageEvent, read about it here:
    http://jd.bukkit.org/rb/apidocs/

    You can get if someone is crouching by getting the isSneaking() boolean from the Player class, also in the javadocs.

    For reducing damage, just read the methods you can use in the superclass of the event (EntityDamageEvent extends EntityDamageEvent), here are a few you might need:
    Edit: Oh, and you may need to use setCanceled(boolean bool) for when a sneaking player tries to attack
     
    Doodledew likes this.
  7. Offline

    Burnett1

    I'm bored and was looking for something to do before i left. So i done that quickly. Some people learn a lot from seeing code, others copy and paste. Its up to them on which person they are. The dedicated ones will study and not copy.
     
  8. Offline

    skipperguy12

    Burnett1
    That isn't helping her at all...
    Like Rprrr said, don't feed code, give examples, and use the javadocs...
    Anyways, even if your code doesn't do what he wants, simply by giving him examples, she'll figure out what to do.

    Edit: Changed to she and her :p
     
  9. Offline

    Doodledew

    Thanks, I'll try and figure it out ^^
    Btw, I'm a girl ._.


    How can I make this event only available for certain players? (like players in an arraylist)

    if(turtlecontains(p.getName())) {

    // code


    right?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  10. Offline

    skipperguy12

    Doodledew
    If turtle is an ArrayList<String>, then yes :)

    It's not exactly making the event for certain players, it's more of just checking to make sure they're in the array, the event will still be called for everyone though.
     
  11. Offline

    Doodledew

    skipperguy12 ye, it's a kit :3 An ye, and an ArrayList<String> :D
     
  12. Offline

    chasechocolate

Thread Status:
Not open for further replies.

Share This Page