open.mp forum
[Pawn] Random Player - Printable Version

+- open.mp forum (https://forum.open.mp)
+-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
+--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
+--- Thread: [Pawn] Random Player (/showthread.php?tid=1704)



Random Player - Lord_Bukake - 2021-02-23

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


RE: Random Player - destiezk - 2021-02-23

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


RE: Random Player - Radical - 2021-02-23

Use foreach and Y_Iterate.



PHP Code:
new random_player = Iter_Random(Player);



RE: Random Player - Lord_Bukake - 2021-02-24

It works! Thanks a lot