Random Player
#3

Here's my version. Returns a random player or INVALID_PLAYER_ID if no players are connected. Also its worth noting that foreach has an inbuilt random player function if you already use that library.

pawn Code:
GetRandomPlayer()
{
    new
        pCount,
        rPlayers[MAX_PLAYERS] = {INVALID_PLAYER_ID, ...};
       
    for(new playerid; playerid < MAX_PLAYERS; playerid++)
    {
        if(IsPlayerConnected(playerid))
        {
            rPlayers[pCount] = playerid;
            pCount++;
        }
    }
    if(pCount)
        return rPlayers[random(pCount)];
    else
        return INVALID_PLAYER_ID;
}
Reply


Messages In This Thread
Random Player - by geerdinho8 - 14.07.2011, 19:24
Re: Random Player - by Ricop522 - 14.07.2011, 19:33
Re: Random Player - by iggy1 - 14.07.2011, 19:45
Re: Random Player - by Shadoww5 - 14.07.2011, 20:31
Re: Random Player - by geerdinho8 - 17.07.2011, 02:30
Re: Random Player - by =WoR=Varth - 17.07.2011, 02:46
Re: Random Player - by CyNiC - 17.07.2011, 02:50
Re: Random Player - by geerdinho8 - 17.07.2011, 03:11
Re: Random Player - by =WoR=Varth - 17.07.2011, 03:14
Re: Random Player - by geerdinho8 - 17.07.2011, 03:17

Forum Jump:


Users browsing this thread: 2 Guest(s)