Raised This Month: $ Target: $400
 0% 

Parsing a string for admin flags


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 07-31-2009 , 04:21   Re: Parsing a string for admin flags
Reply With Quote #1

Try this out. I modified another stock that I wrote to handle flag strings instead of just bitflags.

PHP Code:
/**
 * Checks to see if a client has all of the specified admin flags
 *
 * @param client        Player's index.
 * @param flagString    String of flags to check for.
 * @return                True on admin having all flags, false otherwise.
 */
stock bool:CheckAdminFlagsByString(client, const String:flagString[])
{
    new 
AdminId:admin GetUserAdmin(client);
    if (
admin != INVALID_ADMIN_ID)
    {
        new 
countfoundflags ReadFlagString(flagString);
        for (new 
0<= 20i++)
        {
            if (
flags & (1<<i))
            {
                
count++;

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

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

    return 
false;

bl4nk is offline
rodrigo286
Veteran Member
Join Date: Sep 2010
Location: Brazil, São Paulo
Old 11-17-2017 , 22:47   Re: Parsing a string for admin flags
Reply With Quote #2

Quote:
Originally Posted by bl4nk View Post
Try this out. I modified another stock that I wrote to handle flag strings instead of just bitflags.

PHP Code:
/**
 * Checks to see if a client has all of the specified admin flags
 *
 * @param client        Player's index.
 * @param flagString    String of flags to check for.
 * @return                True on admin having all flags, false otherwise.
 */
stock bool:CheckAdminFlagsByString(client, const String:flagString[])
{
    new 
AdminId:admin GetUserAdmin(client);
    if (
admin != INVALID_ADMIN_ID)
    {
        new 
countfoundflags ReadFlagString(flagString);
        for (new 
0<= 20i++)
        {
            if (
flags & (1<<i))
            {
                
count++;

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

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

    return 
false;

This works nice on 18/11/2017 Stable and Dev Build...

Thanks bl4nk.

New API Syntax:

PHP Code:
/**
 * Checks to see if a client has all of the specified admin flags
 *
 * @param client        Player's index.
 * @param flagString    String of flags to check for.
 * @return                True on admin having all flags, false otherwise.
 * Original taken from https://forums.alliedmods.net/showpost.php?p=886345&postcount=4
 */
stock bool CheckAdminFlagsByString(int client, const char[] flagString)
{
    
AdminId admin view_as<AdminId>(GetUserAdmin(client));
    if (
admin != INVALID_ADMIN_ID){
        
int countfoundflags ReadFlagString(flagString);
        for (
int i 0<= 20i++){
            if (
flags & (1<<i))
            {
                
count++;

                if(
GetAdminFlag(adminview_as<AdminFlag>(i))){
                    
found++;
                }
            }
        }

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

    return 
false;

Regards.
__________________
My Plugins | VIEW HERE | I accept private requests, send me a PM.
Buy respawn | Uber Recall | Grenade drop | Damage Supperssor
Meet the Medic | Disguise Expert | Crazy Jet

CZSBrasil TEAM

Last edited by rodrigo286; 11-17-2017 at 22:49.
rodrigo286 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 05:28.


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