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