Picking a 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: Picking a random player? (
/showthread.php?tid=142650)
Picking a random player? -
0ne - 19.04.2010
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?
Re: Picking a random player? -
Norck - 19.04.2010
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
}
Re: Picking a random player? -
0ne - 19.04.2010
Ty
Re: Picking a random player? -
Kyosaur - 19.04.2010
Nvm.