AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get_pcvar_string and read_flags (https://forums.alliedmods.net/showthread.php?t=192756)

Liverwiz 08-13-2012 19:47

get_pcvar_string and read_flags
 
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!?

fysiks 08-13-2012 23:17

Re: get_pcvar_string and read_flags
 
Register cvars in plugin_init() unless there is a good reason not to do so.

Bugsy 08-14-2012 00:04

Re: get_pcvar_string and read_flags
 
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

ConnorMcLeod 08-14-2012 09:46

Re: get_pcvar_string and read_flags
 
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.

Liverwiz 08-15-2012 00:17

Re: get_pcvar_string and read_flags
 
Quote:

Originally Posted by fysiks (Post 1770938)
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 (Post 1770957)
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 (Post 1771170)
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?

ConnorMcLeod 08-15-2012 05:05

Re: get_pcvar_string and read_flags
 
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.

Liverwiz 08-15-2012 10:06

Re: get_pcvar_string and read_flags
 
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?

Arkshine 08-15-2012 10:15

Re: get_pcvar_string and read_flags
 
cvarlist ?

ConnorMcLeod 08-15-2012 10:41

Re: get_pcvar_string and read_flags
 
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.


All times are GMT -4. The time now is 05:47.

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