SA-MP Forums Archive
Bonus - 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: Bonus (/showthread.php?tid=454440)



Bonus - Ananisiki - 28.07.2013

^^^^^^^^


Re: Bonus - jamesbond007 - 28.07.2013

pawn Код:
stock SelectRandomPlayer()
{
    new Prandom = random(MAX_PLAYERS);
    if(IsPlayerConnected(Prandom))
    {
       return Prandom;
    }
    else
    {
       return SelectRandomPlayer();
    }
}



Re: Bonus - MP2 - 28.07.2013

Use Iter_Random in foreach. Also, that code could still return a non-connected player ID.


Re: Bonus - jamesbond007 - 29.07.2013

Quote:
Originally Posted by MP2
Посмотреть сообщение
Also, that code could still return a non-connected player ID.
how..?


Re: Bonus - MP2 - 29.07.2013

Okay I failed and didn't see the recursion. But still, you should use Iter_Random in foreach(). Also, a while() loop would be better than recursion.


Re: Bonus - jamesbond007 - 29.07.2013

Quote:

They aren't connected either, but i'll still return the ID..

wtf? wrong.. it will keep looping until it finds connected... possibly going infinite if server is empty..
why would it stop there.. lol


Re: Bonus - MP2 - 29.07.2013

Re-read please - I fucked up :P