Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function random_player_from_lms()
- {
- // Don't do anything if there's no player connected
- if (GetPlayers() <= 0) return null;
- // Use an array to gather all candidates
- local players = [];
- // NOTE: Use reversed loop to avoid calling GetMaxPlayers() on each iteration
- for (local id = GetMaxPlayers()-1; id >= 0; id--) {
- // Get the player instance associated with the current ID
- local i_player = FindPlayer(id);
- // See if the player is a possible candidate and store it's ID
- if (i_player != null && pArena[ i_player.ID ].LMS) players.push(i_player.ID);
- }
- // Feed the random generator seed. Use GetTickCount() to increase the randomness.
- srand(GetTickCount());
- // Return a random player from the possible candidates
- return FindPlayer(players[rand() % players.len()]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement