This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

How to check if client doesn't have a flag


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SilentLikeSilence
Senior Member
Join Date: Jul 2009
Old 12-26-2009 , 10:52   How to check if client doesn't have a flag
Reply With Quote #1

Hello!

I'm making a plugin and I want to distinguish admins and donators.

PHP Code:

new flags GetUserFlagBits(client);

//Admins (have generic flag and kick flag)
if(flags ADMFLAG_GENERIC && flags ADMFLAG_KICK)

//Donators (have generic flag and don't have kick flag
if(flags ADMFLAG_GENERIC && flags *what can I use here?* ADMFLAG_KICK
Thanks for help!
Silent
SilentLikeSilence is offline
AltPluzF4
Senior Member
Join Date: Aug 2007
Old 12-26-2009 , 11:27   Re: How to check if client doesn't have a flag
Reply With Quote #2

You can simply set it in parenthesis and add the ! operator.

PHP Code:
if (flags ADMFLAG_GENERIC && !(flags ADMFLAG_KICK)) 
AltPluzF4 is offline
Dragonshadow
BANNED
Join Date: Jun 2008
Old 12-26-2009 , 12:21   Re: How to check if client doesn't have a flag
Reply With Quote #3

I'm half asleep, but maybe this could help:

PHP Code:
 
stock HasFlag
(clientflag)
{
    new 
AdminId:admin GetUserAdmin(client);
    if((
admin != INVALID_ADMIN_ID) && (GetAdminFlag(adminflagAccess_Effective) == true))
    {
        return 
true;
    }
    return 
false;

Dragonshadow is offline
Antithasys
Moderator
Join Date: Apr 2008
Old 12-26-2009 , 13:48   Re: How to check if client doesn't have a flag
Reply With Quote #4

Look at my core stock function SM_IsValidAdmin()

Does all you need, and you can even make the donator flag a cvar and pass the flag string you want to look for.
__________________
[my plugins]

When you think about asking a question... consider what have you tried?
Antithasys is offline
SilentLikeSilence
Senior Member
Join Date: Jul 2009
Old 12-26-2009 , 14:43   Re: How to check if client doesn't have a flag
Reply With Quote #5

Works perfectly, thanks.
SilentLikeSilence is offline
Kevin_b_er
SourceMod Donor
Join Date: Feb 2009
Old 12-26-2009 , 16:32   Re: How to check if client doesn't have a flag
Reply With Quote #6

With some bit-manipulation-foo:

if((flags & (ADMFLAG_GENERIC | ADMFLAG_KICK)) == ADMFLAG_GENERIC)
Kevin_b_er is offline
Wazz
SourceMod Donor
Join Date: Mar 2009
Old 12-26-2009 , 16:46   Re: How to check if client doesn't have a flag
Reply With Quote #7

Quote:
Originally Posted by SilentLikeSilence View Post
PHP Code:
//Donators (have generic flag and don't have kick flag)
if(flags ADMFLAG_GENERIC && flags *what can I use here?* ADMFLAG_KICK
becomes
PHP Code:
//Donators (have generic flag and don't have kick flag)
if(flags ADMFLAG_GENERIC && flags ADMFLAG_KICK
^ is XOR
Wazz is offline
Kevin_b_er
SourceMod Donor
Join Date: Feb 2009
Old 12-27-2009 , 16:06   Re: How to check if client doesn't have a flag
Reply With Quote #8

Wazz, I don't think that will work to use XOR like that.

For the person with both:
ADMFLAG_KICK is 100 (base 2) and ADMFLAG_GENERIC is 10 (base 2), making 110.

So we have the following XOR operation of 110 with 100 (the kick flag), which is flags ^ ADMFLAG_KICK with flags = both generic and kick.
Code:
0110
0100
-----
0010
If they only had the generic flag:
Code:
0010
0100
-----
0110
Neither calculation results in 0, so they both be true and flags ^ ADMFLAG_KICK will be true for the examples in the OP's post.
Kevin_b_er is offline
Wazz
SourceMod Donor
Join Date: Mar 2009
Old 12-27-2009 , 18:24   Re: How to check if client doesn't have a flag
Reply With Quote #9

Thanks for pointing that out. So I'm thinking ~flags & ADMFLAG_KICK would work.
Code:
1001 - 0110 inverted
0100
----
0000 - False, user has ADMFLAG_KICK
Code:
1101 - 0010 inverted
0100
----
0100 - True, user doesn't have ADMFLAG_KICK
These operations always confuse me.
Wazz is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 12-27-2009 , 20:13   Re: How to check if client doesn't have a flag
Reply With Quote #10

Just do what AltPluzF4 said.
bl4nk 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 16:00.


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