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

Count online players

Comments in 'Plugin Development' started by deot, Oct 1, 2015.

  1. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    Hi, is there're anyway to get number of online players?

    I'm using this code:
    PHP:
    count($this->getServer()->getOnlinePlayers())
    Is this code correct and able to get number of online players?
    Because there's people saying count() is only for array thingy.... So, I have doubt on it...
  2. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Yeah array thingy. $this->getServer()->getOnlinePlayers() returns an array of players.
  3. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    So, in the end of the day, is this code can get NUMBER of online players?
    Legoboy0215 likes this.
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Yep.
  5. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    It exists, read the API
    Legoboy0215 likes this.
  6. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    @PEMapModder said it, check out the topic, Mechanics in Plugin Development


    Sorry if I am wrong :p I am still learning
    Last edited: Oct 1, 2015
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Don't try to be a smart-a**. $this->getServer()->getOnlinePlayers() exist, but not $level->getOnlinePlayers().
    #ReadTheDocs.
    PEMapModder likes this.
  8. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    sorry, but you don't have to be so rude about this...
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If you don't understand, please do not post. Every post you make will be kept on the forums and last forever, and people who read it in the future will be misled.
  10. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    I will delete it :)
  11. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I am not so rude normally ;)
    Just want you to read da docs as @Intyre's signature says.
  12. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    in case anyone else was wondering, the correct way to get the players in a level is $level->getPlayers();

Share This Page

Advertisement