Advertisement
Guest User

LMS random player.

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