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

Trying To Detect How Many People In A World

Comments in 'Plugin Development' started by Calrizer, Jan 24, 2015.

  1. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Hello again people of PocketMine, I need your help!!

    I'm trying to create a plugin that detects how many people are in an arena and if there are less than 20 it says [Join] at the top of a sign and if there is more than 20 and less than 25 a VIP the sing will display [VIP] on the top of the sign.

    Here is the code:

    PHP:
    if($tile instanceof Sign){
                       
                        
    $t $tile->getText();
                       
                        if(
    $t[0] == "[SG]"){
                           
                            
    $world $t[1];
                            
    $name $t[2];
                           
                            if(
    $this->getOwner()->getServer()->isLevelLoaded($world) == true){
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                               
                                if(
    $online 20){
                                    
    $tile->setText("[Join]" $world $name $ol "/24");
                               
                                }elseif(
    $online 25 and >= 20){
                                    
    $tile->setText("[VIP]" $world $name $ol "/24");
                               
                                }elseif(
    $online == 24){
                                    
    $tile->setText("[Full]" $world $name $ol "/24");
                                }
                            }
                        }
    It says unexpected ">"

    If anyone can help I will be grateful! :)
  2. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    PHP:
    }elseif($online 25 and $online >= 20){
  3. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    That worked for a bit but now it says Undefined Variable: online
    Heres the code, any pointers / fixes / rookie mistakes??

    PHP:
    public function onRun($currentTick){
            foreach(
    $this->getOwner()->getServer()->getLevels() as $ln => $l){
                
    $tl $l->getTiles();
                foreach(
    $tl as $tli => $tile){
                    if(
    $tile instanceof Sign){
                       
                        
    $t $tile->getText();
                       
                        if(
    $t[0] == "[SG]"){
                           
                            
    $world $t[1];
                            
    $name $t[2];
                       
                            if(
    $this->getOwner()->getServer()->isLevelLoaded($world) == true){
                               
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                               
                                if(
    $online <= 20){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                                   
                                }elseif(
    $online == 0)
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                               
                                }elseif(
    $online 25 and $online >= 20){
                                    
    $tile->setText("[VIP]" $world $name $online "/24");
                               
                                }elseif(
    $online == 24){
                                    
    $tile->setText("[Full]" $world $name $online "/24");
                                }
                            }
                        }
                    }
                }
            }
  4. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    Yea, you have give "$online" again for your second check in that line. If its not there its checking nothing
  5. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Where about do I put it??
  6. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    I've done this...
    PHP:
    public function onRun($currentTick){
            foreach(
    $this->getOwner()->getServer()->getLevels() as $ln => $l){
                
    $tl $l->getTiles();
                foreach(
    $tl as $tli => $tile){
                    if(
    $tile instanceof Sign){
                       
                        
    $t $tile->getText();
                       
                        if(
    $t[0] == "[SG]"){
                           
                            
    $world $t[1];
                            
    $name $t[2];
                       
                            if(
    $this->getOwner()->getServer()->isLevelLoaded($world) == true){
                               
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                               
                                if(
    $online <= 20){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                                   
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                                   
                                }elseif(
    $online == 0)
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                               
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                               
                                }elseif(
    $online 25 and $online >= 20){
                                    
    $tile->setText("[VIP]" $world $name $online "/24");
                               
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                               
                                }elseif(
    $online == 24){
                                    
    $tile->setText("[Full]" $world $name $online "/24");
                                }
                            }
                        }
                    }
                }
            }
  7. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    What line is the error on?
  8. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    This line...
    PHP:
    }elseif($online 25 and $online >= 20){
  9. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    Don't sep are variables using commas! Use dots xD (The line where you set the text of the sign)
  10. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    The commas are for the multiline of the sign
    PEMapModder likes this.
  11. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    PHP:
    <?php
    public function onRun($currentTick){
            foreach(
    $this->getOwner()->getServer()->getLevels() as $ln => $l){
                
    $tl $l->getTiles();
                foreach(
    $tl as $tli => $tile){
                    if(
    $tile instanceof Sign){
                      
                        
    $t $tile->getText();
                      
                        if(
    $t[0] == "[SG]"){
                          
                            
    $world $t[1];
                            
    $name $t[2];
                      
                            if(
    $this->getOwner()->getServer()->isLevelLoaded($world) == true){
                              
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                              
                                if(
    $online <= 20){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                                  
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                                  
                                }elseif(
    $online == 0){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                              
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                              
                                }elseif(
    $online 25 and $online >= 20){
                                    
    $tile->setText("[VIP]" $world $name $online "/24");
                              
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                              
                                }elseif(
    $online == 24){
                                    
    $tile->setText("[Full]" $world $name $online "/24");
                                }
                            }
                        }
                    }
                }
            }
    Try that, it looks like you missed a curly bracket on one line.
    Calrizer likes this.
  12. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Great thanks! Thats working now! But it seems to not update the sign when a player leaves.
  13. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    How are you running it?
  14. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    I'm attempting to run it so it updates the signs constantly
  15. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    Can you send me both the task.php and main.php
  16. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Main:
    PHP:
    <?php

    namespace PlayerDetector;

    use 
    PlayerDetector\TimeUpdate;
    use 
    pocketmine\plugin\PluginBase;

    class 
    Main extends PluginBase{

        public function 
    onEnable(){
            
    $this->getServer()->getLogger()->info("PlayerDetector Is Now Enabled");
            
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new TimeUpdate($this), 20);
        }
       
        public function 
    onDisable(){
            
    $this->getServer()->getLogger()->info("PlayerDetector Is Now Disabled");
        }

    }
    TimeUpdate:
    PHP:
    <?php

    namespace PlayerDetector;

    use 
    pocketmine\level\Level;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\tile\Sign;

    class 
    TimeUpdate extends PluginTask{

        function 
    __construct($p){
            
    parent::__construct($p);
        }
       
        public function 
    onRun($currentTick){
            foreach(
    $this->getOwner()->getServer()->getLevels() as $ln => $l){
                
    $tl $l->getTiles();
                foreach(
    $tl as $tli => $tile){
                    if(
    $tile instanceof Sign){
                     
                        
    $t $tile->getText();
                     
                        if(
    $t[0] == "[SG]"){
                         
                            
    $world $t[1];
                            
    $name $t[2];
                     
                            if(
    $this->getOwner()->getServer()->isLevelLoaded($world) == true){
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                if(
    $online <= 20){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                                 
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                                 
                                }elseif(
    $online == 0){
                                    
    $tile->setText("[Join]" $world $name $online "/24");
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                }elseif(
    $online 25 and $online >= 20){
                                    
    $tile->setText("[VIP]" $world $name $online "/24");
                             
                                
    $online count($this->getOwner()->getServer()->getLevelByName($world)->getPlayers());
                             
                                }elseif(
    $online == 24){
                                    
    $tile->setText("[Full]" $world $name $online "/24");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Get a proper IDE to get rid of your syntax errors.
    PocketKiller and Angelo Vidrio like this.
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Only update them when someone quits/joins :)
    Angelo Vidrio likes this.
  19. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    Highly recommend this because if you update them every second it can get a bit slow, I think.
  20. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Can I have the code for that?? plz?

Share This Page

Advertisement