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

Get a random username

Comments in 'Plugin Development' started by YoDevil, Jun 28, 2014.

  1. YoDevil
    Offline

    YoDevil New Member

    Joined:
    May 12, 2014
    Posts:
    10
    Minecraft User:
    YoDevil
    I don't understand whats wrong with my code (old API)!
    PHP:
    $pList $this->api->player->getAll();
    $rNumPlayer rand(0count($pList) - 1);
    $rPlayer $pList[$rNumPlayer];
    $rPlayerName $rPlayer->username;
    When broadcasting a message using that $rPlayerName nothing appears!
  2. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    Use foreach(?) i'm not sure
  3. YoDevil
    Offline

    YoDevil New Member

    Joined:
    May 12, 2014
    Posts:
    10
    Minecraft User:
    YoDevil
    How would I make that with a foreach?
  4. PluginMastered
    Offline

    PluginMastered Active Member

    Joined:
    Mar 1, 2014
    Posts:
    161
    Minecraft User:
    Flexa33
    is rPlayerName a variable
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You are not using Java. $pList is ordered by client IDs ($ip . ":" . $port), not with increasing integers. Therefore, your randomly generated integer is not an existent offset in $pList.

    Use array_rand().

Share This Page

Advertisement