PublicConVar class and sv_tags

Official Announcements about Source.Python.
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

PublicConVar class and sv_tags

Postby satoon101 » Thu Sep 18, 2014 4:04 am

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>')
Image
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Fri Sep 19, 2014 12:41 pm

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.
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
L'In20Cible
Project Leader
Posts: 1534
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Fri Sep 19, 2014 2:23 pm

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.).
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri Sep 19, 2014 2:53 pm

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.
Image
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Fri Sep 19, 2014 3:41 pm

You made things clear. thanks, didn't know about it :)
My Github repositories:

Source.Python: https://github.com/backraw

Return to “News & Announcements”

Who is online

Users browsing this forum: No registered users and 3 guests