How can I stop the damage without interrupting anything else?

Discussion in 'Development' started by YogaLose, Jun 2, 2021.

  1. YogaLose

    YogaLose Spider

    Messages:
    10
    I want the player to take damage, but don't let his original health decrease, but the date.
    PHP:
    public function OnDamage(EntityDamageEvent $event){
            
    $data = ["Health" => 500];
            
    $damage =   $event->getFinalDamage();
            
    $count   =   $data["Health"] - $damage;
            
    $data["Health"] = $count;
            
    $event->setCancelled();
        }
    But when stopping the damage, the player doesn't make animation or sound, how can I stop it without this happening?
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    647
    Try setting the damage to zero?
     
    minijaham and ErikX like this.
  3. YogaLose

    YogaLose Spider

    Messages:
    10
    And how do I do this for everything?
    I think I did something like that, even going to 0 damage, the heart lost (0.5)
    and knockback works?
     
    Last edited: Jun 2, 2021
  4. minijaham

    minijaham Zombie Pigman

    Messages:
    514
    GitHub:
    minijaham
    Set the base damage 0 and dont cancel the event
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.