Random Player from a team
#2

There's nothing random about it. It just picks the first player in that team all the time. I will suggest using foreach and custom iterators; one for each team. Then you can use Iter_Rand(). Otherwise you can get by with a do-while loop but you must be cautious to not let it run infinitely.

PHP код:
GetRandomPlayerInTeam(teamdef)
{
    new
        
randomPlayer INVALID_PLAYER_ID,
        
maxId GetPlayerPoolSize(),
        
loopGuard 1000;
        
    do
    {
        
randomPlayer random(maxId);
    }
    while(
team[randomPlayer] != teamdef && --loopGuard 0);
    
    return (
loopGuard <= 0) ? INVALID_PLAYER_ID randomPlayer;

Again, foreach is probably the better option.
Reply


Messages In This Thread
Random Player from a team - by xTURBOx - 18.01.2017, 12:13
Re: Random Player from a team - by Vince - 18.01.2017, 12:30

Forum Jump:


Users browsing this thread: 1 Guest(s)