• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Random Player
#1
Exclamation 
Hi, how can i randomly select a player and have it run once per game?

i have a TDM server for rounds and i need it to run only once per game



This is my code:



Code:
new ran = random(GetPlayerPoolSize());

loop_start:

if(!IsPlayerConnected(ran))

{

? ? ran = random(GetPlayerPoolSize());

? ? goto loop_start;

}

printf("player found");

printf("%d",ran);

if(team[ran] == TEAM_GREEN)SpawnPlayer(ran);

GetPlayerPos(ran, xpo, ypo, zpo);



The problem is that it runs more than once, can you help me please?, thanks
  Reply
#2
Code:
stock GetRandomPlayer()
{
    new randomPlayer = INVALID_PLAYER_ID;
    do
    {
        randomPlayer = random(GetPlayerPoolSize()  1);
    }
    while (!IsPlayerConnected(randomPlayer));

    return randomPlayer;
}
and call GetRandomPlayer(); where you have to
  Reply
#3
Use foreach and Y_Iterate.



PHP Code:
new random_player Iter_Random(Player); 
  Reply
#4
It works! Thanks a lot
  Reply


Forum Jump: