SA-MP Forums Archive
getrandom player function not working? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: getrandom player function not working? (/showthread.php?tid=201539)



getrandom player function not working? - The_Gangstas - 21.12.2010

pawn Код:
stock GetRandomPlayer()
{
    new ConnectedPlayers[MAX_PLAYERS];
    new idx;
    foreach(Player,i)
    {
        ConnectedPlayers[idx] = i;
        idx++;
    }
    if(idx == 0 || idx == 1) return INVALID_PLAYER_ID;
    else return ConnectedPlayers[random(idx)];
}
always returns invalid_player_id even though 5+ ppl are online?


Re: getrandom player function not working? - Seven. - 21.12.2010

pawn Код:
stock GetRandomPlayer()
{
    new yplayer[MAX_PLAYERS+1];
    for (new y = 0; y != MAX_PLAYERS; y ++) {
        if (IsPlayerConnected(y)) {
            yplayer[0] ++;
            yplayer[yplayer[0]] = y;
        }
    }
    return yplayer[random(yplayer[0])+1];
}



Re: getrandom player function not working? - The_Gangstas - 21.12.2010

if i use foreach, will it still work?


Re: getrandom player function not working? - Seven. - 21.12.2010

No idea, only one way to find out xD