Solved Change Damage Imunity (turning red).

Discussion in 'Plugin Development' started by uksspy, Oct 26, 2014.

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

    uksspy

    I'm looking to change the damage immunity of entities when they are hit with a projectile. This is to make "guns" that shoot snowballs at a high ROF (rate of fire) more effective. I would have assumed that there would be a method for modifying it under EntityDamageEvent but that is not the case.
     
  2. Offline

    CraftCreeper6

    uksspy
    You mean EntityDamageByEntityEvent?
     
  3. Offline

    uksspy

    I wasn't sure if the gun plugin I use fired that event. Even if it did the EntityDamageByEntityEvent doesn't have a method to modify immunity time.
     
  4. Offline

    CraftCreeper6

    uksspy
    What do you mean by "immunity time" what for? (I didn't understand your original post ;p)
     
  5. Offline

    uksspy

    I linked this explanation from the wiki in the OP.
    "Damage immunity

    After sustaining damage from any source, a mob will turn red in color for 0.5 seconds. During this period, any other incoming damage will not be counted against the mob's total health. For instance, if you attack a mob with a Sword repeatedly hitting the mouse button, the sword's rate of fire will exceed the mob's allowable rate of incoming damage, and several of the attacks will not damage the mob even if they land. (It is recommended to wait for a mob to be hittable again before swinging your sword, making your hits more precise. The tool used won't lose durability after unsuccessful attacks). However, if a mob or player is recovering from damage and then receives higher damage, it gets counted. Players are also subject to damage immunity."

    Hopefully that explains it.
     
  6. Offline

    CraftCreeper6

    uksspy
    I did look at it ;)
    Now I understand! Okay. What I would do is EntityDamageByEntityEvent
    Check both entites (One player & one whatever...)
    Cast them to player an whatever.
    Then add the mob to a list, if the player damages the mob again before they are removed from the list (You can use a scheduler) cancel the event & set damage to 0. Otherwise, do the damage.
     
  7. Offline

    rbrick

  8. Offline

    CraftCreeper6

    Or just do what rbrick said...
     
  9. Offline

    uksspy

    Thanks, I'll try that out!

    Ok, I managed to get it work. I had to use a slighting different method though.
    Here is my code for anyone else with the same problem:
    Code:java
    1. @EventHandler
    2. public void onEntityDamage(EntityDamageByEntityEvent e){
    3. if(e.getCause() == DamageCause.PROJECTILE && e.getEntity() instanceof LivingEntity){
    4. LivingEntity ent = (LivingEntity) e.getEntity();
    5. ent.setMaximumNoDamageTicks(0);
    6. }
    7.  
    8. }


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

    rbrick

    uksspy alright. i knew it was one of the two methods.
     
Thread Status:
Not open for further replies.

Share This Page