getting a random player
#6

Here:
pawn Код:
stock RandomPlayerID()
{
    new
       pIDs[MAX_PLAYERS],
       it[2];
       
    for(it[0] = 0, it[1] = 0; it[0] < MAX_PLAYERS; ++it[0])
        if(IsPlayerConnected(it[0]) && !IsPlayerNPC(it[0]))
        {
            pIDs[it[1]] = it[0];
            it[1]++;
        }
       
    return (it[1] != 0) ? (pIDs[random(it[1])]) : (INVALID_PLAYER_ID);
}
As gamer_z said, the loops would take awhile. Even if there was a 200 max player limit, and 1 player was connected with the ID of 79, random might not return 79 for quite some time. With the above code there's not a need to worry about that problem.
Reply


Messages In This Thread
getting a random player - by thomas.. - 05.10.2010, 21:19
Re: getting a random player - by Scenario - 05.10.2010, 21:31
Re: getting a random player - by Gamer_Z - 05.10.2010, 21:37
Re: getting a random player - by bigcomfycouch - 05.10.2010, 21:39
Re: getting a random player - by Gamer_Z - 05.10.2010, 21:41
Re: getting a random player - by Tannz0rz - 05.10.2010, 21:49
Re: getting a random player - by bigcomfycouch - 05.10.2010, 22:03
Re: getting a random player - by Tannz0rz - 05.10.2010, 22:08
Re: getting a random player - by bigcomfycouch - 05.10.2010, 22:20
Re: getting a random player - by Tannz0rz - 05.10.2010, 22:23

Forum Jump:


Users browsing this thread: 1 Guest(s)