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

How to get Players in Multiple worlds

Discussion in 'Development' started by Besher, Sep 7, 2020.

  1. Besher

    Besher Witch

    Messages:
    51
    How do i get how many players there are in Multiple worlds and add them so when i add it to a form it will show the player count of 2 worlds
     
  2. dadodasyra

    dadodasyra Witch

    Messages:
    68
    GitHub:
    dadodasyra
    $this->getServer()->getOnlinePlayers()
     
  3. Besher

    Besher Witch

    Messages:
    51
    yes but in worlds
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    level->getPlayers();
     
  5. Emirhan Akpınar

    Emirhan Akpınar Slime

    Messages:
    90
    PHP:
    $playerCount 0;
    $worlds = ["world1""world2"]; // Add which worlds will calculate
    foreach($worlds as $world){
      if(!
    Server::getInstance()->isLevelLoaded($world)){
        
    Server::getInstance()->loadLevel($world);
      }
      
    $level Server::getInstance()->getLevelByName($world);
      
    $playerCount += count($level->getPlayers());
    }

    // Do what do you want with $playerCount
     
    Besher likes this.
  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.