SA-MP Forums Archive
Random Player - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Random Player (/showthread.php?tid=75882)



Random Player - Trooper[Y] - 03.05.2009

How can i choose a random player?

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

Hope on your answer,
Trooper


Re: Random Player - HB - 03.05.2009

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
}



Re: Random Player - Trooper[Y] - 03.05.2009

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


Re: Random Player - HB - 03.05.2009

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;



Re: Random Player - Lewwy - 03.05.2009

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;
}



Re: Random Player - Trooper[Y] - 03.05.2009

Thanks, found a solution =)

Happy to be here, English forum rules =D