Solved Resistance Effects

Discussion in 'Plugin Development' started by Pink__Slime, May 24, 2013.

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

    Pink__Slime

    Ok so I want to give players resistance without actually giving them the potion.
    I currently have an event cancelling a percentage of the damage as resistance would but when you hit the player it doesn't make them appear to be hit though they actually are losing health.

    Is there a way of doing this so they will appear to be getting hit?

    My event:
    Code:java
    1. @EventHandler
    2. public void resistanceEvent(EntityDamageEvent event){
    3. if(event.getEntity() instanceof Player){
    4. Player player = (Player) event.getEntity();
    5. double damage = event.getDamage();
    6. if(Main.playTurtle.containsKey(player.getName())){
    7. if(player.isSneaking()){
    8. int resistHealth = (int) (damage * 0.8);
    9. event.setCancelled(true);
    10. player.setHealth(player.getHealth() - resistHealth);
    11. }
    12. }else if(Main.playTank.containsKey(player.getName())){
    13. int resistHealth = (int) (damage * 0.2);
    14. event.setCancelled(true);
    15. player.setHealth(player.getHealth() - resistHealth);
    16. }
    17. }
    18. }
     
  2. Offline

    Garris0n

    player.damage(x)
    Just do player.damage(0) and it will look like they're getting hit.
     
  3. Offline

    Pink__Slime

    Garris0n
    Ok I'm now using this.
    Code:java
    1. @EventHandler
    2. public void resistanceEvent(EntityDamageEvent event){
    3. if(event.getEntity() instanceof Player){
    4. Player player = (Player) event.getEntity();
    5. double damage = event.getDamage();
    6. if(Main.playTurtle.containsKey(player.getName())){
    7. if(player.isSneaking()){
    8. int resistHealth = (int) (damage * 0.8);
    9. event.setCancelled(true);
    10. player.damage(resistHealth);
    11. }
    12. }else if(Main.playTank.containsKey(player.getName())){
    13. int resistHealth = (int) (damage * 0.2);
    14. event.setCancelled(true);
    15. player.damage(resistHealth);
    16. }
    17. }
    18. }


    Now the players in those HashMaps (playTank & playTurtle) don't get knocked back at all.
     
  4. Offline

    thecrystalflame

    you could try setting the damage rather than making your own damage.
    do this by:

    Code:JAVA
    1.  
    2. event.setDamage(damage * 0.2);
    3.  


    this should fix your issue
     
  5. Offline

    Pink__Slime

    If I use that will it cancel what would of been the damage or does it add the damage on top of what would of been the damage

    Ok nothing is working. It's only for those in the HashMaps, playTank & playTurtle. - They don't take any damage at all.

    Event:
    Code:java
    1. @EventHandler
    2. public void resistanceEvent(EntityDamageEvent event){
    3. if(event.getEntity() instanceof Player){
    4. Player player = (Player) event.getEntity();
    5. int damage = event.getDamage();
    6. if(Main.playTurtle.containsKey(player.getName())){
    7. System.out.println(player.getName() + " is turtle");
    8. if(player.isSneaking()){
    9. System.out.println(player.getName() + " is turtle and shifting");
    10. int resistHealth = (int) (damage * 0.2);
    11. event.setDamage(resistHealth);
    12. System.out.println("Orginal Damage: " + damage + ". Damage taken: " + resistHealth);
    13. }
    14. }else if(Main.playTank.containsKey(player.getName())){
    15. System.out.println(player.getName() + " is tank.");
    16. int resistHealth = (int) (damage * 0.8);
    17. event.setDamage(resistHealth);
    18. System.out.println("Orginal Damage: " + damage + ". Damage taken: " + resistHealth);
    19. }
    20. }
    21. }


    I don't get any of the messages I added nor do I get any errors.

    Ok, turns out there was an error in another one of my classes that caused events not to work and messages to send thrice. I wouldn't of found that if I didn't kill myself.
    It works now.

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

    thecrystalflame


    no as im sure you figured out since you say its now working, it does not apply the original damage
     
  7. Offline

    Garris0n

    Pink__Slime just so you know for the future(it may be helpful) you can do player.damage(0, [player]) to damage somebody by somebody else(which generates knockback).
     
Thread Status:
Not open for further replies.

Share This Page