Picking a random player?
#1

Ok i got a timer on gamemodeinit , and could anyone tell me how to pick a random player, i mean absolutely random like i got a timer of 5mins in gamemodeinit, and i want to pick a random player to give him money, if there is no players in server it wouldn't do anything just repeat the timer?
Reply
#2

Put this in your timer:
pawn Код:
new maxid = -1;
for(new i = 0; i < GetMaxPlayers(); i++)
{
  if(IsPlayerConnected(i))
  maxid = i;
}
if(maxid != -1)//If someone is connected
{
  new happywinner = random(maxid+1);
  while(!IsPlayerConnected(happywinner))  
  {
    happywinner = random(maxid+1);
  }
  GivePlayerMoney(happywinner,100);//Will give this lucky $100
}
Reply
#3

Ty
Reply
#4

Nvm.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)