This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

{First Release} IsAdminOnline


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sammy-ROCK!
Senior Member
Join Date: Jun 2008
Location: Near Mrs.Lag
Old 09-22-2008 , 21:24   {First Release} IsAdminOnline
Reply With Quote #1

Code:
stock bool:IsAdminOnline(MaxPlayersInServer)
{
    for(new player=1; player<=MaxPlayersInServer; player++)
    {
        if(IsClientConnected(player))
        {
            new flags = GetUserFlagBits(player);
            if (flags != 0)
                return true;
        }
    }
    return false;
}
I was looking and SM didn't have a command to check if there are any admins online. So I decided to make one. This is my first release so tell me what you think about this stock. It returns if there are any admins online. Use GetMaxClients() inside OnMapStart() and save the result. Then call IsAdminOnline() with the saved result of GetMaxClients(). I decided to make it like that so GetMaxClients() would not be called more than needed.

For example:
Code:
new MaxPlayers = 0;

public OnPluginStart()
{
    RegConsoleCmd("isadminonline", Command_IsAdminOnline);
}

public OnMapStart()
{
    MaxPlayers = GetMaxClients();
}

stock bool:IsAdminOnline(MaxPlayersInServer)
{
    for(new player=1; player<=MaxPlayersInServer; player++)
    {
        if(IsClientConnected(player))
        {
            new flags = GetUserFlagBits(player);
            if (flags != 0)
                return true;
        }
    }
    return false;
}

public Action:Command_IsAdminOnline(client, args)
{
    if(IsAdminOnline(MaxPlayers))
        ReplyToCommand(client, "There are admins online.");
    else
        ReplyToCommand(client, "There are no admins online.");
    return Plugin_Handled;
}
Sammy-ROCK! is offline
pheadxdll
AlliedModders Donor
Join Date: Jun 2008
Old 09-24-2008 , 11:05   Re: {First Release} IsAdminOnline
Reply With Quote #2

To make this more extensive, why not return the client index of the admin. If one is not found, just return zero. The rest of your code would still work fine. ;)
__________________
pheadxdll is offline
Sammy-ROCK!
Senior Member
Join Date: Jun 2008
Location: Near Mrs.Lag
Old 09-24-2008 , 18:36   Re: {First Release} IsAdminOnline
Reply With Quote #3

Returning the admin index would not be that good. Like if there are 2 or more admins online it'd get only 1 admin. But I could make it store in a array the admin indexes. Going to post when i make it (Probably soon).
Sammy-ROCK! is offline
Sammy-ROCK!
Senior Member
Join Date: Jun 2008
Location: Near Mrs.Lag
Old 09-24-2008 , 19:04   Re: {First Release} IsAdminOnline
Reply With Quote #4

I done it from scratch but I'm not sure it'll work (Haven't tested).
Code:
stock ListAdminsOnline(MaxPlayersInServer, MaxArraySize = MaxPlayersInServer)
{
    new AdminList[MaxArraySize] = {0, ...};
    new CurrentArray = 0;
    for(new player=1; player<=MaxPlayersInServer; player++)
    {
        if(IsClientConnected(player))
        {
            new flags = GetUserFlagBits(player);
            if(flags != 0)
            {
                AdminList[CurrentArray] = player;
                CurrentArray++;
            }
        }
    }
    return AdminList;
}
Code:
new MaxPlayers = 0;
#define ADMINLIST_MAXSIZE 500

public OnPluginStart()
{
    RegConsoleCmd("isadminonline", Command_IsAdminOnline);
    RegConsoleCmd("listadminsonline", Command_ListAdminsOnline);
}

public OnMapStart()
{
    MaxPlayers = GetMaxClients();
}

stock bool:IsAdminOnline(MaxPlayersInServer)
{
    for(new player=1; player<=MaxPlayersInServer; player++)
    {
        if(IsClientConnected(player))
        {
            new flags = GetUserFlagBits(player);
            if (flags != 0)
                return true;
        }
    }
    return false;
}

public Action:Command_IsAdminOnline(client, args)
{
    if(IsAdminOnline(MaxPlayers))
        ReplyToCommand(client, "There are admins online.");
    else
        ReplyToCommand(client, "There are no admins online.");
    return Plugin_Handled;
}

stock ListAdminsOnline(MaxPlayersInServer, MaxArraySize = MaxPlayersInServer)
{
    new AdminList[MaxArraySize] = {0, ...};
    new CurrentArray = 0;
    for(new player=1; player<=MaxPlayersInServer; player++)
    {
        if(IsClientConnected(player))
        {
            new flags = GetUserFlagBits(player);
            if(flags != 0)
            {
                AdminList[CurrentArray] = player;
                CurrentArray++;
            }
        }
    }
    return AdminList;
}

public Action:Command_ListAdminsOnline(client, args)
{
    new AdminList[MaxPlayers] = ListAdminsOnline(MaxPlayers);
    if(AdminList[0] == 0)
    {
        ReplyToCommand(client, "No admins are online.");
        return Plugin_Handled;
    }
    decl String:List[ADMINLIST_MAXSIZE], String:Name[MAX_NAME_LENGTH];
    Format(List, sizeof(List), "The following admins are online:");
    GetClientName(AdminList[0], Name, sizeof(Name));
    Format(List, sizeof(List), "%s \"%s\"", List, Name);
    for(new i=1; i<MaxPlayers; i++)
    {
        if(IsClientConnected(AdminList[i]))
        {
            GetClientName(AdminList[i], Name, sizeof(Name));
            Format(List, sizeof(List), "%s, \"%s\"", List, Name);
        }
        else
        {
            Format(List, sizeof(List), "%s.", List);
            ReplyToCommand(client, List);
            return Plugin_Handled;
        }
    }
    Format(List, sizeof(List), "%s.", List);
    ReplyToCommand(client, List);
    return Plugin_Handled;
}
Sammy-ROCK! is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 09-24-2008 , 19:09   Re: {First Release} IsAdminOnline
Reply With Quote #5

PHP Code:
stock FindAdmins(adminArray[MAXPLAYERS+1])
{
    new 
posmaxclients GetMaxClients();
    for (new 
1<= maxclientsi++)
    {
        if (!
IsClientConnected(i) || !IsClientAuthorized(i))
            continue;

        if (
GetUserFlagBits(i) != 0)
        {
            
adminArray[pos] = i;
            
pos++;
        }
    }

    return 
pos;

Input an integer array (size of MAXPLAYERS+1) and it will return the number of admins found, with the admin's index(es) inserted into the input array.

You could use it in something like this:
PHP Code:
new adminArray[MAXPLAYERS+1], count;
if ((
count FindAdmins(adminArray)) > 0)
{
    
PrintToChatAll("There are %i admins online:"count);
    for (new 
0counti++)
    {
        
PrintToChatAll("%N"adminArray[i]);
    }

[edit]

^ Beaten?

Last edited by bl4nk; 09-24-2008 at 19:18.
bl4nk is offline
Sammy-ROCK!
Senior Member
Join Date: Jun 2008
Location: Near Mrs.Lag
Old 09-24-2008 , 21:46   Re: {First Release} IsAdminOnline
Reply With Quote #6

When did it become a fight about who beat each other? Also if you haven't noticed using PrintToChat with the possibility of many repeats would spam user and he wouldn't be able to read it actualy. Also GetMaxClients is only trusted at OnMapStart and it's a waste being called more than once (Like everytime you find admins).
Sammy-ROCK! is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 09-24-2008 , 21:56   Re: {First Release} IsAdminOnline
Reply With Quote #7

Quote:
Originally Posted by Sammy-ROCK! View Post
When did it become a fight about who beat each other?
..it's not.

Quote:
Originally Posted by Sammy-ROCK! View Post
Also if you haven't noticed using PrintToChat with the possibility of many repeats would spam user and he wouldn't be able to read it actualy.
I just provided an example. It's up to the users who actually want to use it to do what they want with it.

Quote:
Originally Posted by Sammy-ROCK! View Post
Also GetMaxClients is only trusted at OnMapStart and it's a waste being called more than once (Like everytime you find admins).
Once again, this was just an example. Sure, it might be a little wasteful, but I wrote up the code in about 2 minutes, and didn't feel the need to write a plugin to show how it was used.

bl4nk is offline
Sammy-ROCK!
Senior Member
Join Date: Jun 2008
Location: Near Mrs.Lag
Old 09-24-2008 , 21:59   Re: {First Release} IsAdminOnline
Reply With Quote #8

PrintToChatAll is not actualy only to users who wanna see. It's to every single player in game.
Sammy-ROCK! is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 09-24-2008 , 23:54   Re: {First Release} IsAdminOnline
Reply With Quote #9

I'm well aware of that. Like I said in my previous post. I was just giving an example to those who wanted to use the code I pasted. I don't expect someone to actually use that, I just put it there so someone will know how they can use the information given to them by the function.
bl4nk is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:16.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode