How to use Cvars

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 417
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

How to use Cvars

Postby decompile » Sun May 22, 2016 9:43 pm

Hey,

Im still having issues how to use cvars in source python, wiki couldnt help me much, thats why im asking here to be sure.

1. How can I get a cvar?

Lets say mp_timelimit;float

2. How can I set/change a cvar value?

3. How can I create a cvar?

lets say xx_version == 1.0.1
User avatar
Ayuto
Project Leader
Posts: 2209
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: How to use Cvars

Postby Ayuto » Sun May 22, 2016 10:15 pm

It's quite easy! :)

Syntax: Select all

from cvars import ConVar

# Get an existing ConVar
mp_timelimit = ConVar('mp_timelimit')
print(mp_timelimit.get_float())

# Create a new ConVar
my_convar = ConVar('my_convar')

# Set a ConVar
my_convar.set_int(10)
decompile
Senior Member
Posts: 417
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: How to use Cvars

Postby decompile » Sun May 22, 2016 10:30 pm

Thank you!
User avatar
satoon101
Project Leader
Posts: 2703
Joined: Sat Jul 07, 2012 1:59 am

Re: How to use Cvars

Postby satoon101 » Mon May 23, 2016 12:28 am

Also, to create a ConVar with the config package:
http://builds.sourcepython.com/job/Sour ... onfig.html

That needs some updating, but should suffice.

And, for a public versioning ConVar:
http://builds.sourcepython.com/job/Sour ... blicConVar
Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 93 guests