gamer931215

GetRandomPlayerId

Jul 18th, 2011
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 0.41 KB | None | 0 0
  1. stock GetRandomPlayerId() //returns -1 when there are no players connected
  2. {
  3.     new anybodyhere = 0;
  4.     new counter = 0;
  5.     new ids[MAX_PLAYERS];
  6.     for(new i = 0;i<MAX_PLAYERS;i++)
  7.     {
  8.         if(IsPlayerConnected(i))
  9.         {
  10.             ids[counter] = i;
  11.             anybodyhere = 1;
  12.             i++;
  13.         }
  14.     }
  15.     new rnd = random(sizeof(ids));
  16.     if(anybodyhere == 0)
  17.     {
  18.         return -1;
  19.     } else {
  20.         return ids[rnd];
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment