Adding a Console Variable

 

I was putting a few new cvars into my code recently, and had to go and look at a tut to see how it was done. That tut wasn't on CVARS so I decided to put one together, partialy to make my own life easier when i wanted to do it again.


This is a fairly easy one. No new files. It does require a few changes to a few files though. The cvar I will be adding will be called teamplay Simply chage it to whatever you want your cvar to be

The first file anything will be added to is g_local.h Big surprise isn't it?.

Find the line which reads

extern cvar_t *maxclients;

And just under it put

extern cvar_t *teamplay;

extern means it isn't defined here but that it exists and can be used. As this is in g_local.h it can be used anywhere in the source.

Next open up g_main.c and find the line that reads

cvar_t *sv_cheats;

just under it insert

cvar_t *teamplay;

Thats it defined. now we need to initilize it. open g_save.c and find the line

bob_roll = gi.cvar ("bob_roll", "0.002", 0);

And yet again insert this line under it

teamplay = gi.cvar ("teamplay", "1",CVAR_SERVERINFO|CVAR_LATCH);

CVAR_SERVERINFO|CVAR_LATCH makes it server information and makes it latch (stick around until the server restarts). I'm not going to list the flags you can use. the number is the default value of the cvar


Thats the basics of adding a cvar., heres how to use it

check the value of coopexit->value in code where you want to check the cvar. easy don't you think?


Skunkworks Tutorials