Random Player from Team - 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 Player from Team (
/showthread.php?tid=607172)
Random Player from Team -
XStreeter - 15.05.2016
Hello i want to create a Random System
I want to choose someone random from TEAM_HUMAN.
This team is Defined
I just want to se an variable from 0-1 (newteam = 1
Re: Random Player from Team -
XStreeter - 15.05.2016
AnyOne?
Re: Random Player from Team -
oMa37 - 15.05.2016
Didn't really understand what u want, But something like this?
PHP код:
stock RandomPlaya()
{
new random = Random(MAX_PLAYERS);
if(TEAM_HUMAN(random))
{
return random;
}
else
{
RandomPlaya();
}
}
and use it like this:
PHP код:
new randomplayer = RandomPlaya();
SetPlayerArmour(randomplayer, 100); // this is example
Re: Random Player from Team -
NaS - 15.05.2016
Quote:
Originally Posted by oMa37
Didn't really understand what u want, But something like this?
PHP код:
stock RandomPlaya()
{
new random = Random(MAX_PLAYERS);
if(TEAM_HUMAN(random))
{
return random;
}
else
{
RandomPlaya();
}
}
and use it like this:
PHP код:
new randomplayer = RandomPlaya();
SetPlayerArmour(randomplayer, 100); // this is example
|
You should add some checks to see if there even is someone in that team, else it will be an infinite loop.
Furthermore why get a random number from range 1000 if the highest connected human ID is for example 5?
It can theoretically take a very long time until a valid number is found. Practically this may never happen but still it's possible.
Re: Random Player from Team -
Nin9r - 16.05.2016
If you want to make a command to split all the players in 2 teams try it:
new Team1 = 0;
new Team2 = 0;
Код HTML:
if(Team1 < Team2)
{
SetPlayerPos(playerid,3521.2134,877.6339,-26.7354);
Team1 += 1;
}
else
{
SetPlayerPos(playerid,2321.21321,891.9823,-31.7539);
Team2+= 1;
}
Re: Random Player from Team -
Vince - 16.05.2016
Use foreach and create custom iterators for the teams. Then use Iter_Random. This is by far the most reliable way. A do-while loop might also work but it is not as efficient and there's a chance it may hang the server if no players are found.