SA-MP Forums Archive
How do I pick a random admin? - 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: How do I pick a random admin? (/showthread.php?tid=139526)



How do I pick a random admin? - biltong - 05.04.2010

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.


Re: How do I pick a random admin? - dice7 - 05.04.2010

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



Re: How do I pick a random admin? - biltong - 05.04.2010

Thanks.


Re: How do I pick a random admin? - biltong - 06.04.2010

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.


Re: How do I pick a random admin? - campkz - 06.04.2010

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.