AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get_flags (https://forums.alliedmods.net/showthread.php?t=233780)

kasu007 01-20-2014 06:48

get_flags
 
Question: Which is faster and less cpu usage.
Doing
PHP Code:

#define VipAccess ADMIN_CHAT
public vipMenu(id){
    if(
get_user_flagsid) & VipAccess ){
        
// menu
        // give item
   
}
}

OR

new 
vipAccess[32];
public 
client_putinserver(id){
    if(
get_user_flagsid) & VipAccess ){
        
vipAccess[id] = true;
    }
}
public 
client_disconnect(id){
    
vipAccess[id] = false;
}
public 
vipMenu(id){
    if( 
vipAccess ){
        
// menu
        // give item
   
}



SpeeDeeR 01-20-2014 06:54

Re: get_flags
 
It's surely a trivial optimization.
Using the first one will avoid the situation of adding flags while the player is ingame and appear as the player doesn't have the needed flag.

YamiKaitou 01-20-2014 09:39

Re: get_flags
 
If another plugin modifies the users flags after you have saved them, then you will start to encounter problems. Unless you don't care about that, best to stick to calling get_user_flags when it is needed

kasu007 01-21-2014 02:42

Re: get_flags
 
There is no other plugin that modifies, for me if its needed I can add the user to vipAccess[id] = true;
I'm just wondering if its faster if there is 16 players and in each player spawn its asked get_user_flags(id)
and then menu does the same check and more other things.

For me, lets say 100x get_user_flags(id) OR 100x
vipAccess[id] ==true ?
like I mean, example in 1st post

fysiks 01-21-2014 05:06

Re: get_flags
 
Quote:

Originally Posted by kasu007 (Post 2088895)
For me, lets say 100x get_user_flags(id) OR 100x [/COLOR][/COLOR][/COLOR][/COLOR][/COLOR]vipAccess[id] ==true ?
like I mean, example in 1st post

The latter is faster.

Bugsy 01-21-2014 11:37

Re: get_flags
 
Checking a variable/array value is definitely better than calling a native function.

You can do this, too:
PHP Code:

public client_putinserver(id)
{
        
vipAccessid ] = ( get_user_flagsid ) & VipAccess ) ? true false;


If you plan on having multiple-flags then it's safer to do this because using (flags & Access) will return true if it finds only 1 matching flag. So if you have 4 flags, it can return true if the user has only 1, or any number of the Access flags.
PHP Code:

public client_putinserver(id)
{
        
vipAccessid ] = ( ( get_user_flagsid ) & VipAccess ) = VipAccess ) ? true false;


You also want to size your vipAccess array to 33; if a user on slot 32 connects you will get an index out of bounds error.


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

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