Guest User

Untitled

a guest
Oct 5th, 2010
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. public OnGameModeInit()
  2. {
  3. new
  4. t,
  5. pid;
  6. t = GetTickCount();
  7. for (new i; i < 1000000; ++i)
  8. {
  9. pid = GetRandomPlayer();
  10. }
  11. printf("mine %i", GetTickCount() - t);
  12. t = GetTickCount();
  13. for (new i; i < 1000000; ++i)
  14. {
  15. pid = RandomPlayerID();
  16. }
  17. printf("thine %i", GetTickCount() - t);
  18. return 1;
  19. }
  20.  
  21. GetRandomPlayer()
  22. {
  23. new
  24. pmax,
  25. rand;
  26. for (new i; i < MAX_PLAYERS; ++i) if (IsPlayerConnected(i)) ++pmax;
  27. while (pmax > 0)
  28. {
  29. rand = random(pmax);
  30. if (IsPlayerConnected(rand)) return rand;
  31. }
  32. return INVALID_PLAYER_ID;
  33. }
  34.  
  35. RandomPlayerID()
  36. {
  37. new
  38. it[2],
  39. pIDs[MAX_PLAYERS];
  40. for(it[0] = 0, it[1] = 0; it[0] < MAX_PLAYERS; ++it[0])
  41. {
  42. if(IsPlayerConnected(it[0]) && !IsPlayerNPC(it[0]))
  43. {
  44. pIDs[it[1]++] = it[0];
  45. }
  46. }
  47. return (it[1]) ? (pIDs[random(it[1])]) : (INVALID_PLAYER_ID);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment