Solved What's up with setNoDamageTicks() ?!

Discussion in 'Plugin Development' started by Digi, Apr 16, 2013.

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


    EDIT: Mistery solved:

    I needed to use this method but now apparently it does not work properly... but the goal is to prevent entity damage done by my createExplosion(), if you have an alternative that doesn't involve events please do tell.

    So, I did some tests on this... I've set setNoDamageTicks() to 1... then to 2.. then to 5, 10... and still doesn't want to block explosion damage, explosion beeing called right after that code so 2 ticks or more is overkll.
    But the strangest part is that if I set it to 20 it works... but I can't use that because I get 1 second of invulnerability, which is not good.

    Then I had a look at max no damage ticks, apparently player's max no damage ticks is 20, if I change that to 1 and set nodamage ticks to 1 I get invulnerability... :confused:

    So to be clear, in code...

    This does NOT work
    player.setNoDamageTicks(1); // does work if I set it to player.getMaximumNoDamageTicks() which is 20 ticks
    // explosion
    This DOES work:
    // explosion
    Anyone know what's going on ? =)

    I'm currently storing max ticks, setting them to 1 and no damage ticks to 1 as well then after explosion I'm restoring max ticks.
  2. Offline


    Hmm. That's interesting. I'll have a look at it in the morning.
  3. Offline


    Bump, anyone got ideas ?
  4. Offline


    Digi Nope, sorry, I wanted to help you once, but I don't know how to do this, I have no expercience with setNoDamageTicks(). I learned a lot of your explanations on this forum. And now you ask one question and I can't help you. I just want to do something back :), but I can't do something back this time, sorry

    PS: Is it: I wanted to help you once or is it I wanted to help you ones?
  5. Offline


    I don't need any schedulers because I can solve the problem (see last paragraph in the thread).

    My question is why is that code solution necesary ? By using setNoDamageTicks() to a value lower than getMaximumNoDamageTicks() it doesn't grant invulnerability which makes no sense.

    setMaximumNoDamageTicks() affects how many ticks the entity has invulnerability after recieving damage... like in platformer games where you blink out after getting damaged and don't get damage for 1-2 seconds.

    I used explosions because I needed that for explosions, I belive it will act the same way for any other kind of damage, feel free to test.

    The "ones" word has a diferent meaning, it's "once".
  6. Offline

    Hoolean Retired Staff


    Unless I'm incorrect, 'DamageTicks' refers to the amount of ticks that have passed since the player was last damaged and has no effect on preventing damage.
  7. Offline


    It's "NoDamageTicks" which sets godmode for a specific amount of ticks.
  8. Offline

    Hoolean Retired Staff

    Yes, "NoDamageTicks" is what I meant.

    Are you sure it provides "godmode"? Have you tested this?
  9. Offline


    Ok, so here's the deal.

    Yes, the "no damage ticks" are that godmode kind of thingy that prevent you from being damaged twice in quick succession.

    No, its value is not as simple as "the amount of ticks to pass until the entity can be damaged again".

    Don't ask me why, but the algorithm is as follows:
    • Decrease noDamageTicks by 1 per tick (until it hits 0)
    • Upon receiving damage, if noDamageTicks is larger than the half of maxNoDamageTicks:
      • cancel the damage if the current damage is smaller than the last damage received (the one that caused you to get the "no damage timer"
      • otherwise, damage the entity by the difference of the current damage and last damage
    • If damage was applied, set noDamageTicks to maxNoDamageTicks

    I'm honestly having a hard time understanding the purpose of the "larger than half of the max", but that's not up to us to change ;)
    Basically, what that also tells you is that when the last damage the player recently received (like half a heart of fall damage) will (theoretically) cause your explosion to still cause some damage even if in "invincible mode".

    Possible concept for a solution:
    // execute your explosion
    // reset invincibility
  10. Offline


    Now that just makes no sense :p how would 'no damage ticks' mean the time since last damage ?

    I see, now that actually makes more sense, thanks for the explication and the new solution.

    I think I would also have to reset LastDamage to previous value to not screw with results of other plugins.
  11. Offline

    Hoolean Retired Staff

    Behold the logic I use when I probably should be sleeping ;)
  12. Offline


    It's probably cleaner to do that, yes, even though the value isn't currently used anywhere other than in combination with noDamageTicks and doesn't server any other use.
    Storing the old value beforehand and resetting to the original value afterwards is probably the best way, just in case some other plugin happens to use it for something of importance, you're right :)
Thread Status:
Not open for further replies.

Share This Page