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

Entitydamageevent

Discussion in 'Development' started by Habiba, Jan 13, 2018.

  1. Habiba

    Habiba Spider

    Messages:
    9
    GitHub:
    misu
    How can i fix
    PHP:
    public function onDamage(EntityDamageEvent $event){
           if(
    $event->getEntity() instanceof Player){
               if(isset(
    $this->iswildin[$event->getEntity->getName()])){
                   
    $p $event->getEntity();
                   unset(
    $this->iswildin[$p->getName()]);
                         
    $event->setCancelled();
               }
           }
        }
    }
     
    Last edited: Jan 13, 2018
  2. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    Please specify the error if you just tell how can i fix we dont know the problem and What do You think about using the [ PHP]
     
  3. Habiba

    Habiba Spider

    Messages:
    9
    GitHub:
    misu
    i dont get any error, the code just dont work, when i do /wild i get fall damage
     
  4. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    Make sure you register the events and implements listener
    And do
    PHP:
    $event->setCancelled(true);
     
  5. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    Be sure your class is registered as an event listener. You're code looks fine, ensure you are pushing the players name to the "iswildin" array. An alternative would be to teleport the player to a spot ontop of a block (not randomly in the air).
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Having "true" or not is the same.
     
    Palente likes this.
  7. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    Change

    PHP:
    $event->getEntity->getName()
    to

    PHP:
    $event->getEntity()->getName()
     
  8. Habiba

    Habiba Spider

    Messages:
    9
    GitHub:
    misu
    still dont work
     
  9. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Show how are you adding player to the array
     
  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.