SA-MP Forums Archive
How to get random player - 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)
+--- Thread: How to get random player (/showthread.php?tid=475816)



How to get random player - Fitri - 15.11.2013

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


Re: How to get random player - Tuntun - 15.11.2013

What? -_-


Re: How to get random player - newbie scripter - 15.11.2013

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


Re: How to get random player - Emmet_ - 15.11.2013

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;
}



Re: How to get random player - Fitri - 15.11.2013

Thanks !