cvar_t true_cvar_name = { " command_for_cvar ", "current_value" };
cvar_t testcvar = { " test_cvar ", "0" };
// testcvar - Name Of Cvar || test_cvar - Command For Cvar || 0 - Value of 0
before or after
cvar_t displaysoundlist = { " displaysoundlist ", "0" };
cvar_t testcvar = { " test_cvar ", "0" };
cvar_t testcvar = { " test_cvar ", "0", Flag };
So before you add a flag, check on the list to make sure it's the flag you want to use(taken from common/cvardef.h):
FCVAR_ARCHIVE
- set to cause it to be saved to vars.rcFCVAR_USERINFO
- changes the client's info stringFCVAR_SERVER
- notifies players when changedFCVAR_EXTDLL
- defined by external DLLFCVAR_CLIENTDLL
- defined by the client DLLFCVAR_PROTECTED
- It's a server Cvar, but we don't send the data since it's a password, etc. Sends 1 if it's not bland/zero, 0 otherwise as value.FCVAR_SPONLY
- This Cvar cannot be changed by clients connected to a multiplayer server.FCVAR_PRINTABLEONLY
- This Cvar's string cannot contain unprintable characters (e.g., used for player name etc).FCVAR_UNLOGGED
- If this is a FCVAR_SERVER, don't log changes to the log file / console if we are creating a logcvar_t displaysoundlist = { " displaysoundlist ", "0", FCVAR_SERVER };
// Only the host can use this command
cvar_t displaysoundlist = { " displaysoundlist ", "0", FCVAR_SERVER | FCVAR_UNLOGGED };
// Only the host can use this command and it's not logged.
Note: The Cvar can be changed by all players, by default. Now since this is the server DLL, the Cvar will effect everyone. So if wish to use the Cvar for the server only, make sure to use the Server-only flag (FCVAR_SERVER
) on.
void GameDLLInit( void )
Now within the { }
we are going to register our Cvar with:
CVAR_REGISTER (&testcvar);
Notice we are using the Cvar name and not the Cvar command.
extern cvar_t testcvar;
Then in the file you're going to include your Cvar, make sure to add this at the top:
#include "game.h"
int number = CVAR_GET_FLOAT( "testcvar" );
ALERT(at_console," Int Number : %d n ", number );
float limit = CVAR_GET_FLOAT( "testcvar" );
ALERT(at_console," Float Number : %d n ", limit );
ALERT(at_console," String Name : %d n ", CVAR_GET_STRING( "testcvar" ) );
if (testcvar.value == X)
// If value is X , then do this
if (testcvar.value > X)
// If value of x is greater then the value of the cvar, then do something.
if (testcvar.value < X)
// If value of x is less then the value of the cvar, then do something.
if (testcvar.value)
// If cvar is greater then 0, then do this
Note: You can use "else", incase you want something else to happen, if the Cvar value is not what it needs to be. Example:
if (testcvar.value) {
// Do Something
} else {
// Something else
}
void CHud :: Init( void )
Before we create the Cvar, there is something you need to know. Since the client Cvars are different, you don't have the ability to have the Cvar name and a command name, you just get 1 name. In other words, whatever your Cvar name is, that's the console command to change the value. Let's add the following (in CHud::Init
):
CVAR_CREATE ("testcvar", "0", 0);
Notice the difference, between the client and server Cvar? In case you don't:
CVAR_CREATE ("name_of_cvar_and_command_name", "value", flags);
Yes, the flags are the same as the server DLL, so in case you don't remember how to do the flags, scroll up to Part A, Step B.
CVAR_GET_FLOAT
to get a float value or a int value.CVAR_GET_STRING
to get the string value.
int number = CVAR_GET_FLOAT( "testcvar" );
gEngfuncs.Con_Printf (" Int Number : %d \n ", number );
float limit = CVAR_GET_FLOAT( "testcvar" );
gEngfuncs.Con_Printf (" Float Number : %d \n ", limit );
gEngfuncs.Con_Printf (" String Name : %d \n ", CVAR_GET_STRING( "testcvar" ) );
if (testcvar.value == X)
// If value is X , then do this
if (testcvar.value > X)
// If value of x is greater then the value of the cvar, then do something.
if (testcvar.value < X)
// If value of x is less then the value of the cvar, then do something of all the servers Cvars.
if (testcvar.value)
// If cvar is not 0, then do this
Note: You can do "else", incase you want something else to happen, if the Cvar value is not what it needs to be. Example:
if (testcvar.value) {
// Do Something
} else {
// Something else
}
You must log in to post a comment. You can login or register a new account.