random ?? help
#1

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

Use random function.

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

Thanks Hy rep
Reply
#4

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
Reply
#5

thank you Kaliber I will try
Reply
#6

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

thanks for the tip CalvinC
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)