No Knockback

Discussion in 'Plugin Development' started by coopjc, Feb 16, 2016.

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

    coopjc

    Hi, How can I make it so when a player gets hit by another player, projectile, mob, etc, they don't take knock back? If you know how to do this please reply.

    Thank you!
     
  2. @coopjc
    Listen for an EntityDamageEvent, check the cause of the damage (e.g Arrow), set velocity to 0.
    May cause issues if they are running, not sure.
     
    Last edited: Feb 16, 2016
  3. Offline

    Xerox262

    @Connor2weirdness Wouldn't that just stop the entity that attacked them from moving?

    @coopjc There's a very dirty way to do this, it's to cancel damage events then set health to be health - damage.

    There is a method for living entities called damage, however it's possible that method could call an event (The method would call the event, the event would call the method, the method would call the event...), if it doesn't then you should use damage instead of setHealth.

    There's another problem with this though, the player will not appear red and it will not look as if they were damaged at all, nor will they achieve the built in 10 ticks of invulnerability that is built in after each hit so a entity could be killed quite quickly.

    Edit: Spacing...
     
  4. @Xerox262
    I mean, set the player's velocity to 0.
     
  5. Offline

    Xerox262

    @Connor2weirdness Since that would be set inside the event handler all that should do is clear the player's velocity before the knockback is applied, the knockback is not actually applied until the event returns as not cancelled.

    Which means it needs to run through all event handlers first.
     
  6. Offline

    coopjc

    Example?
     
  7. Offline

    Xerox262

  8. Offline

    Skylandz

     
    Connor2weirdness likes this.
  9. Offline

    teej107

    Connor2weirdness likes this.
Thread Status:
Not open for further replies.

Share This Page