random connected id
#1

hey,
how i can select a random id that connect in the server?
maybe:

pawn Код:
for(new i; i<MAX_PLAYERS; i++)
{
  if(IsPlayerConnected(i))
  {
  ...
  }
}
but more i dont know.
Reply
#2

pawn Код:
RANDOM_CODE:
new
    randomPlayer;
randomPlayer = random(MAX_PLAYERS);
if(IsPlayerConnected(randomPlayer))
{
  // connected.
}
else
{
  goto RANDOM_CODE;
}
Reply
#3

Quote:
Originally Posted by Don Correlli
pawn Код:
new
    randomPlayer;
randomPlayer = random(MAX_PLAYERS);
if(IsPlayerConnected(randomPlayer))
{
  // connected.
}
else
{
  // not connected.
}
That unfortunately won't work very well..
It would return "Not connected" too often, and it would be quite inefficient in a loop
Reply
#4

Depends where you want to use it.
Reply
#5

Start using foreach.

pawn Код:
new randomplayer = Itter_Random(Player);
Reply
#6

i like to use it in a mission.
example: i type /mission and than comes: go an kill id 5.
and 10 players are connectet, therefore don't select id 20 or so.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)