SA-MP Forums Archive
Getting 1 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Getting 1 Random Player (/showthread.php?tid=271143)



Getting 1 Random Player - COD - 23.07.2011

i don't understand how to get 1 random player using foreach i made one but it gets like 3 or 6 players.

im also using gTeam.


Re: Getting 1 Random Player - Kitten - 23.07.2011

pawn Код:
forward RandomPlayer(playerid);
public RandomPlayer(playerid) {
    new count = 0;
    new Random = Iter_Random(Player);
    foreach(Player, i){
        if(gTeam[i] == TeamName) count++;
        if(count == Iter_Count(Player)) {
            // Your stuff for that 1 player
                        // Example GivePlayerCash(Random,5000);
        }
    }
    return 1;
}