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

$this->api->player->getAll(); not working??

Comments in 'Plugin Development' started by Mac_MC, Apr 18, 2014.

  1. Mac_MC
    Offline

    Mac_MC Banned

    Joined:
    Mar 9, 2014
    Posts:
    10
    Minecraft User:
    Mac_DRK
    Hey better coders, why thats not working?
    $test = $this->api->player->getAll("world");
    $this->api->chat->broadcast("$test");
    ????

    Your Mac
  2. InusualZ
    Offline

    InusualZ Active Member Plugin Developer

    Joined:
    Aug 23, 2013
    Posts:
    218
    Plugins:
    1
    Minecraft User:
    Inusu4lZ
    Because the variable $test is a array.
  3. Mac_MC
    Offline

    Mac_MC Banned

    Joined:
    Mar 9, 2014
    Posts:
    10
    Minecraft User:
    Mac_DRK
    so how i can print it now out?
  4. InusualZ
    Offline

    InusualZ Active Member Plugin Developer

    Joined:
    Aug 23, 2013
    Posts:
    218
    Plugins:
    1
    Minecraft User:
    Inusu4lZ
  5. Topic
    Offline

    Topic New Member Plugin Developer

    Joined:
    Aug 29, 2013
    Posts:
    47
    Plugins:
    3
    Minecraft User:
    topic
    If you want to count players from some world, you can user this:
    PHP:
    $players count($this->api->player->getAll($this->api->level->get("world")));
    $this->api->broadcast($players);
    But if you want to get Players names, so getAll() it's array with nick names, so you can try this:
    PHP:
    $players $this->api->player->getAll($this->api->level->get("world"));
    foreach(
    $players as $p)
    {
    $this->api->chat->broadcast($p);
    }
    No tested.
  6. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Can you
    You sure the array isnt the player objects?
  7. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    Yeah he's got it wrong. You use $p->username. Why does nobody around here understand objects?
  8. Topic
    Offline

    Topic New Member Plugin Developer

    Joined:
    Aug 29, 2013
    Posts:
    47
    Plugins:
    3
    Minecraft User:
    topic
    $this->api->player->getAll(); it's array
  9. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    Yes, it's an array of player OBJECTS.
  10. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    should be
    PHP:
    $players $this->api->player->getAll($this->api->level->get("world"));
    foreach(
    $players as $p){
       
    $this->api->chat->broadcast($p->username);//$p->username as the function returns a array of objects, not strings
    }

Share This Page

Advertisement