Random Player
#1

How can i choose a random player?

I think of
Код:
random(MAX_PLAYERS)
or sth. like this...

Hope on your answer,
Trooper
Reply
#2

You have to create a loop and check if they are connected. By the way you're doing it right now it can select 155 for example, when there are only 20 people online.

The loop:
pawn Код:
for(new i=0;i<MAX_PLAYERS;i++)
{
//stuff here
}
Reply
#3

This is what i already know...
I mean, even if im making a loop for every player, how can i pick ONE Player ?!
Reply
#4

Quote:
Originally Posted by Trooper[Y
]
This is what i already know...
I mean, even if im making a loop for every player, how can i pick ONE Player ?!
pawn Код:
new RandPlayer = random(i);
break;
Reply
#5

pawn Код:
stock GetRandomID()
{
  new randn = random(MAX_PLAYERS);
   
  if(IsPlayerConnected(randn)) return randn;
   
  else
  {
     return GetRandomID();
  }
}
Example:
pawn Код:
public RandPlayer1()
{
  GivePlayerWeapon(GetRandomID(), 16, 5);
  SetPlayerArmour(GetRandomID(), 100);
  SendClientMessageToAll(COLOR_YELLOW, "[Random: A Random Player has been given ''5 Grenades'' and ''Full Armor'']");
  return 1;
}
Reply
#6

Thanks, found a solution =)

Happy to be here, English forum rules =D
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)