Page 1 of 1

PublicConVar class and sv_tags

Posted: Thu Sep 18, 2014 4:04 am
by satoon101
Just posted a new release that includes the following changes (among a few others).

There is now a PublicConVar class that automatically makes a ConVar public on instantiation and removes it from being public when the plugin that instantiated it is unloaded. Previously, make_public didn't actually make the ConVar public, it just added the NOTIFY flag. Now, we can actually make the ConVar public. To use it, simply create the ConVar as you would any other, but make sure it is in the global scope. This is one typical way in which I would think most people would use this class:

Syntax: Select all

from cvars.public import PublicConVar
from plugins.info import PluginInfo

info = PluginInfo()
info.name = '<Project Name>'
info.author = '<Your Name>'
info.version = '<Version Number>'
info.basename = '<Actual Name of the Plugin>'
info.variable = info.basename + '_version'
info.url = '<Link to Repository>'
info.convar = PublicConVar(
info.variable, info.version, 0, info.name + ' Version')


This doesn't only need to be used for the plugin's version variable, but any variable you wish to be seen publicly from your plugin.


We have also included a ConVar instance of sv_tags to directly interact with its value. You should use it like it is a set object:

Syntax: Select all

from cvars.tags import sv_tags

sv_tags.add('<some name>')

def unload():
sv_tags.remove('<some name>')

Posted: Fri Sep 19, 2014 12:41 pm
by BackRaw
Pretty cool. How about exposing all sv_ and mp_ variables like that? Maybe in an ini file or dynamically if there's a way
I could contribute if it makes sense that way.

Posted: Fri Sep 19, 2014 2:23 pm
by L'In20Cible
BackRaw wrote:Pretty cool. How about exposing all sv_ and mp_ variables like that? Maybe in an ini file or dynamically if there's a way
I could contribute if it makes sense that way.

Where would be the benefit? The reason why it does makes sense for sv_tags is that the object is doing some work for you (splitting values, etc.).

Posted: Fri Sep 19, 2014 2:53 pm
by satoon101
Yeah, sv_tags does not function like any other cvar. If you "set" its value, it adds the string to its existing value. For all other cvars, just set them as you normally would.

Posted: Fri Sep 19, 2014 3:41 pm
by BackRaw
You made things clear. thanks, didn't know about it :)