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

Snowball Debuff when hits entity

Discussion in 'Development' started by Vaxrp, Nov 4, 2017.

  1. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    PHP:

    public function onDamage(EntityDamageEvent $event) {
            
    $victim $event->getEntity();
            
    $cause $event->getCause();
               
                if(
    $cause == EntityDamageEvent::PROJECTILE){
                    if(
    $victim instanceof Player){
                        
    $killer $event->getDamager();
    I dont know if Im even close. Am I correct on this? I know I have to check if the player was hit by a projectile get the victim and add a desired debuff to him but can you guys help me? Im stuck dont know if this is close to right
     
  2. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Use CAUSE_PROJECTILE instead
     
    Vaxrp likes this.
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    If the cause is EntityDamageEvent::CAUSE_PROJECTILE, you'll need to handle the next step in two divisions.
    PHP:
    //if cause = EntityDamageEvent::CAUSE_PROJECTILE
    $killer null;
    if(
    $event instanceof EntityDamageByChildEntityEvent){
        
    $projectile $event->getChild();
        
    $killer $event->getDamager();
    }else{
        
    $projectile $event->getDamager();
    }

    if(
    $projectile instanceof Snowball){//pocketmine\entity\projectile\Snowball
        //...
    }
    Yes, $killer can be null. It's null if the killer launched the projectile and quit the game, and the projectile later hits another entity.
     
  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.