AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   how does get_user_flags(id) work? (https://forums.alliedmods.net/showthread.php?t=95546)

minimiller 06-24-2009 15:43

how does get_user_flags(id) work?
 
please dont link me to this i know how it works in the coding sence, i want to know how it really works

Lets start with a snippet:
PHP Code:

#include <amxmodx>
#include <amxmisc>

public plugin_init()
{
    
register_plugin("flags test""1.0""Stewie!");
    
register_clcmd("say /myflags""myflags", -1"Handles the /myflags command");
}

public 
myflags(id)
{
    if(
get_user_flags(id) & ADMIN_ADMIN)
    {
         
client_print(idprint_chat"You are an admin!");
    }
    else
    {
         
client_print(idprint_chat"You are not an admin!");
    }


So clearly, ADMIN_ADMIN and all the other flags are defined as:
PHP Code:

#define ADMIN_ADMIN 1
#define ADMIN_IMMUNITY 2
#define ADMIN_BAN 4
#define ADMIN_KICK 8
etc

when get_user_flags(id) is called, the function loops through the users.ini file to see if the steamID of who called the func matches an entry
something like this:
PHP Code:

get_user_flags(id)
{
    if(
file_exists(gUsersIni))
    {
        new 
TextLine[33];
        new 
NoOfChars;
        new 
szPlayerAuth[33];
        new 
Lines file_size(gUsersIni1);
        new 
szParse[2][33];
        new 
iValue 0;
        
        for(new 
LineToReadLineToRead LinesLineToRead++)
        {
            
read_file(gUsersIniLineToReadTextLine32NoOfChars);
            
            if(!
TextLine[0] || TextLine[0] == ';' || TextLine[0] == '/' && TextLine[1] == '/')
            {
                continue;
            }
            
            
get_user_authid(idszPlayerAuth32);
            
parse(TextLineszParse[0], 32szParse[1], 32);
            
            if(
equali(szPlayerAuthszParse[0]))
            {
                if(
containi(szParse[1], "a"))
                {
                    return 
ADMIN_IMMUNITY//This line
                
}
            }
        }
    }
    return 
0;


but what happens on the lines that ive commented?
Clearly you cannot return more than 1 value so doing this wouldnt work
PHP Code:

if((containi(szParse[1], "a")) && (containi(szParse[1], "b")))
{
    return 
ADMIN_IMMUNITY && ADMIN_BAN;


any1 know how it works properly?

Sylwester 06-24-2009 16:26

Re: how does get_user_flags(id) work?
 
it should be sth like this:
PHP Code:

  if((containi(szParse[1], "a")) && (containi(szParse[1], "b")))
  {
      return 
ADMIN_IMMUNITY ADMIN_BAN;
  } 

but using containi and + is not very effective. You should loop through all cells and depending on value change variable holding result and return it at the end.

sth like this:
PHP Code:

res 0
for(new i=0i<strlen(flags_string); i++)
    
res res | (<< (flags_string[i] - offset) )
return 
res 


minimiller 06-24-2009 16:51

Re: how does get_user_flags(id) work?
 
interesting
ill try that out l8er
just about to start a mix =D

xPaw 06-24-2009 17:07

Re: how does get_user_flags(id) work?
 
Quote:

Originally Posted by minimiller (Post 856203)
interesting
ill try that out l8er
just about to start a mix =D

We already finished mixing :mrgreen:


All times are GMT -4. The time now is 15:26.

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