Random Player from Team
#1

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
Reply
#2

AnyOne?
Reply
#3

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(randomplayer100); // this is example 
Reply
#4

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(randomplayer100); // 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.
Reply
#5

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;
					}
Reply
#6

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)