Trampler kit : Target sneaking

Discussion in 'Plugin Development' started by TCO_007, Apr 6, 2014.

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

    TCO_007

    Hey guys! I have had this kit coded for a while but there is still something I want to add but I am confused on how to do that. Im sorry if it seems really stupid but I am new to coding. Basically what I am coding is the kit stomper, but renamed Trampler. I want it so when the player (the one who ISNT trampler) is sneaking, it will decrease the damage the trampler transfers to them. I need help on how to do that if anyone can provide it. Thanks!
    Trampler code:
    Code:java
    1. @EventHandler
    2. public void onPlayerDamage(EntityDamageEvent e) {
    3. if (e.getEntity() instanceof Player) {
    4. Player p = (Player) e.getEntity();
    5. if (plugin.trampler.contains(p.getName())) {
    6. if(e.getCause().equals(DamageCause.FALL)){
    7. e.setDamage((double) p.getFallDistance() / 8);
    8. if (p.getFallDistance() > 3) {
    9. List<Entity> nearby = p.getNearbyEntities(5, 5, 5);
    10. for (Entity tmp : nearby)
    11. if (tmp instanceof Player) {
    12. ((Player) tmp).damage((double) p.getFallDistance() / 2);
    13.  
    14. }
    15. }
    16. }
    17. }
    18. }
    19. }
     
  2. Offline

    Mr360zack

    if(!tmp.isSneaking()){
    // damage amount if not sneaking
    }
    else{
    // damage amount if sneaking
     
  3. Offline

    TCO_007

    Mr360zack so like this?
    Code:java
    1. @EventHandler
    2. public void onPlayerDamage(EntityDamageEvent e) {
    3. if (e.getEntity() instanceof Player) {
    4. Player p = (Player) e.getEntity();
    5. if (plugin.trampler.contains(p.getName())) {
    6. if(e.getCause().equals(DamageCause.FALL)){
    7. e.setDamage((double) p.getFallDistance() / 8);
    8. if (p.getFallDistance() > 3) {
    9. List<Entity> nearby = p.getNearbyEntities(5, 5, 5);
    10. for (Entity tmp : nearby)
    11. if (tmp instanceof Player) {
    12. if (!((Player) tmp).isSneaking()){
    13. ((Player) tmp).damage((double) p.getFallDistance() / 5);
    14. }else {
    15. ((Player) tmp).damage((double) p.getFallDistance() / 2);}
    16. }
    17. }
    18. }
    19. }
    20. }
    21. }
     
  4. Offline

    Mr360zack

    Looks good to me, does it work?

    Although right now you're doing less damage to users who are NOT sneaking

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

    TCO_007

    How would I fix that Mr360zack ?
    Do i take out the "!"?

    Nevermind Mr360zack
    Thanks for helping! It works now!

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

    Mr360zack

    Any time. Please mark thread as solved
     
  7. Offline

    TCO_007

    Im trying to mark it as solved but it keeps glitching out and wont let me but Ill keep trying to. Thanks for the help. :D
     
  8. Offline

    Mr360zack

    Just change title to say [SOLVED] in front of it if it's glitching
     
Thread Status:
Not open for further replies.

Share This Page