AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Print To All Admins (https://forums.alliedmods.net/showthread.php?t=108977)

noodleboy347 11-11-2009 17:35

Print To All Admins
 
How could I use PrintToChat and have it show up to all of the admins?

bl4nk 11-11-2009 20:01

Re: Print To All Admins
 
Simple version:
PHP Code:

stock PrintToAdmins(const String:sMessage[])
{
    for (new 
1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            new 
flags GetUserFlagBits(i);
            if (
flags ADMFLAG_GENERIC || flags ADMFLAG_ROOT)
            {
                
PrintToChat(isMessage);
            }
        }
    }


Using a stock I wrote:

PHP Code:

stock PrintToAdmins(const String:sMessage[])
{
    for (new 
1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            new 
flags GetUserFlagBits(i);
            if (
CheckAdminFlags(iADMFLAG_GENERIC))
            {
                
PrintToChat(isMessage);
            }
        }
    }
}

/**
 * Checks to see if a client has all of the specified admin flags
 *
 * @param client        Player's index.
 * @param flags            Flags to check for.
 * @return                True on admin having all flags, false otherwise.
 */
stock bool:CheckAdminFlags(clientflags)
{
    new 
AdminId:admin GetUserAdmin(client);
    if (
admin != INVALID_ADMIN_ID)
    {
        new 
countfound;
        for (new 
0<= 20i++)
        {
            if (
flags & (1<<i))
            {
                
count++;

                if (
GetAdminFlag(adminAdminFlag:i))
                {
                    
found++;
                }
            }
        }

        if (
count == found)
        {
            return 
true;
        }
    }

    return 
false;



meng 11-11-2009 22:11

Re: Print To All Admins
 
oops, nvm, listen to that guy ^^^

FaTony 11-12-2009 09:38

Re: Print To All Admins
 
I'm using this:
PHP Code:

public InformAdmin (const String:rawmessage[], any:...)
{
    new 
String:message[MESSAGE_LENGTH];
    
VFormat(messageMESSAGE_LENGTHrawmessage2);
    new 
AdminId:id=INVALID_ADMIN_ID;
    
PrintToServer(message);
    new 
clients=GetClientCount();
    for (new 
i=1;i<=clients;i++) {
        if (
IsClientConnected(i)) {
            
id=GetUserAdmin(i);
            if (
id!=INVALID_ADMIN_ID) {
                
PrintToConsole(imessage);
                
PrintToChat(imessage);
                }
            }
        }



DJ Tsunami 11-12-2009 10:42

Re: Print To All Admins
 
That's wrong FaTony, using GetClientCount() in a for-loop might leave out clients. Use MaxClients instead. Also a little more spacing to make it more readable wouldn't hurt :)

exvel 11-12-2009 14:07

Re: Print To All Admins
 
Quote:

Originally Posted by FaTony (Post 987875)
I'm using this:
PHP Code:

public InformAdmin (const String:rawmessage[], any:...)
{
    new 
String:message[MESSAGE_LENGTH];
    
VFormat(messageMESSAGE_LENGTHrawmessage2);
    new 
AdminId:id=INVALID_ADMIN_ID;
    
PrintToServer(message);
    new 
clients=GetClientCount();
    for (new 
i=1;i<=clients;i++) {
        if (
IsClientConnected(i)) {
            
id=GetUserAdmin(i);
            if (
id!=INVALID_ADMIN_ID) {
                
PrintToConsole(imessage);
                
PrintToChat(imessage);
                }
            }
        }



Use IsClientInGame instead of IsClientConnected. Or there may be erros.

BrutalGoerge 11-12-2009 14:24

Re: Print To All Admins
 
well i this it's better to look at people with root or ban, since i have admins with just a flag for reservation, or s flag for reskick immunity.

bl4nk 11-12-2009 22:10

Re: Print To All Admins
 
Quote:

Originally Posted by BrutalGoerge (Post 988176)
well i this it's better to look at people with root or ban, since i have admins with just a flag for reservation, or s flag for reskick immunity.

That's why in my version I specified the b/z flags. Also with the second example I provided you could specify multiple flags and it would only fire if the clients had all of the flags. For example:

PHP Code:

if (CheckAdminFlags(clientADMFLAG_GENERIC|ADMFLAG_BAN|ADMFLAG_SLAY))
{
    
// do stuff


I also have a slightly modified version that makes it so if any of the specified admin flags are found on the client it will trigger, if you would like that.

p3tsin 11-12-2009 22:54

Re: Print To All Admins
 
Quote:

Originally Posted by bl4nk (Post 988689)
Also with the second example I provided you could specify multiple flags and it would only fire if the clients had all of the flags. For example:

PHP Code:

if (CheckAdminFlags(clientADMFLAG_GENERIC|ADMFLAG_BAN|ADMFLAG_SLAY))
{
    
// do stuff



... isnt that the same as this?

PHP Code:

if((GetUserFlagBits(client) & ADMFLAG_GENERIC|ADMFLAG_BAN|ADMFLAG_SLAY) == ADMFLAG_GENERIC|ADMFLAG_BAN|ADMFLAG_SLAY) {
    
//do stuff



FaTony 11-13-2009 09:28

Re: Print To All Admins
 
Well my code was written in early 2008 when I was a complete noob in scripting. :D I'll fix it.

EDIT: Fixed.
PHP Code:

public InformAdmin (const String:rawmessage[], any:...)
{
    
decl String:message[MESSAGE_LENGTH];
    
VFormat(messageMESSAGE_LENGTHrawmessage2);
    new 
AdminId:id=INVALID_ADMIN_ID;
    
PrintToServer(message);
    for (new 
i=1;i<=MaxClients;i++) {
        if (
IsClientInGame(i)) {
            
id=GetUserAdmin(i);
            if (
id!=INVALID_ADMIN_ID) {
                
PrintToConsole(imessage);
                
PrintToChat(imessage);
                }
            }
        }




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

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