Solved How to stop damage cooldown?

Discussion in 'Plugin Development' started by TheSporech, Apr 19, 2016.

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

    TheSporech

    Hi!
    You know how in MC, mobs/players/animals or whatever, can't take damage too often, like if you kept hitting a creeper, it would only be registering half the hits?

    I've seen plugins (such as bending- using rapidpunch) override this somehow. How is this possible?
     
  2. Offline

    mine-care

    @TheSporech
    Well keep a Map with the entity ID as key, and a Long as value.
    On hit, check if the map contains the attacker's ID, if it does, check if the last time they hit (the value which is in miliseconds) plus the cooldown value in miliseconds is less than the current timestamp. If it is allow them to hit. Otherwise cancel the damage.

    Now, to explain better, here is a code-like representation:
    Code:
    Map <Integer,Long> MAP ;
    
    onHit{
       if MAP contains DAMAGER_ID then:
           if( MAP get DAMAGER_ID + COOLDOWN_IN_MS > CURRENT_TIME_MILISECONDS ) then:
              cancelHit
           end if.
       end if.
    }
    
     
  3. Offline

    TheSporech

    I don't want to add my own cooldown, I want to get past the default MC cooldown.
    MC only registers hits every X ticks, yet some plugins seem to get past this. How?
     
    Last edited: Apr 19, 2016
  4. Offline

    CoolDude53

    @TheSporech
    Use LivingEntity#setMaximumNoDamageTicks(int ticks). The default is 20 ticks, so you can lower it, but this is not permanent, you will need to set it for every entity when they are spawned (if you want to change entities) and every player when they join (if you want to change players).
     
    Last edited: Apr 19, 2016
  5. Offline

    I Al Istannen

    @CoolDude53
    Umm, you linked another method than you wrote. I think the linked one is the correct one.
     
  6. Offline

    TheSporech

    Thanks, this is what I needed.
    When you say it isn't permanent, do you mean that the effect will wear off? or it doesn't apply globally?
     
  7. Offline

    CoolDude53

    oops, fixed ;3

    @TheSporech
    I mean that when you set a player max no damage ticks, it will reset every time they logout. Mobs just need to have it set whenever they spawn.
     
  8. Offline

    TheSporech

    Thanks dude!
    This really helps.:cool:
     
  9. Offline

    WolfMage1

    You could just combine the 2 ifs :p
     
  10. Offline

    mine-care

    @WolfMage1 Ofcourse, but does it make it more readable? Nope! Does it make it more efficient? Nope! so i can't see a reason to do it ;)
     
Thread Status:
Not open for further replies.

Share This Page