How do I pick a random admin?
#1

Title. I have:

pawn Код:
for(new i; i < MAX_PLAYERS, i++)
{
    if(IsPlayerAdmin(playerid))
    {
        //code
    }
}
I don't want to run the code for every admin online, just a random one.
Reply
#2

pawn Код:
new
    AdminsOnline = 0, //variable to save the number of admins online
    i = 0,
    m = GetMaxPlayers(); //getting the max number of players
for (; i < m, i++) if (IsPlayerAdmin) AdminsOnline++; //getting the number of admins online

new rand = random(AdminsOnline); //getting a random number

for (; i < m, i++)
{
    if(IsPlayerAdmin(playerid))
    {
        if (AdminsOnline <= 0)
        {
            //random admin code
            break;
        }
        AdminsOnline--;
    }
}

//if the random number is 3, the third admin you meet in the loop will be the random admin
Reply
#3

Thanks.
Reply
#4

OK I got my code compiling now, but I'm not sure where to put the rand bit in. I can post the code if you'd like.
Reply
#5

new rand = random(AdminsOnline); //getting a random number


put that in your command your doing. (thats if your doing a command)

or if your doing onplayerspawn put it in there.

basically put it in the public thing your doing.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)