AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Check if client has at least one of multiple flags (https://forums.alliedmods.net/showthread.php?t=328726)

LiveAndLetDie 11-22-2020 20:46

Check if client has at least one of multiple flags
 
Hey, I want to check if client has at least one of the required flags set by cvar. Below is an example code which apparently only works with the first flag in the cvar string because if I give myself only 'o' flag then I don't have access.

Code:

#include <sourcemod>

ConVar g_cFlags;
int g_iFlags;

public void OnPluginStart()
{
    g_cFlags = CreateConVar("sm_test_flags", "bo");
    RegConsoleCmd("sm_test", OnTest);
}

public void OnConfigsExecuted()
{
    char Buffer[8];
    GetConVarString(g_cFlags, Buffer, sizeof(Buffer));
    g_iFlags = ReadFlagString(Buffer);
}

public Action OnTest(int client, int args)
{
    HasFlag(client) ? PrintToChat(client, "Access!") : PrintToChat(client, "No access!");
    return Plugin_Handled;
}

bool HasFlag(int client)
{
    return(CheckCommandAccess(client, "", g_iFlags, true));
}

How to modify it to meet the requirements? Any help would be appreciated.

Psyk0tik 11-22-2020 20:57

Re: Check if client has at least one of multiple flags
 
Try checking for the flags like this:
PHP Code:

bool HasFlag(int client)
{
    
int iUserFlags GetUserFlagBits(client);
    return (
g_iFlags != && (iUserFlags g_iFlags)) || (iUserFlags ADMFLAG_ROOT);



SSheriFF 11-22-2020 21:05

Re: Check if client has at least one of multiple flags
 
Quote:

Originally Posted by LiveAndLetDie (Post 2725953)
Hey, I want to check if client has at least one of the required flags set by cvar. Below is an example code which apparently only works with the first flag in the cvar string because if I give myself only 'o' flag then I don't have access.

Code:

#include <sourcemod>

ConVar g_cFlags;
int g_iFlags;

public void OnPluginStart()
{
    g_cFlags = CreateConVar("sm_test_flags", "bo");
    RegConsoleCmd("sm_test", OnTest);
}

public void OnConfigsExecuted()
{
    char Buffer[8];
    GetConVarString(g_cFlags, Buffer, sizeof(Buffer));
    g_iFlags = ReadFlagString(Buffer);
}

public Action OnTest(int client, int args)
{
    HasFlag(client) ? PrintToChat(client, "Access!") : PrintToChat(client, "No access!");
    return Plugin_Handled;
}

bool HasFlag(int client)
{
    return(CheckCommandAccess(client, "", g_iFlags, true));
}

How to modify it to meet the requirements? Any help would be appreciated.

Found this.
With a small modification it can get you what you want.
PHP Code:

stock bool CheckAdminFlagsByString(int client, const char[] flagString)
{
    
AdminId admin view_as<AdminId>(GetUserAdmin(client));
    if (
admin != INVALID_ADMIN_ID)
    {
        
int flags ReadFlagString(flagString);
        for (
int i 0<= 20i++)
        {
            if (
flags & (1<<i))
            {
                if(
GetAdminFlag(adminview_as<AdminFlag>(i)))
                    return 
true;
              }
          }
    }
    return 
false;



LiveAndLetDie 11-23-2020 14:11

Re: Check if client has at least one of multiple flags
 
Both of these do the job. Thanks a lot! :)


All times are GMT -4. The time now is 11:08.

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