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



random ?? help - Clarck - 08.03.2015

creating to choose a random number...
example: / job
choose random an id on the server to go hitman to kill him
??


Re: random ?? help - HY - 08.03.2015

Use random function.

pawn Код:
new id;
id = random(MAX_PLAYERS);
if(IsPlayerConnected(id))
{
    // Code.
}



Re: random ?? help - Clarck - 09.03.2015

Thanks Hy rep


AW: Re: random ?? help - Kaliber - 09.03.2015

Quote:
Originally Posted by Clarck
Посмотреть сообщение
Thanks Hy rep
The Code he posted will not work

Use this:

Код:
stock GetRandomOnlineID() {
    new tmp[MAX_PLAYERS],idx;
    for(new i; i<MAX_PLAYERS; i++) if(IsPlayerConnected(i)) tmp[idx]=i,idx++;
    return tmp[random(idx)];
}

new id = GetRandomOnlineID(); //now you have a random id
Greekz


Re: random ?? help - Clarck - 09.03.2015

thank you Kaliber I will try


Re: random ?? help - CalvinC - 09.03.2015

If you want to get the ID of a random online player, you can just use Iter_Random in foreach.


Re: random ?? help - Clarck - 09.03.2015

thanks for the tip CalvinC