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

Solved Check if client has at least one of multiple flags


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LiveAndLetDie
Junior Member
Join Date: Sep 2019
Location: Finland
Old 11-22-2020 , 20:46   Check if client has at least one of multiple flags
Reply With Quote #1

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.

Last edited by LiveAndLetDie; 11-23-2020 at 14:12.
LiveAndLetDie is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 11-22-2020 , 20:57   Re: Check if client has at least one of multiple flags
Reply With Quote #2

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);

__________________
Psyk0tik is offline
SSheriFF
AlliedModders Donor
Join Date: May 2020
Location: Israel
Old 11-22-2020 , 21:05   Re: Check if client has at least one of multiple flags
Reply With Quote #3

Quote:
Originally Posted by LiveAndLetDie View Post
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;

__________________
Taking small private requests (Free) and big private requests (Paid).
Contact me via Discord: WilDick#1524

My Plugins:
SSheriFF is offline
LiveAndLetDie
Junior Member
Join Date: Sep 2019
Location: Finland
Old 11-23-2020 , 14:11   Re: Check if client has at least one of multiple flags
Reply With Quote #4

Both of these do the job. Thanks a lot!
LiveAndLetDie 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 03:11.


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