22.03.2011, 20:29
Quote:
|
Mike_Garber, your function might be buggy. Why? For example you have 10 players in your server with id's 0, 1, 3, 5, 6, 9, 10, 12, 13, 14. Random function might pick Non existing ID, for example 4.
Foreach include has an function with what you can pick random player with no bugs( search for it ) |
my code can easily be rewritten to not pick an invalid ID.
pawn Код:
GetPlayersOnServer() {
new count;
for(new x=0; x< MAX_PLAYERS; x++) { //x = MAX_PLAYERS
if(IsPlayerConnected(x))) {
count++;
}
}
return count;
}
// Then do;
randomplayer()
{
new randomid = random(GetPlayersOnServer());
if(!IsPlayerConnected(randomid)){ return randomplayer(); }
return randomid;
}
//And now you can do a function like;
infectplayer(randomplayer);

