Get online players ID
#5

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
You can also do it with plain pawn functions.

You can create an array with the size of MAX_PLAYERS.
Then loop through all players and check if it's connected.
In case that ID is connected, add it to the array and count the connected players.
The you can get a random player from that array, using the count as random value.

pawn Код:
GetRandomConnectedPlayer()
{
    // Setup local variables
    new PlayerList[MAX_PLAYERS], Count;

    // Loop through all players
    for (new i; i < MAX_PLAYERS; i++)
    {
        // If this player is connected
        if (IsPlayerConnected(i))
        {
            // Add him to the player-list and increase the count
            PlayerList[Count] = i;
            Count++;
        }
    }

    // Select a random player from the connected players stored in the list and return it
    return PlayerList[random(Count)];
}
Usage:
pawn Код:
RandomPlayer = GetRandomConnectedPlayer();
This is the best way, i guess.. I did quite the same thing today with a script for my server ahahha
Reply


Messages In This Thread
Get online players ID - by awoo - 04.03.2015, 16:21
Re: Get online players ID - by KayJ - 04.03.2015, 16:24
Re: Get online players ID - by CalvinC - 04.03.2015, 16:26
Re: Get online players ID - by PowerPC603 - 04.03.2015, 19:55
Re: Get online players ID - by ReshiramZekrom - 04.03.2015, 22:20

Forum Jump:


Users browsing this thread: 1 Guest(s)