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

Count of players

Discussion in 'Development' started by SergeyIvanov, Jul 17, 2017.

  1. SergeyIvanov

    SergeyIvanov Witch

    Messages:
    59
    GitHub:
    sergeyivanov14
    How to get the coun of players in worlds world1, world2 and world3?
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Use Server::getLevelByName("world") to get the Level instance, then use count(Level::getPlayers()) to get the number of players.
    PHP:
    /** @var Server $server */
    $levels = [];
    foreach([
    "world1""world2"] as $worldname){
        
    $levels[] = $server->getLevelByName($worldname);
    }
    $count 0;
    foreach(
    $levels as $level){
        
    $count += count($level->getPlayers());
    }
    echo 
    $count;
    Make sure the levels exist and are loaded.
     
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    getLevelByName() function is not static ( ͡° ͜ʖ ͡° )
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
  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.