[Tutorial] Removing Damage Tick Delay

Discussion in 'Resources' started by sethrem, Nov 10, 2014.

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

    sethrem

    Hello Bukkitians,

    Objective:
    • Removing EntityDamageByEntityEvent Tick Delay
    Result:

    • Entities can damage players more than once in 10 ticks(Which is the damage Tick Delay)
    Information:
    If you wanted to damage an entity more than once in a tick for instance thinking about a gun, a shotgun in specific, it shoots more than one bullet(or shell) at once. If you were to use snowballs as the projectile which is going to act like the bullets, you would not be able to damage a player within 10 ticks of the first hit so the player would only be damaged by one snowball.
    Code:
    Before Code

    Code:java
    1. @EventHandler
    2. public void onDamage(EntityDamageByEntityEvent e) {
    3. if (e.getEntity() instanceof Player) {
    4. if (e.getDamager() instanceof Snowball) {
    5. Snowball sball = (Snowball) e.getDamager();
    6. Player victim = (Player) e.getEntity();
    7. Player attacker = (Player) sball.getShooter();
    8. if (attacker.getItemInHand().getType().equals(Material.IRON_BARDING)) {
    9. e.setDamage(14.0);
    10. }
    11. }
    12. }
    13. }

    Now the code above wont allow multiple hits to get registered within 10 ticks which is the damage tick delay. To remove this delay we would do the following.

    Above:
    Code:java
    1. e.setDamage(14.0);


    Add:
    Code:java
    1. victim.setNoDamageTicks(0);


    Finished Code

    Code:java
    1. @EventHandler
    2. public void onDamage(EntityDamageByEntityEvent e) {
    3. if (e.getEntity() instanceof Player) {
    4. if (e.getDamager() instanceof Snowball) {
    5. Snowball sball = (Snowball) e.getDamager();
    6. Player victim = (Player) e.getEntity();
    7. Player attacker = (Player) sball.getShooter();
    8. if (attacker.getItemInHand().getType().equals(Material.IRON_BARDING)) {
    9. victim.setNoDamageTicks(0);
    10. e.setDamage(14.0);
    11. }
    12. }
    13. }
    14. }


    Finished:
    Now you have followed these steps you have finished your goal. If you have any questions on this subject please comment below because I do feel as if I did not elaborate enough, if so I will do my best to explain this more as much as possible. Please forgive me if this is bad due to it being my first tutorial.
     
    ChipDev and GrandmaJam like this.
  2. Offline

    xTrollxDudex

    So this would only work if you are holding IRON_BARDING?
     
  3. Offline

    sethrem

    xTrollxDudex No, You can remove that if statement if you'd like and then it would work for everything. I just had that iron barlding to use as a gun.

    AdamQpzm I guess so.
     
    Last edited by a moderator: Jul 4, 2015
    ChipDev likes this.
  4. Offline

    Agentleader1

    I LOVE THIS POST! Never thought it was THAT EASY! :D

    Is this probably what mineplex does for the paintball shotgun?

    //Edit: no longer works... How do you make this work now?
     
    Last edited: Feb 16, 2015
    ChipDev likes this.
  5. Offline

    redstone13

    Now you need to use "LivingEntity" instead of "Player"
    Code:
    LivingEntity victim = (LivingEntity) event.getEntity();
    victim.setNoDamageTicks(0);
    victim.damage(10.0);
    //or event.setDamage(10.0);
    But there is still something that doesn't work...
    My Shotgun code is still not working, only one bullet per shot is damaging even if 4 bullets hitted the LivingEntity...
     
Thread Status:
Not open for further replies.

Share This Page