How to get Players in Multiple worlds

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

  1. Besher

    Besher Silverfish

    Messages:
    21
    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:
    58
    GitHub:
    dadodasyra
    $this->getServer()->getOnlinePlayers()
     
  3. Besher

    Besher Silverfish

    Messages:
    21
    yes but in worlds
     
  4. Levi

    Levi Skeleton

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

    Emirhan Akpınar Slime

    Messages:
    90
    GitHub:
    EmirhanWSD
    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.

Share This Page

  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.