How to get random player
#1

Hi, I wanna Know How To Get 1 Player (random) Of All Player Connected
Reply
#2

What? -_-
Reply
#3

pawn Код:
new rand = random(sizeof(MAX_PLAYERS)) + 1;
May or May not work
Reply
#4

You can do it with foreach or y_iterate:

pawn Код:
new randomid = Iter_Random(Player);
Or else, you'll have to use this function:

pawn Код:
stock getRandomPlayer()
{
    new
        count = 0,
        randomid = INVALID_PLAYER_ID
    ;
    while (randomid == INVALID_PLAYER_ID || !IsPlayerConnected(randomid))
    {
        count++;
        randomid = random(MAX_PLAYERS);
        if (count > 200 || IsPlayerConnected(randomid)) break;
    }
    return randomid;
}
Reply
#5

Thanks !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)