Raised This Month: $12 Target: $400
 3% 

Checking for several flags


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EpicKiller
Senior Member
Join Date: Jun 2014
Location: Constanta, Romania
Old 03-11-2015 , 05:39   Checking for several flags
Reply With Quote #1

I had to do a check for three flags. I tried if(get_user_flags(id) & ADMIN_LEVEL_F | ADMIN_LEVEL_G | ADMIN_LEVEL_H), but everybody would pass this one. Should "|" be a comma or "&&"? Of course I also thought of three if statements, but that's obviously uneficient. How should I do it?
__________________
~ Swiftly and with style ~
EpicKiller is offline
Send a message via Yahoo to EpicKiller Send a message via Skype™ to EpicKiller
Shiina.Mashiro
Senior Member
Join Date: Sep 2014
Location: Vietnam
Old 03-11-2015 , 06:18   Re: Checking for several flags
Reply With Quote #2

PHP Code:
if(get_user_flags(id) & ADMIN_LEVEL_F && ADMIN_LEVEL_G && ADMID_LEVEL_H)
{
     
//do stuff

try this
__________________
Shiina.Mashiro is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-11-2015 , 08:07   Re: Checking for several flags
Reply With Quote #3

Quote:
PHP Code:
if(get_user_flags(id) & ADMIN_LEVEL_F && ADMIN_LEVEL_G && ADMID_LEVEL_H)
{
     
//do stuff

try this
That's wrong shiina

PHP Code:
const FlagsNeeded ADMIN_LEVEL_F ADMIN_LEVEL_G ADMID_LEVEL_H;

if( ( 
get_user_flags(id) & FlagsNeeded ) == FlagsNeeded )
{
     
//do stuff

__________________

Last edited by Bugsy; 03-11-2015 at 08:13.
Bugsy is offline
Shiina.Mashiro
Senior Member
Join Date: Sep 2014
Location: Vietnam
Old 03-11-2015 , 10:48   Re: Checking for several flags
Reply With Quote #4

Quote:
Originally Posted by Bugsy View Post
That's wrong shiina

PHP Code:
const FlagsNeeded ADMIN_LEVEL_F ADMIN_LEVEL_G ADMID_LEVEL_H;

if( ( 
get_user_flags(id) & FlagsNeeded ) == FlagsNeeded )
{
     
//do stuff

wew that's weird, because it works fine for me xD
but ur way is better I think
__________________
Shiina.Mashiro is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-11-2015 , 12:14   Re: Checking for several flags
Reply With Quote #5

Quote:
Originally Posted by Shiina.Mashiro View Post
wew that's weird, because it works fine for me xD
but ur way is better I think
It does not work fine for you, you are just not testing the condition correctly. Your method will always return true as long as the player has the ADMIN_LEVEL_F flag. The other flags you are using conditional AND (&&) on which just checks if they are non-zero, which is always true. I see you are at 1% at learning Pawn. Please don't try to help others if you don't know how to script yourself.
__________________

Last edited by Bugsy; 03-11-2015 at 12:19.
Bugsy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-11-2015 , 12:29   Re: Checking for several flags
Reply With Quote #6

You can use read_flags too.
__________________
HamletEagle is offline
EpicKiller
Senior Member
Join Date: Jun 2014
Location: Constanta, Romania
Old 03-11-2015 , 16:08   Re: Checking for several flags
Reply With Quote #7

Thank you both, guys! You're great!
__________________
~ Swiftly and with style ~
EpicKiller is offline
Send a message via Yahoo to EpicKiller Send a message via Skype™ to EpicKiller
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-11-2015 , 16:40   Re: Checking for several flags
Reply With Quote #8

Quote:
Originally Posted by HamletEagle View Post
You can use read_flags too.
OP: read_flags( "efg" ) instead of ( FLAG | FLAG | FLAG ) would only be useful if you wanted to set admin flag permissions with a cvar/config/string of some sort. If the flags are permanent/hard-coded, use what I posted above.
__________________

Last edited by Bugsy; 03-11-2015 at 16:43.
Bugsy is offline
EpicKiller
Senior Member
Join Date: Jun 2014
Location: Constanta, Romania
Old 03-11-2015 , 17:57   Re: Checking for several flags
Reply With Quote #9

Quote:
Originally Posted by Bugsy View Post
OP: read_flags( "efg" ) instead of ( FLAG | FLAG | FLAG ) would only be useful if you wanted to set admin flag permissions with a cvar/config/string of some sort. If the flags are permanent/hard-coded, use what I posted above.
I've used it, thank you for that!
__________________
~ Swiftly and with style ~
EpicKiller is offline
Send a message via Yahoo to EpicKiller Send a message via Skype™ to EpicKiller
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 03-12-2015 , 14:16   Re: Checking for several flags
Reply With Quote #10

There's also the has_flag() stock. Essentially it encapsulates Bugsy's method.

http://www.amxmodx.org/api/amxmisc/has_flag

Alternately, if you want them to have all the flags specified:

http://www.amxmodx.org/api/amxmisc/has_all_flags
__________________

Last edited by Brad; 03-12-2015 at 14:17.
Brad 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 16:13.


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