AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   define two flags? (https://forums.alliedmods.net/showthread.php?t=143527)

DeLiriuM 11-21-2010 05:14

define two flags?
 
Is it possible, to define 2 (or more) flags, so that the admin can use the specific command.

For example:
#define ADMIN_LEVEL_A && ADMIN_LEVEL_B
The admin should have both "m" and "n" so that he could use +hook (for example).

ConnorMcLeod 11-21-2010 05:37

Re: define two flags?
 
PHP Code:

const FLAG_ADMIN_HOOK ADMIN_LEVEL_A ADMIN_LEVEL_B

register_clcmd
("+hook""ClCmd_HookOn"FLAG_ADMIN_HOOK)

public 
ClCmd_HookOn(idlvl)
{
    if( !
is_user_alive(id) || get_user_flags(id) & FLAG_ADMIN_HOOK != FLAG_ADMIN_HOOK )
    {
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_HANDLED



DeLiriuM 09-04-2011 05:08

Re: define two flags?
 
Ok. What happens if I want to define 6 flags for example? Is there an easier way?


(1) Flags abcd => get access to specific command.
(2) Flag b => access to another specific command.

But (1) shouldn't have access to (2).

jim_yang 09-04-2011 05:21

Re: define two flags?
 
if ( get_user_flags(id) == read_flags("abcd") )
if ( get_user_flags(id) == read_flags("b") )

Backstabnoob 09-04-2011 05:23

Re: define two flags?
 
Just do it like

PHP Code:

const FLAGS ADMIN_IMMUNITY ADMIN_KICK ADMIN_BAN ADMIN_RESERVATION
const FLAG ADMIN_RESERVATION


if(get_user_flags(id) & FLAGS)
 return

if(
get_user_flags(id) & FLAG)
 
// has only b flag 


ConnorMcLeod 09-04-2011 06:28

Re: define two flags?
 
Backstabnoob is wrong.

PHP Code:

public plugin_init()
{
    
register_clcmd("amx_command""ClCmd_Command")
}

public 
ClCmd_Command(id)
{
    const 
ADMIN_FULLACCESS ADMIN_IMMUNITY ADMIN_RESERVATION ADMIN_KICK ADMIN_BAN
    
new iFlags get_user_flags(id)
    if( 
iFlags ADMIN_FULLACCESS == ADMIN_FULLACCESS )
    {
        
// first command code
    
}
    else if( 
iFlags ADMIN_RESERVATION )
    {
        
// second command code
    
}
    return 
PLUGIN_HANDLED



Backstabnoob 09-04-2011 06:42

Re: define two flags?
 
Can you explain why is there the equality operator? I kind of don't understand that...

Edit: what exactly is wrong with that? I thought that when a player has all of these access flags, it shall not allow him process to the next check.

Arkshine 09-04-2011 06:50

Re: define two flags?
 
If you don't put == it means the flag can be either ADMIN_IMMUNITY or ADMIN_RESERVATION , etc.. And not ADMIN_IMMUNITY and ADMIN_IMMUNITY, etc..

Backstabnoob 09-04-2011 06:52

Re: define two flags?
 
Thanks, looks like I made a lot of mistakes because of that :D


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

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