SA-MP Forums Archive
Get random player - 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: Get random player (/showthread.php?tid=318722)



Get random player - tal_peretz - 16.02.2012

How can I get random id of player that sustains this -

if(X[playerid] == 0 && playerid != LastIdChoose)

But not in the order [as in "for"]



Thanks


Re: Get random player - milanosie - 16.02.2012

Explain a lil more


Re: Get random player - Chris White - 16.02.2012

uh, I didn't get what you want. Please explain more.


Re: Get random player - tal_peretz - 16.02.2012

I need random id of player ... that his variable is == 0 and changed than the last id I got ...

I thought to use for, but I want it not in order [0,1,2,3], How can I make it ?


Re: Get random player - Ash. - 16.02.2012

You could create a function, or use Iter_Random (I think It's that) in ******' foreach, if you're using foreach, that is.

Here is a function that will get you a random, connected, player - though it could be done much better!

pawn Code:
stock RandomPlayer()
{
     new iPlayer = random(GetMaxPlayers());
     while(!IsPlayerConnected(iPlayer)) iPlayer = random(GetMaxPlayers());
     return iPlayer;
}