Random player select
#6

Hello again.

I would do something like this:

pawn Code:
if(strcmp(cmd, "/mission", true) == 0)
{
    new onlineids[MAX_PLAYERS]; // to store all online playerids
    new playersonline; // to store the amount of current online players
    new pname[16]; // to store the chosen player's name

    for(new i=0; i<MAX_PLAYERS; i++) // loop through max amount of players (hopefully redefined from default!)
    {
        if(IsPlayerConnected(i)) // check to see if current id in the loop is connected
        {
            onlineids[playersonline] = i; // store the current id into the onlineids variable
            playersonline++; // increase the playersonline by 1
        }
    }

    GetPlayerName(onlineids[random(playersonline)], pname, sizeof(pname)); // use the random function to randomly select a store online id
    format(pname, sizeof(pname), "Player name is %s", pname);
    SendClientMessage(playerid, COLOR_WHITE, pname);
    return 1;
}
EDIT: ninja'd big time
Reply


Messages In This Thread
Random player select - by VoViNaToR - 14.06.2011, 18:57
Re: Random player select - by Mauzen - 14.06.2011, 19:01
Re: Random player select - by VoViNaToR - 14.06.2011, 19:10
Re: Random player select - by WooTFTW - 14.06.2011, 19:14
Re: Random player select - by Ricop522 - 14.06.2011, 19:20
Re: Random player select - by Benjo - 14.06.2011, 19:22
Re: Random player select - by VoViNaToR - 14.06.2011, 19:22

Forum Jump:


Users browsing this thread: 1 Guest(s)