AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Check admin flags (https://forums.alliedmods.net/showthread.php?t=245012)

ashwink7 07-27-2014 02:14

Check admin flags
 
hi this is my code basically what i want is that to get the acces flags via cvar and check whether the user has that flags and execute som codes according to it hers my code

PHP Code:

new flag;
new 
aflags[5];
public 
plugin_init() 
{
             
flag register_cvar("acces_flag","a");
             
register_clcmd("say /lol","check_flags");
}
public 
check_flags(id)
{
                        
get_pcvar_string(flag,aflags,charsmax(aflags));
                        if(
get_user_flags(id) && read_flags(aflags)); 
                           {
                                    
// my code 
                           
}



here i want to check whether user has a ie immunity flag or not but this code is not working :( please help

YamiKaitou 07-27-2014 03:12

Re: Check admin flags
 
Use & instead of &&

ashwink7 07-27-2014 05:51

Re: Check admin flags
 
Quote:

Originally Posted by YamiKaitou (Post 2174487)
Use & instead of &&

CAn you please xplain me why it wont work for && nd what is the difference between & and && ? :)

mottzi 07-27-2014 06:18

Re: Check admin flags
 
&& is the logic boolean 'and'-operator while & is the bitwise 'and'-operator. There is a good tutorial in the tutorials section about that.

Bugsy 07-27-2014 17:06

Re: Check admin flags
 
If you ever use a cvar (or any variable) that holds more than 1 flag, your code will still return true when the player has only 1 of the flags, any combination of, or all flags.

Here's an example, see my comments.
PHP Code:

public check_flags(id)
{
    new 
iFlags;
    
iFlags read_flagsget_pcvar_stringflag aflags charsmaxaflags ) ) );

    
//True only if player has ALL flags contained in aflags cvar.
    
if( ( get_user_flagsid ) & iFlags ) == iFlags ); 
    {
        
// my code 
    
}

    
//True if player has AT LEAST ONE (or some, or all) of the flags contained in aflags cvar.
    
if( get_user_flagsid ) & iFlags ); 
    {
        
// my code 
    
}




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

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