Raised This Month: $ Target: $400
 0% 

Global Shared CVARS - How To ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kurian
Member
Join Date: Aug 2005
Old 06-05-2007 , 03:23   Global Shared CVARS - How To ?
Reply With Quote #1

I have multiple plugins that share the same CVAR. They function independent of each other.

Any of these plugins can be used together so the problem arises when it comes to the CVAR being registered for the first time.

How do I register a CVAR before hand so that it is available for all plugins to use.

Right now I am doing this in all the plugins (Actually this block is being commonly included from a customized amxmisc.inc)

PHP Code:
    new amx_override_spec get_cvar_pointer("amx_override_spec")
    
    if (!
amx_override_spec)
    {
        
amx_override_spec register_cvar("amx_override_spec","1")
    } 
Basically every plugin checks if the CVAR is already declared and if not declares it. Any further plugins will see the declared CVAR. This isn't a function that is going to be executed repeatedly so the get_cvar_pointer inefficiency is not a problem.

Is there any way to declare a CVAR before hand so that its existence need not be checked each time. I don't really want to create a dummy plugin to do this. And even so it would have to be the FIRST entry in plugins.ini so that it gets executed first.

Is there any command or anything could be placed in amxx.cfg to create a CVAR ?
__________________
[IMG]http://img267.**************/img267/8526/userbarjg9.gif[/IMG]
kurian is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 06-05-2007 , 07:02   Re: Global Shared CVARS - How To ?
Reply With Quote #2

I do believe I've seen something like a cvar, command manager round here but I think they might be a bit much for what you need. Just checking cvars in plugin_init() is better since server load is at it's minimum.

Also AMXX does NOT provide any mechanism of pre-declaring stand-alone cvars (it has something to do with cvar registration and owner plugin). Moving forward, you could edit an always-active amxx plugin and create the cvar there, leaving the rest of the plugins to just access it.

EDIT: Or you could declare the cvar pointer as public and thus fully exposing it to other plugins.

Last edited by _Master_; 06-05-2007 at 07:06.
_Master_ is offline
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 06-05-2007 , 08:33   Re: Global Shared CVARS - How To ?
Reply With Quote #3

Maybe I'm completely missing your problem, but..

Code:
register_cvar("a_cvar", "1");
new cvar_pointer = get_cvar_pointer("a_cvar");
register_cvar() already checks to see if the cvar has been declared previously. Whether this is better is debatable because if the cvar does not already exist then you've just discarded the return value which you will then be interested in.

If these plugins are only for personal use then why not register the cvar in admincmd.sma or one of the other base add-ons..? In fact, why is this such an issue in the first place? plugin_init() should be the last place you look at optimising. The rest of the code should be perfect before you even consider this.

Last edited by Lee; 06-05-2007 at 09:18.
Lee is offline
pRED*
Join Date: Dec 2006
Old 06-05-2007 , 17:14   Re: Global Shared CVARS - How To ?
Reply With Quote #4

You could register it in one of the plugins plugin_precache..

Then it will already be there in all of the plugin_init's, so you wont need to check if it exsits.
pRED* is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 06-05-2007 , 21:15   Re: Global Shared CVARS - How To ?
Reply With Quote #5

Again:
Just doing this in plugin_init() is ok !!! The overload is irrelevalnt !!!
_Master_ is offline
sawce
The null pointer exception error and virtual machine bug
Join Date: Oct 2004
Old 06-06-2007 , 00:23   Re: Global Shared CVARS - How To ?
Reply With Quote #6

Lee is completely correct.

It doesn't matter how many plugins register a cvar, if it has already been registered when another call is made, register_cvar() will act basically like get_cvar_pointer(), and give you the pointer to it for use with pcvars. The value of the already existing cvar will not be changed by subsequent calls to it via register_cvar().

Additionally, no plugins "own" a cvar. It is open for anything within the engine to use freely.

There is no need whatsoever to make a central repository of cvar pointers, or exposing cvar pointers via public variables.
__________________
fyren sucks

Last edited by sawce the snail; 06-06-2007 at 00:29.
sawce is offline
kurian
Member
Join Date: Aug 2005
Old 06-06-2007 , 08:15   Re: Global Shared CVARS - How To ?
Reply With Quote #7

Quote:
Originally Posted by _Master_ View Post
Again:
Just doing this in plugin_init() is ok !!! The overload is irrelevalnt !!!
Actually I am making a modified include file that adds functionality to all existing plugins. All you have to do is recompile all your current plugins and i dont want people to have to write code into their existing plugins. I just want them to open the SMA and hit recompile. Thats why the entire content of this procedure MUST be in the include file.

This is the feature I was making

http://forums.alliedmods.net/showthread.php?t=55956
__________________
[IMG]http://img267.**************/img267/8526/userbarjg9.gif[/IMG]
kurian is offline
kurian
Member
Join Date: Aug 2005
Old 06-06-2007 , 08:23   Re: Global Shared CVARS - How To ?
Reply With Quote #8

Quote:
Originally Posted by sawce View Post
It doesn't matter how many plugins register a cvar, if it has already been registered when another call is made, register_cvar() will act basically like get_cvar_pointer(), and give you the pointer to it for use with pcvars. The value of the already existing cvar will not be changed by subsequent calls to it via register_cvar().
So what your saying is that I can simply write

Code:
amx_override_spec = register_cvar("amx_override_spec","1")
So the first time the function is called, the CVAR will be created and its value will be set to 1. Then suppose the user changes the value to 0 by typing amx_override_spec 0 in console. Then if the function is executed again in another plugin, it will simply return a CVAR pointer and the value will still remain at 0 even though register_cvar re initializes it with a value of 1 ?


If so then this seems to be the best option. Because I CANNOT add any code in the plugins themselves, everything must be contained in the include file.
__________________
[IMG]http://img267.**************/img267/8526/userbarjg9.gif[/IMG]
kurian is offline
sawce
The null pointer exception error and virtual machine bug
Join Date: Oct 2004
Old 06-06-2007 , 10:19   Re: Global Shared CVARS - How To ?
Reply With Quote #9

Quote:
Originally Posted by kurian View Post
So what your saying is that I can simply write

Code:
amx_override_spec = register_cvar("amx_override_spec","1")
So the first time the function is called, the CVAR will be created and its value will be set to 1. Then suppose the user changes the value to 0 by typing amx_override_spec 0 in console. Then if the function is executed again in another plugin, it will simply return a CVAR pointer and the value will still remain at 0 even though register_cvar re initializes it with a value of 1 ?


If so then this seems to be the best option. Because I CANNOT add any code in the plugins themselves, everything must be contained in the include file.
Correct.
__________________
fyren sucks
sawce 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:41.


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