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

Action onEntity hit

Comments in 'Plugin Development' started by JackboyPlay, May 22, 2016.

  1. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    How can I do an action if a player hits an blaze?
  2. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    no answers...
  3. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    PHP:
    public function onHit(EntityDamageEvent $event){
    if(
    $event instanceof EntityDamageByEntityEvent){
    if(!
    $player $event->getDamager() instanceof Player) return;
    if(
    $blaze $event->getEntity() instanceof Blaze){

    // function

    }}
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    // functions
    var_dump($player);
    var_dump($blaze);
    (bool)true
    (bool)true

    Solution:
    PHP:
    if(!($player $event->getDamager()) instanceof Player) return;
  5. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    eh what?
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    By doing
    PHP:
    if($blaze $event->getEntity() instanceof Blaze){
    You'll set $blaze as an result to 'instanceof' call. You're missing surrounding parenthesis.

    Also look here
    Last edited: May 22, 2016
    Irish likes this.
  7. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    is it possible with if($victim instanceof Blaze) ?
  8. MikkiMCPE
    Offline

    MikkiMCPE Active Member

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

    PHP:
    $victim $event->getEntity();
  9. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Why did you choose that line of code as an example?
  10. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    That was last code I looked at before I wrote that post. Although off-topic, it's great question :D
    Legoboy0215 likes this.

Share This Page

Advertisement