2 Players in Iter_Random - 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: 2 Players in Iter_Random (
/showthread.php?tid=624246)
2 Players in Iter_Random -
JaKe Elite - 13.12.2016
How do I choose 2 players in Iter_Random?
Re: 2 Players in Iter_Random -
X337 - 13.12.2016
You can't, but you can make your own custom function to do that by comparing the first random player with the second one.
Re: 2 Players in Iter_Random -
JaKe Elite - 13.12.2016
Can you give me an example on how to do it? And yeah I know Iter_Random can't do that, My English sucks it should've been "How do I choose 2 players instead of one with the Iter_Random function"
Re: 2 Players in Iter_Random -
Konstantinos - 13.12.2016
pawn Код:
TwoRandomPlayers(&player1, &player2)
{
if (Iter_Count(Player) > 1)
{
player1 = Iter_Random(Player);
do
{
player2 = Iter_Random(Player);
}
while (player1 == player2);
return 1;
}
return 0;
}
Re: 2 Players in Iter_Random -
JaKe Elite - 13.12.2016
Will try it out, I appreciated all the helps I been getting from you @Konstantinos
Re: 2 Players in Iter_Random -
Gammix - 13.12.2016
PHP код:
GetRandomPlayer()
{
static Iterator:StaticList<MAX_PLAYERS>;
if (Iter_Size(StaticList) == 0)
{
foreach (new i : Player)
Iter_Add(i);
}
new ret = Iter_Random(StaticList);
Iter_Remove(StaticList, ret);
return ret;
}
If you are using the function for a significant amount of players at once (more than 2 or 5) plus this works for N number of players, N being number of connected players.