AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Checking for several flags (https://forums.alliedmods.net/showthread.php?t=259697)

EpicKiller 03-11-2015 05:39

Checking for several flags
 
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?

Shiina.Mashiro 03-11-2015 06:18

Re: Checking for several flags
 
PHP Code:

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


try this

Bugsy 03-11-2015 08:07

Re: Checking for several flags
 
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



Shiina.Mashiro 03-11-2015 10:48

Re: Checking for several flags
 
Quote:

Originally Posted by Bugsy (Post 2272544)
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

Bugsy 03-11-2015 12:14

Re: Checking for several flags
 
Quote:

Originally Posted by Shiina.Mashiro (Post 2272599)
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.

HamletEagle 03-11-2015 12:29

Re: Checking for several flags
 
You can use read_flags too.

EpicKiller 03-11-2015 16:08

Re: Checking for several flags
 
Thank you both, guys! You're great!

Bugsy 03-11-2015 16:40

Re: Checking for several flags
 
Quote:

Originally Posted by HamletEagle (Post 2272630)
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.

EpicKiller 03-11-2015 17:57

Re: Checking for several flags
 
Quote:

Originally Posted by Bugsy (Post 2272731)
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!

Brad 03-12-2015 14:16

Re: Checking for several flags
 
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


All times are GMT -4. The time now is 12:28.

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