Raised This Month: $ Target: $400
 0% 

get_pcvar_string and read_flags


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 08-13-2012 , 19:47   get_pcvar_string and read_flags
Reply With Quote #1

Ok....i'm trying to use flags for the pcvars and it isn't working.

Here is my code....
PHP Code:
new spawn_pcvar
new cvarBits

#define ON (1 << 0)  // a
#define BACKPACK (1 << 1)  // b
#define CLIP (1 << 2)  // c

 
public plugin_precache()
 {
     
spawn_pcvar register_cvar("source_spawn""abc")
    new 
szFlags[10]
        
get_pcvar_string(spawn_pcvarszFlagscharsmax(szFlags) )
    
cvarBits read_flags(szFlags)
}

// Then to access....
    
if(is_user_bot(id) || !is_user_alive(id) || !(cvarBits ON))
    {
        new 
f[10]
        
get_pcvar_string(spawn_pcvarfcharsmax(f) )
        
client_print(idprint_console"The plugin is off %d, %s"cvarBitsf)
        return 
HAM_IGNORED
    

Always prints in console
Code:
The plugin is off 65536, 1
No matter what i put in for the cvar.

Am i missing something?


EDIT: aaannnnddd.....an episode of wtf theater....
It just doesn't recognize "source_spawn" as a cvar. When i changed the cvar name, it started working again.
wtf!?
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 08-13-2012 at 20:10.
Liverwiz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-13-2012 , 23:17   Re: get_pcvar_string and read_flags
Reply With Quote #2

Register cvars in plugin_init() unless there is a good reason not to do so.
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-14-2012 , 00:04   Re: get_pcvar_string and read_flags
Reply With Quote #3

65536 is 1 << 16, not sure if there is more to your code than what you are showing.

Are you using this flag?

#define ADMIN_LEVEL_E (1<<16) /* flag "q" */

PHP Code:
public plugin_init() 
{
    new 
spawn_pcvar register_cvar("source_spawn""abc")
    
    new 
szFlags[10]
    
get_pcvar_string(spawn_pcvarszFlagscharsmax(szFlags) )
    new 
cvarBits read_flags(szFlags)
    
server_print("The plugin is off %d"cvarBits )

I get this, which is correct.
Code:
The plugin is off 7
1<<0 | 1<<1 | 1<<2 = 111 = 7
__________________

Last edited by Bugsy; 08-14-2012 at 00:16.
Bugsy is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-14-2012 , 09:46   Re: get_pcvar_string and read_flags
Reply With Quote #4

client_print(id, print_console, "The plugin is off %d, %s", cvarBits, f)

If last value is "1" it means you have set the cvar to 1 instead of letters, read_flags can't work properly on this, also, you should be aware that cvar in converted only at map load, so if you change the cvar, restart the map.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 08-15-2012 , 00:17   Re: get_pcvar_string and read_flags
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
Register cvars in plugin_init() unless there is a good reason not to do so.
I put it there as part of my debug process. It is now in plugin_init.

Quote:
Originally Posted by Bugsy View Post
65536 is 1 << 16, not sure if there is more to your code than what you are showing.

Are you using this flag?

#define ADMIN_LEVEL_E (1<<16) /* flag "q" */

PHP Code:
public plugin_init() 
{
    new 
spawn_pcvar register_cvar("source_spawn""abc")
    
    new 
szFlags[10]
    
get_pcvar_string(spawn_pcvarszFlagscharsmax(szFlags) )
    new 
cvarBits read_flags(szFlags)
    
server_print("The plugin is off %d"cvarBits )

I get this, which is correct.
Code:
The plugin is off 7
1<<0 | 1<<1 | 1<<2 = 111 = 7
Yes, 7 is what i get when it is running correctly. And no, i didn't have any other code that affected the cvars. Its all just things that the plugin does. (which was tested to run properly before i switched to flags) It has nothing that has to do with admin flags, or the letter Q (16th letter in the 0-based alphabet) lol. It seems like just a freak occurance (or plugin overlaps) with the CVAR name "source_spawn"
Quote:
Originally Posted by ConnorMcLeod View Post
client_print(id, print_console, "The plugin is off %d, %s", cvarBits, f)

If last value is "1" it means you have set the cvar to 1 instead of letters, read_flags can't work properly on this, also, you should be aware that cvar in converted only at map load, so if you change the cvar, restart the map.
I knew that. Which is why i thought it was so weird and had to ask. I'm also aware that it only works on map load....and i tried changing the cvar in game using amx_cvar source_spawn abc then changing the map. But it gave the same bit number with 'abc' as the string. Also....very weird. But changing the cvar name to a different name made it work properly. And now its running and i have FCVAR_SPONLY flag in the register_cvar declaration.

To everyone....any ideas why source_spawn might give strange results? Its probably just my server because bugsy tests it to run fine....
Anyone know a way to print all cvars registered in the server?
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-15-2012 , 05:05   Re: get_pcvar_string and read_flags
Reply With Quote #6

The only reason i can see is that the cvar is written in some file such as amxx.cfg, or is also created/changed in another plugin.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 08-15-2012 , 10:06   Re: get_pcvar_string and read_flags
Reply With Quote #7

I thought that too...but let me ask you. Does order in plugins.ini give a CVAR precedence like plugin commands? i.e. if a CVAR is defined in two plugins, does the one closest to the top get to keep its value while the other one malfunctions?

And is there a way for me to print all CVARs used in all plugins?
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-15-2012 , 10:15   Re: get_pcvar_string and read_flags
Reply With Quote #8

cvarlist ?
__________________
Arkshine is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-15-2012 , 10:41   Re: get_pcvar_string and read_flags
Reply With Quote #9

Also if you run that plugin with another cvar name, you can check (after a real reboot of the server), if the previous cvar still exist, that would mean another plugin is creating it.
If it doesn't exist, and if a plugin tries to use it, could be some error logs depending on how that plugin handles the cvar manipulation.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply


Thread Tools
Display Modes

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 05:47.


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