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

No error but crashes server.

Discussion in 'Development' started by WreckagePE / ZAYD, Mar 20, 2017.

  1. WreckagePE / ZAYD

    WreckagePE / ZAYD Slime

    Messages:
    82
    PHP:
    <?php   

    namespace MyPlugin\ZaydPE;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\entity\EntityDamageByChildEvent;
    use 
    pocketmine\entity\Entity

    class Main extends PluginBase{
        public function 
    onEntityDamageByEntityEvent;
           
    $damager->sendMessage("$entity has $health/$maxHealth hearts left!");
            }
    The code is here; bare in mind this is my first plugin and i have just learnt php
     
  2. WreckagePE / ZAYD

    WreckagePE / ZAYD Slime

    Messages:
    82
    It just crashes my server with no error...
     
  3. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    you didn't define any of your variables!
     
    Zayd likes this.
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    • You are missing a ";" at "use pocketmine\entity\Entity".
    • That's an invalid function.
    • No variables were defined.
    • The class must implement \pocketmine\event\Listener if you are going to call event functions from it.
     
    Last edited: Mar 21, 2017
    Zayd and jasonwynn10 like this.
  5. Zayd

    Zayd Witch

    Messages:
    55
    GitHub:
    ZaydPE
    Thankyou. By adding the use
    use pocketmine\entity\Entity;
    Isn't the $health + $damager variable already defined?
     
  6. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Jack Noordhuis, Zayd and jasonwynn10 like this.
  7. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    where in your code does it say
    PHP:
    $health $ev->getEntity->getHealth();
    $damager $ev->getDamager();
     
  8. Zayd

    Zayd Witch

    Messages:
    55
    GitHub:
    ZaydPE
    Sorry. What is $ev though? XD
     
  9. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    HimbeersaftLP likes this.
  10. Zayd

    Zayd Witch

    Messages:
    55
    GitHub:
    ZaydPE
    Alright. Thankyou guys for helping me :D
     
  11. Zayd

    Zayd Witch

    Messages:
    55
    GitHub:
    ZaydPE
    Can someone post a link to the functions list please guys? :D
     
  12. PocketKiller

    PocketKiller Slime

    Messages:
    83
    GitHub:
    iPocket
    I wonder why you made a "plugin tutorial" without understanding the very basics of PHP.
     
  13. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    PHP functions, or PocketMine API methods?
     
  14. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
  15. Zayd

    Zayd Witch

    Messages:
    55
    GitHub:
    ZaydPE
    Pocketmine Api methods
     
  16. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
  17. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    I recommend you to start basic of php on http://php.net
    You have not defined variables $health,$damager
    Here is correct code your your.
    PHP:
    public function onDamage(EntityDamageEvent $e){
    if(
    $e instanceof EntityDamageByEntityEvent){
    $damager $e->getDamager();
    $health $e->getEntity()->getHealth();
    $maxHealth $entity->getMaxHealth(); //If you are not using $entity->setMaxHealth() You can do $health/20 instead $maxHealth
    $damager->sendMessage("$entity has $health/$maxHealth hearts left!");
    }
    }
    The most used function are in Player.php
    https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/Player.php
    and Server.php
    https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/Server.ph
     
    Zayd likes this.
  18. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    It's better to use (') than (") while declaring string. You be the example.
    It just confused the readers and probably even PHP in understanding whether the / is meant to be a string or a mathematical operator for division of $health by $maxhealth.
    Better use
    PHP:
    $damager->sendMessage($entity.' has '.$health.'/'.$maxHealth.' hearts left!');
     
    Zayd likes this.
  19. Zayd

    Zayd Witch

    Messages:
    55
    GitHub:
    ZaydPE
    Thankyou so much @Kyd instead of saying negative you actually help !! :)!!
     
  20. Zayd

    Zayd Witch

    Messages:
    55
    GitHub:
    ZaydPE
    And thanks @Muqsit for clearing that up
     
  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.