help/pick a random player
#1

hi guys..

i'm asking about how to pick a random player from the server!

like i have a president class and police and ......
and when the president dies,i want to set a random player as the president(president Class)!

anybody knows how?!

Thx alot guys...
Reply
#2

how?!?!?
Reply
#3

With foreach:
pawn Код:
Iter_Random(Player);
Reply
#4

?! what you mean?!
i didnt get it :X
thx..
Reply
#5

foreach is an include which provides faster loops, it also includes a function to get a random player

Just read the foreach topic and if you like it you could use the code varthshenon provided

If not use that

pawn Код:
stock GetRandomPlayer() {
    new
        i = 0,
        count = 0,
        player[MAX_PLAYERS];
    for( ; i != MAX_PLAYERS; ++i) {
        if(IsPlayerConnected(i)) {
            player[count++] = i;
        }
    }
    if(count == 0) {
        return INVALID_PLAYER_ID;
    }
    return player[random(count)];
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)