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

How to get online players on a map

Comments in 'Plugin Development' started by AndrewBit, Oct 17, 2015.

  1. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    I'm usign in a plugin:
    PHP:
    $onp count($this->getServer()->getLevelByName($map)->getPlayers());
    But when I start the plugin I get a error :'D
    Code:
    Fatal error: Call to a member function getPlayers() on null in /home/andrewbit4/Escritorio/PocketMine/plugins/PvP source/src/andrewbit4/PvP/Main.php on line 178
    
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    LEVEL NOT LOADED
    PHP:
    if(!$this->getServer()->isLevelLoaded(/*LevelName*/)){
    $this->getServer()->loadLevel(/*LevelName*/);
    }
  3. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Idk what's my error, but I'm pretty that the level is loaded...
  4. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Then your level doesn't exist or you're using the wrong name.
  5. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    what does $map equal?
  6. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    'arena'
  7. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Just to check.
    PHP:
    $map $this->getServer()->getLevelByName('world_main');
    if(
    $map instanceof \pocketmine\level\Level){
       
    $playersCount count($map->getPlayers());
    }
    PEMapModder likes this.
  8. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Are you sure that's the level name? Level name !== level folder

Share This Page

Advertisement