Random choose - 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)
+--- Thread: Random choose (
/showthread.php?tid=378410)
Random choose -
SumX - 17.09.2012
Hello.How can I choose a random player using "foreach" and give him 5000$,for example?
I found some threads where ****** replyed,but I didn't understand perfectly.
Thank you!
Re: Random choose -
XtremeR - 17.09.2012
well here you go
pawn Код:
stock SelectRandomPlayer()
{
new random = Random(MAX_PLAYERS);
if(IsPlayerConnected(random))
{
return random;
}
else
{
SelectRandomPlayer();
}
}
Now you can use it for example like this:
pawn Код:
new randomplayer = SelectRandomPlayer();
GivePlayerMoney(randomplayer, 5000);
+rep if that helps
Re: Random choose -
detter - 17.09.2012
you can use this as a cmd...
Код:
new onlinePlayers ,winner;
for(new i = 0; i < MAX_PLAYERS ; i++)
{
if(IsPlayerConnected(i) ) onlinePlayers++;
}
winner = random(onlinePlayers);
GivePlayerMoney(winner ,5000);
SendClinetMessage(winner ,COLOR_GREEN ,"Congrats ,you won 5000$ on a random draw!");
Re: Random choose -
DeathTone - 17.09.2012
You can choose a random Iter from foreach, using:
will return a random id of the list of connected players.
Re: Random choose -
SumX - 17.09.2012
Quote:
Originally Posted by DeathTone
You can choose a random Iter from foreach, using:
will return a random id of the list of connected players.
|
so ...I have this command:randomgivemoney
PHP код:
#include <a_samp>
#include <ZCMD>
#include <foreach>
CMD:randomgivemoney(playerid,params[])
{
Iter_Random(Player);
GivePlayerMoney(Player,5000);
return 1;
}
It's this right?
EDIT:The other 2 guys, I said clearly: I am using Foreach.Simple loops is looping through offline players.
Re: Random choose -
DeathTone - 17.09.2012
Quote:
Originally Posted by SumX
so ...I have this command:randomgivemoney
PHP код:
#include <a_samp>
#include <ZCMD>
#include <foreach>
CMD:randomgivemoney
{
Iter_Random(Player);
GivePlayerMoney(Player,5000);
return 1;
}
It's this right?
|
Actually, this is correct:
PHP код:
CMD:randomgivemoney
{
new randomplayer;
randomplayer = Iter_Random(Player);
GivePlayerMoney(randomplayer,5000);
return 1;
}
Re: Random choose -
SumX - 17.09.2012
Quote:
Originally Posted by DeathTone
Actually, this is correct:
PHP код:
CMD:randomgivemoney(playerid,params[])
{
new randomplayer;
randomplayer = Iter_Random(Player);
GivePlayerMoney(randomplayer,5000);
return 1;
}
|
Thank you very much!