Raised This Month: $ Target: $400
 0% 

get_flags


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kasu007
Junior Member
Join Date: Jan 2013
Old 01-20-2014 , 06:48   get_flags
Reply With Quote #1

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
   
}


Last edited by kasu007; 01-20-2014 at 06:50.
kasu007 is offline
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 01-20-2014 , 06:54   Re: get_flags
Reply With Quote #2

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.
SpeeDeeR is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-20-2014 , 09:39   Re: get_flags
Reply With Quote #3

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
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).

Last edited by YamiKaitou; 01-20-2014 at 09:40.
YamiKaitou is offline
kasu007
Junior Member
Join Date: Jan 2013
Old 01-21-2014 , 02:42   Re: get_flags
Reply With Quote #4

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
kasu007 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-21-2014 , 05:06   Re: get_flags
Reply With Quote #5

Quote:
Originally Posted by kasu007 View Post
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.
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-21-2014 , 11:37   Re: get_flags
Reply With Quote #6

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.
__________________

Last edited by Bugsy; 01-21-2014 at 11:46.
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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