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

Please check this code

Discussion in 'Development' started by Nader Jafari, Mar 28, 2018.

  1. Nader Jafari

    Nader Jafari Silverfish

    Messages:
    16
    PHP:
        public function onEDBEE(EntityDamageEvent $ev){
            if(
    $ev instanceof EntityDamageByEntityEvent){
                
    $damager $ev->getDamager();
                
    $entity $ev->getEntity();
                if(
    $damager instanceof Player){
                    if(
    $enitity instanceof SLIME){
                        
    $ev->setDamage(0);
                        
    $ev->setKnockBack(10);
                    }
                }
            }
        }
    My Idea is using Slime entity as a ball for football with resourcepack and plugin
    I want to when a player attacked Slime, Slime knockback to 10 block farther and don't took any damage from attack
    When I started the server, There wasn't any error but in many years I program in C++ I know when my code ran for first time and I don't have any error there is a problem
    However, I'm amateur in PMMP API please check my code and post my problem in this thread
    and sorry for my incorrect English grammer if there is a problem in my text grammer
     
    Last edited: Mar 29, 2018
  2. yuko fuyutsuki

    yuko fuyutsuki Slime

    Messages:
    77
    GitHub:
    fuyutsuki
    There is no grammatical mistake in the presented code.
     
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    instanceof doesn't give errors when a class does not exist. So, for example:
    PHP:
    /** @var Player $player */
    return ($player instanceof AClassThatDoesNotExist);//AClassThatDoesNotExist is a class that does not exist
    will return false and no errors. Did you name your slime class SLIME and not Slime? And did you import the Player class? There's a typo in $entity vs $enitity. You probably didn't import the Player class so the code isn't being executed beyond.
     
  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.