Raised This Month: $32 Target: $400
 8% 

Solved [CS:GO] Check if there's admin in the server


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 03-20-2018 , 20:49   [CS:GO] Check if there's admin in the server
Reply With Quote #1

Is there any fancy way to check if there is admin in the server, before processing a command.

Player A (not an admin) type: sm_testcommand

The plugin will check if there is admin in the server and if there is - it will print for exampe "You can't use that command while an admin is in the server"

Something like that I guess.
PHP Code:
for (int client 1client <= MaxClientsclient++)
{
     if(
IsClientInGame(client) || CheckCommandAccess(client"is_a_sm_admin"ADMFLAG_GENERICtrue))
     {
          
//And add a count++ if an admin is online
     
}
}

if(
count0)
{
     
PrintToChat(client"Nope, admin online");

__________________

Last edited by PinHeaDi; 03-24-2018 at 09:27.
PinHeaDi is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 03-20-2018 , 23:51   Re: [CS:GO] Check if there's admin in the server
Reply With Quote #2

That will work
__________________
8guawong is offline
pride95
Senior Member
Join Date: Aug 2015
Old 03-21-2018 , 10:59   Re: [CS:GO] Check if there's admin in the server
Reply With Quote #3

why count? use a bool for what you need and a break after you found an admin.
isclientingame and ( && ) checkcommandacces, not or ( || )

PHP Code:
bool admin false;

for (
int client 1client <= MaxClientsclient++)
{
     if(
IsClientInGame(client) && CheckCommandAccess(client"is_a_sm_admin"ADMFLAG_GENERICtrue))
     {
          
admin true;
          break;
     }


Last edited by pride95; 03-21-2018 at 11:00.
pride95 is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 03-24-2018 , 09:27   Re: [CS:GO] Check if there's admin in the server
Reply With Quote #4

PHP Code:
        int Admins 0;

    for(
int i 1<= MaxClientsi++)
    {
        if(
IsValidClient(i))
        {
            if(
CheckCommandAccess(i"is_a_sm_admin"ADMFLAG_GENERICtrue))        Admins++;
        }
    }

    if(
Admins >= 1)
    {
        
PrintToChat(client"message");
        return 
Plugin_Handled;
    } 
That's what I used, but I guess your code is more simple and well done.
__________________
PinHeaDi is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 03-24-2018 , 09:36   Re: [CS:GO] Check if there's admin in the server
Reply With Quote #5

If you don't need to count admins, just use a function bool.

Then you only need one line. if (isAdminOnline()){ PrintToChatAll("admin is online"); }

The return true in the function bool will also make sure to break the loop. Plus you can re-use the function in other places and keep code shorter.

Code:
bool isAdminOnline()
{
	for (int i = 1; i <= MaxClients; i++)
	{
     		if (IsClientInGame(i) && !IsFakeClient(i) && CheckCommandAccess(i, "sm_admin", ADMFLAG_GENERIC))
     		{
          		return true;
     		}
	}
	return false;
}

Last edited by Visual77; 03-24-2018 at 11:26. Reason: termonology changes, suggested by arne1288
Visual77 is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 03-24-2018 , 10:46   Re: [CS:GO] Check if there's admin in the server
Reply With Quote #6

Quote:
Originally Posted by Visual77 View Post
Then you only need one line. if (isAdmin()){ PrintToChatAll("admin is online"); }
In that case, I strongly suggest using better and more descriptive variable / function names, such as for example "isAdminOnline" or something.

isAdmin() sounds more like a function used to check whether someone specific is admin, e.g. "isAdmin(client)".
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline
Reply


Thread Tools
Display Modes

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 19:49.


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