AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   access() or get_user_flags()? (https://forums.alliedmods.net/showthread.php?t=195492)

Jje 09-08-2012 08:21

access() or get_user_flags()?
 
Hello. What is faster access(index, FLAG) or get_user_flags(index) & FLAG? Is there any difference?

jimaway 09-08-2012 08:29

Re: access() or get_user_flags()?
 
where are you using it that you need speed? maybe it would be better to cache the value to a boolean

ConnorMcLeod 09-08-2012 08:31

Re: access() or get_user_flags()?
 
Use cmd_accessOr tell us in which context you want to use it.
In normal contexts, you shouldn't care about performances.

Jje 09-08-2012 08:33

Re: access() or get_user_flags()?
 
Yes, but i interested for what access(...) need? Isn't this the same with (get_user_flags(index) & FLAG)?

ConnorMcLeod 09-08-2012 08:35

Re: access() or get_user_flags()?
 
context plz

Jje 09-08-2012 08:37

Re: access() or get_user_flags()?
 
Code:

if(access(id, ADMIN_ADMIN));
and
Code:

if(get_user_flags(id) & ADMIN_ADMIN);
case the same? so for what access() was created?

ConnorMcLeod 09-08-2012 08:44

Re: access() or get_user_flags()?
 
PHP Code:

stock access(id,level
{
    if (
level==ADMIN_ADMIN)
    {
        return 
is_user_admin(id);
    }
    else if (
level==ADMIN_ALL)
    {
        return 
1;
    }

    return (
get_user_flags(id) & level);


access prevents coder from making mistakes with flags, because not all coders know usages of ADMIN_ADMIN and ADMIN_ALL, and also it handles better situations where the admin level is hold by a variable.

So :
If you check admin access in a command, use cmd_access
Else use access.
You may also need has_flag or has_all_flags in some situations.

Jje 09-08-2012 08:49

Re: access() or get_user_flags()?
 
Thanks a lot :)


All times are GMT -4. The time now is 08:10.

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