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

How can you specify the Projectile in the ProjectileHitEvent event?

Discussion in 'Development' started by Minetron26, Oct 8, 2018.

  1. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    Hello, I need to know if there is a way to specify the type of projectile in the ProjectileHitEvent, how to specify that the projectile is an arrow, and that when specifying the arrow, maybe with: "if(){", only when hitting the player with the arrow thrown you an effect for example regeneration.
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    okay so the most "non hacky" way would to be
    first:
    register an projectile class with a different name
    add a variable which determine it's effect

    second:
    on the projectile hit event
    you can check the class of the projectile that just hit the player
    you do this by if $projectile instanceof CustomArrow
    and switch ($customArrow->effectID) (or even better the ID is also the ID of the potion effect)
    and then applying it to player
     
  3. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    Thank you for your help, but when you throw the arrow to the player and when you hit it does not give the effect.

    I did it well?
    PHP:
    public function onProjectileHit(ProjectileHitEvent $eventProjectile $projectile){
            
    $customarrow $event->getEntity("ARROW");
            
    $player $event->getPlayer();
            
    $arroweffect Effect::getEffect(10);
            if(
    $projectile instanceof CustomArrow) {
                
    $customarrow->addEffect(new EffectInstance($arroweffect999999));
                }
            }
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    because your event isnt fired
    events are only fired when:
    the function access is public
    argument must only be one class that is an instance of event

    your function failed that check so no matter what you do nothing will happen

    you need to CHECK whatever that hits a player is a custom arrow, if it is apply an effect
     
  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.