11.01.2011, 23:14
This GetRandomPlayerID function is from ******, so i assume it works.
You just have to add the global variable "gPlayersOnline" and increment/decrement it when players connect and disconnect.
Код:
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; }