getrandom player function not working?
#1

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?
Reply
#2

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];
}
Reply
#3

if i use foreach, will it still work?
Reply
#4

No idea, only one way to find out xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)