pick a random guy?
#5

This GetRandomPlayerID function is from ******, so i assume it works.

Код:
stock GetPlayerRandomID()
{
    // Check if there are actually any players
    if (!gPlayersOnline)
    {
        // No, return appropriately
        return INVALID_PLAYER_ID;
    }
    // Select which of the connected players to return
    new
        id = random(gPlayersOnline);
    // Find the player
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        // Loop through all players and only update if they're connected
        if (IsPlayerConnected(i))
        {
            if (id == 0)
            {
                // No players left to loop through
                // Return this ID
                return i;
            }
            // Not found the player we want yet, move on to the next
            id = id - 1;
            // While id is not 0 then we have id number of connected players left to skip
        }
    }
    // Shouldn't get here but needed by the compiler
    return INVALID_PLAYER_ID;
}
You just have to add the global variable "gPlayersOnline" and increment/decrement it when players connect and disconnect.
Reply


Messages In This Thread
pick a random guy? - by MrIncredible - 11.01.2011, 22:48
Re: pick a random guy? - by Kitten - 11.01.2011, 23:00
Re: pick a random guy? - by MrIncredible - 11.01.2011, 23:04
AW: pick a random guy? - by Extremo - 11.01.2011, 23:07
Re: pick a random guy? - by Kyosaur - 11.01.2011, 23:14
Re: pick a random guy? - by Joe Staff - 11.01.2011, 23:22

Forum Jump:


Users browsing this thread: 1 Guest(s)