Random player!
#6

Quote:
Originally Posted by armyoftwo
Посмотреть сообщение
Mike_Garber, your function might be buggy. Why? For example you have 10 players in your server with id's 0, 1, 3, 5, 6, 9, 10, 12, 13, 14. Random function might pick Non existing ID, for example 4.
Foreach include has an function with what you can pick random player with no bugs( search for it )
It's not my function, but yeah I guess... And i know about foreach but he might not have it... But
my code can easily be rewritten to not pick an invalid ID.
pawn Код:
GetPlayersOnServer() {
    new count;
    for(new x=0; x< MAX_PLAYERS; x++) { //x = MAX_PLAYERS
      if(IsPlayerConnected(x))) {
            count++;
        }
    }
    return count;
}

// Then do;
randomplayer()
{
    new randomid = random(GetPlayersOnServer());
    if(!IsPlayerConnected(randomid)){ return randomplayer(); }
    return randomid;
}

//And now you can do a function like;
infectplayer(randomplayer);
This should work.
Reply


Messages In This Thread
Random player! - by GNGification - 22.03.2011, 20:10
Re: Random player! - by Mike Garber - 22.03.2011, 20:17
Re: Random player! - by GNGification - 22.03.2011, 20:22
Re: Random player! - by armyoftwo - 22.03.2011, 20:26
Re: Random player! - by Jefff - 22.03.2011, 20:27
Re: Random player! - by Mike Garber - 22.03.2011, 20:29
Re: Random player! - by GNGification - 27.03.2011, 06:50

Forum Jump:


Users browsing this thread: 1 Guest(s)