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

Online User Array

Comments in 'Plugin Development' started by Falk, Oct 30, 2013.

Thread Status:
Not open for further replies.
  1. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    How can I obtain an array of users that are online at a current time?
  2. Blue Electric
    Offline

    Blue Electric New Member

    Joined:
    Oct 27, 2013
    Posts:
    27
    Minecraft User:
    BE__
    PHP:
    $online $this->api->player->online();

    foreach(
    $online as $name)
    {
        
    $player $this->api->player->get($name);
    //Put Your Code in Here
    }
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    So $online is an array of $player->username and $this->api->player->get($name) returns the id/whatever of the player which you use to do ->teleport() etc.?
  4. Blue Electric
    Offline

    Blue Electric New Member

    Joined:
    Oct 27, 2013
    Posts:
    27
    Minecraft User:
    BE__
    yes, you can use $player->teleport( Position );
  5. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    So is $name the username? Or is it something else?
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $name is declared in each foreach.
    PHP:
    foreach($online as $name){
      
    //your code
    can be translated into:
    PHP:
    for($i=0;$i<sizeof($online);$i++){
      
    $name=$online[i];
      
    //your code
    And if you want a players list array, you can use:
    PHP:
    $online=$this->api->player->online();
    $playersOnline=array();
    foreach(
    $online as $name){
      
    $playersOnline[sizeof($playersOnline)]=$this->api->player->get($name);//maybe I can omit sizeof($playersOnline)?
    }
    //do whatever you want to do with an array of online players $playersOnline and an array of their IGNs $online.
  7. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Okay great!
  8. Syriamanal
    Offline

    Syriamanal Ban Evader Banned

    Joined:
    Oct 2, 2013
    Posts:
    221
    Minecraft User:
    Syriamanal
    Or u can do this $player
  9. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    What do you mean?
  10. Syriamanal
    Offline

    Syriamanal Ban Evader Banned

    Joined:
    Oct 2, 2013
    Posts:
    221
    Minecraft User:
    Syriamanal
    Insted of $name u can do $username
  11. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    easiest:
    PHP:
    $players $this->api->player->getAll();
    This will return an array with all the player objects of the online players.
    Last edited: Nov 11, 2013
    Falk and Glitchmaster_PE like this.
  12. Glitchmaster_PE
    Offline

    Glitchmaster_PE Notable Member Plugin Developer

    Joined:
    Aug 31, 2013
    Posts:
    834
    Plugins:
    8
    Minecraft User:
    Glitchmaster_PE
    That is the one I was thinking of, but everyone was else was doing big chunks of code so I thought I had understood wrong :p
    PEMapModder and Syriamanal like this.
  13. Syriamanal
    Offline

    Syriamanal Ban Evader Banned

    Joined:
    Oct 2, 2013
    Posts:
    221
    Minecraft User:
    Syriamanal
    Lol
  14. Glitchmaster_PE
    Offline

    Glitchmaster_PE Notable Member Plugin Developer

    Joined:
    Aug 31, 2013
    Posts:
    834
    Plugins:
    8
    Minecraft User:
    Glitchmaster_PE
    19 more likes till 100 :p :D
    PEMapModder, Syriamanal and Falk like this.
  15. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    18 now!
  16. Syriamanal
    Offline

    Syriamanal Ban Evader Banned

    Joined:
    Oct 2, 2013
    Posts:
    221
    Minecraft User:
    Syriamanal
    Gave u one more like me to
    PEMapModder likes this.
  17. Glitchmaster_PE
    Offline

    Glitchmaster_PE Notable Member Plugin Developer

    Joined:
    Aug 31, 2013
    Posts:
    834
    Plugins:
    8
    Minecraft User:
    Glitchmaster_PE
    Oh no, don't spam me :p
    PEMapModder likes this.
  18. Glitchmaster_PE
    Offline

    Glitchmaster_PE Notable Member Plugin Developer

    Joined:
    Aug 31, 2013
    Posts:
    834
    Plugins:
    8
    Minecraft User:
    Glitchmaster_PE
    I need to earn them :D
    PEMapModder likes this.
  19. Glitchmaster_PE
    Offline

    Glitchmaster_PE Notable Member Plugin Developer

    Joined:
    Aug 31, 2013
    Posts:
    834
    Plugins:
    8
    Minecraft User:
    Glitchmaster_PE
    Hey I just released KitPro 4.0, you can now have unlimited kits and completely customizable!
    Falk likes this.
  20. Syriamanal
    Offline

    Syriamanal Ban Evader Banned

    Joined:
    Oct 2, 2013
    Posts:
    221
    Minecraft User:
    Syriamanal
    Sick
Thread Status:
Not open for further replies.

Share This Page

Advertisement