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

Getting online players

Discussion in 'Development' started by DroidPlaysMC, Oct 19, 2017.

Thread Status:
Not open for further replies.
  1. DroidPlaysMC

    DroidPlaysMC Creeper

    Messages:
    3
    I'm trying to get online players to the current server using UI. My current code only shows 0 when there players online.

    PHP:
    $button = new Button(TextFormat::GREEN "Factions" "\n" TextFormat::GREEN count(Server::getInstance()->getOnlinePlayers()));
           
    $ui->addButton($button);
     
    Last edited: Oct 19, 2017
  2. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    PHP:
    $playersOnline count($this->getServer()->getOnlinePlayers());
    $maxOnline $this->getServer()->getMaxPlayers();

    $button = new Button(TextFormat::GREEN "Factions" "\n" TextFormat::GREEN $playersOnline "/" $maxOnline );
    If you want to refresh player Count, use the Task
    PHP:
    public function onEnable(){
            
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new TTask($this), 4); //refresh every 5ticks
        
    }


    class 
    TTask extends PluginTask{

        public function 
    onRun(int $currentTick){
            
    $this->getOwner()->reloadUIs(); //reloadUIs or Function name
    //reloadUIs if you use CustomUI by XenialDan
        
    }
    }
     
    Last edited: Oct 20, 2017
  3. DroidPlaysMC

    DroidPlaysMC Creeper

    Messages:
    3
    Thank you it works now. What about getting online players from another server?
     
  4. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    Then you need to use query.
     
  5. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    armagadon159753 likes this.
  6. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    jasonwynn10 likes this.
Thread Status:
Not open for further replies.
  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.