Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved check snowball was interacted to player

Comments in 'Plugin Development' started by MikkiMCPE, May 18, 2016.

  1. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    what event should i use for it?

    i want make snowball can kill player in 1 shoot, thanks you
    PaulchenHD likes this.
  2. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    ProjectileHitEvent.
    PaulchenHD and iksaku like this.
  3. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    Can you give me some example usage?
    PHP:
    $player $event->getEntity;
    $snowball //???
    if($player instanceof Player){

    }
    ?
    PaulchenHD likes this.
  4. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    Last edited: May 18, 2016
    PaulchenHD likes this.
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    I assume you want to know if snowball hit a player, right? You have to capture EntityDamageEvent in that case.
    PHP:
    public function onHit(EntityDamageEvent $e){
            if(
    $e instanceof EntityDamageByEntityEvent === false) return;
            if(
    $e->getCause() === EntityDamageEvent::CAUSE_PROJECTILE){
                    
    $projectile $e->getDamager();
                    if(
    $projectile instanceof Snowball){
                           
    # Entity was hit by a snowball
                    
    }
            }
    }
    Last edited: May 19, 2016
    PaulchenHD, MikkiMCPE and Survingo like this.
  6. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    PHP:

    public function onHit(EntityDamageEvent $ev){
    $player $ev->getEntity();
    if(
    $player instanceof Player){
    if(
    $ev->getCause() == EntityDamageEvent::CAUSE_PROJECTILE){
    $player->kill():
    }}
    i use it
    PaulchenHD likes this.
  7. PaulchenHD
    Offline

    PaulchenHD Active Member

    Joined:
    Jan 17, 2016
    Posts:
    111
    Minecraft User:
    Paulchen_HD
    PHP:

    public function onHit(EntityDamageEvent $event){
    $player $event->getEntity();
    $snowball $event->getDamager();
    if(
    $player instanceof Player){
      if(
    $event->getCause() == EntityDamageEvent::CAUSE_PROJECTILE){
      if(
    $snowball instanceof Snowball){
      
    $player->kill();
      }
      }
    }
    :p
  8. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    This will cause error if entity was damaged by environment. You must add this line to avoid that
    PHP:
    if($e instanceof EntityDamageByEntityEvent === false) return;
    Btw, nice signature.
    PaulchenHD likes this.
  9. PaulchenHD
    Offline

    PaulchenHD Active Member

    Joined:
    Jan 17, 2016
    Posts:
    111
    Minecraft User:
    Paulchen_HD
    okay thx ;)

Share This Page

Advertisement