Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public OnGameModeInit()
- {
- new
- t,
- pid;
- t = GetTickCount();
- for (new i; i < 1000000; ++i)
- {
- pid = GetRandomPlayer();
- }
- printf("mine %i", GetTickCount() - t);
- t = GetTickCount();
- for (new i; i < 1000000; ++i)
- {
- pid = RandomPlayerID();
- }
- printf("thine %i", GetTickCount() - t);
- return 1;
- }
- GetRandomPlayer()
- {
- new
- pmax,
- rand;
- for (new i; i < MAX_PLAYERS; ++i) if (IsPlayerConnected(i)) ++pmax;
- while (pmax > 0)
- {
- rand = random(pmax);
- if (IsPlayerConnected(rand)) return rand;
- }
- return INVALID_PLAYER_ID;
- }
- RandomPlayerID()
- {
- new
- it[2],
- pIDs[MAX_PLAYERS];
- for(it[0] = 0, it[1] = 0; it[0] < MAX_PLAYERS; ++it[0])
- {
- if(IsPlayerConnected(it[0]) && !IsPlayerNPC(it[0]))
- {
- pIDs[it[1]++] = it[0];
- }
- }
- return (it[1]) ? (pIDs[random(it[1])]) : (INVALID_PLAYER_ID);
- }
Advertisement
Add Comment
Please, Sign In to add comment