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

Solved Monsters don't have an instance of anything

Discussion in 'Development' started by TwistedAsylumMC, Apr 22, 2018.

  1. TwistedAsylumMC

    TwistedAsylumMC Slime

    Messages:
    96
    GitHub:
    twistedasylummc
    Im using EntityDamageEvent to get the entity damaged, when i do
    PHP:
    $entity $event->getEntity();
    if(
    $entity instanceof Zombievar_dump(true);
    else 
    var_dump(false);
    and it always says false
    PHP:
    bool(false)
    is there any other way of getting the entity type?
     
  2. Erkam

    Erkam Spider

    Messages:
    13
    GitHub:
    erkamkahriman
    Try this:
    PHP:
    public function onDamage(EntityDamageEvent $event){
            
    $entity $event->getEntity();
            
    $event->setCancelled(true);
            if (
    $event instanceof EntityDamageByEntityEvent) {
                
    $damager $event->getDamager();
                if (
    $damager instanceof Player) {
                    if (
    $entity instanceof Zombie) {
                        
    $event->setCancelled(true);
                        
    $damager->sendMessage("Zombie");
                    }
                }
            }
        }
     
  3. TwistedAsylumMC

    TwistedAsylumMC Slime

    Messages:
    96
    GitHub:
    twistedasylummc
    didnt work
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Have you imported the Zombie class? PHP's instanceof doesnt throw any errors if the class you are comparing the object with doesn't exist.
    PHP:
    use pocketmine\entity\Zombie;
    You can add this to find the entity's class.
    PHP:
    var_dump(get_class($entity));
     
  5. TwistedAsylumMC

    TwistedAsylumMC Slime

    Messages:
    96
    GitHub:
    twistedasylummc
    ah... now you say it i realise what i done lol thanks for the help muq! also u never finished explaining the packet thing to me on sylph xD
     
  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.