1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Entity damage

Discussion in 'Development' started by Nora1903, Jul 16, 2018.

  1. Nora1903

    Nora1903 Slime

    Messages:
    82
    GitHub:
    cuongvnz
    How can i set damage to an entity without hit it ?Thanks
     
  2. Aviv

    Aviv Baby Zombie

    Messages:
    156
    PHP:
    /** @var float $damage */
    /** @var Entity $entity */
    $entity->setHealth($entity->getHealth() - $damage);
    This method ignores armor, strength, resistance, etc.
    EDIT: if you dont want the damage to ignore armor you must use Entity::attack(EntityDamageEvent $event);
    PHP:
    /** @var float $damage */
    /** @var Entity $entity */
    $entity->attack(new EntityDamageEvent($entityEntityDamageEvent::CAUSE_CUSTOM$damage)); // new EntityDamageEvent(Entity $target, int $cause, float $damage, array $modifiers = [])
     
    Last edited: Jul 16, 2018
  3. Nora1903

    Nora1903 Slime

    Messages:
    82
    GitHub:
    cuongvnz
    Are there any ways to make it like EntityDamageByEntityEvent?
     
  4. Aviv

    Aviv Baby Zombie

    Messages:
    156
    So you want an entity attacking another entity? or just an entity being attacked
    BTW read my edited post XD
     
    Last edited: Jul 16, 2018
  5. Nora1903

    Nora1903 Slime

    Messages:
    82
    GitHub:
    cuongvnz
    sorry , i mean that just an entity being attacked, not other damaged entity
     
  6. Aviv

    Aviv Baby Zombie

    Messages:
    156
    The second method I put in my reply is what you want to use.
     
  7. Nora1903

    Nora1903 Slime

    Messages:
    82
    GitHub:
    cuongvnz
    So the damage value will be the $damage right?
     
  8. Aviv

    Aviv Baby Zombie

    Messages:
    156
    Quite obvious, yeah
     
  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.