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

If Damage Reason Is Fall Damage Then Do This

Discussion in 'Development' started by DaRealPandaz, Aug 6, 2019.

  1. DaRealPandaz

    DaRealPandaz Silverfish

    Messages:
    24
    GitHub:
    mrpandaz
    I am trying to get when a player takes fall damage while wearing a mask(Special Armor). If they take damage I want them to get the Effect Night Vision.

    PHP:

    public function onDamageByOther(EntityDamageEvent $event){
        
    $player $event->getEntity();

        
    $isFall $event->getCause() === EntityDamageEvent::CAUSE_FALL;
        if(
    $isFall){
            if(
    $player instanceof Player){
                if(
    $player->getArmorInventory()->getHelmet()->getId() === 86){
                    
    $player->addEffect(new EffectInstance(Effect::getEffect(Effect::NIGHT_VISION), 21474836471false));
                }
            }
        }

        if(
    $player instanceof Player){
            if(
    $player->getArmorInventory()->getHelmet()->getId() === 86){
                    
    $player->addEffect(new EffectInstance(Effect::getEffect(Effect::NIGHT_VISION), 21474836471false));
            }
        }
    }
    Any Help would be great thank you!!!
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    /QUOTE]
    86? 86 isn't guaranteed to be any item's ID. Use Item::DIAMOND_HELMET or something instead. Also, check your imports.
     
    HimbeersaftLP likes this.
  3. DaRealPandaz

    DaRealPandaz Silverfish

    Messages:
    24
    GitHub:
    mrpandaz
    Its a pumpkin Mask...
     
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Have you registered listener?
     
  5. DaRealPandaz

    DaRealPandaz Silverfish

    Messages:
    24
    GitHub:
    mrpandaz
  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.