int
varibles managed by the server, one CVAR is mp_teamplay
.cvar_t blah blah
. Lets make a CVAR that controls the amount of armor you spawn with, so somewhere towards the top of the file add in:
cvar_t spawnarmoramt = {"mp_spawnarmoramt","50",FCVAR_SERVER };
This is one of the most important parts of a CVAR. The spawnarmoramt
is the real CVARs name. The mp_spawnarmoramt
is the console command to change the CVAR while in game. The 50
is the base value for the CVAR. Finally, the FCVAR_SERVER
is... erm... I guess that says its a server CVAR, just leave it alone. Now you need to scroll way down until you get to the GameDLLInit
function. Here you should see CVAR_REGISTER
all over. Add in:
CVAR_REGISTER (&spawnarmoramt);
This will declare your CVAR. Now we need to bust open multiplayer_gamerules.cpp and take a look at the PlayerSpawn
function. At the bottom of the function add in:
pPlayer->pev->armorvalue = CVAR_GET_FLOAT("mp_spawnarmoramt");
This is where everything comes into play. The CVAR_GET_FLOAT
function gets the value of the CVAR in quotes. So whatever mp_spawnarmoramt
is, the players armor value (pPlayer->pev->armorvalue
) will be set to that value. CVAR_GET_FLOAT
value can also be used in if
statements:
if (CVAR_GET_FLOAT("mp_spawnarmoramt") > 0)
That would check mp_spawnarmoramt
and if its higher than 0 then the if
statement would be executed. There you have it, the overwelming power of CVARs. Muwhahahaha!"mp_spawnarmoramt"
{
"Player Spawns w/ X Armor"
{ NUMBER 0.000000 999.000000 }
{ "50.000000" }
}
The first line is the CVAR name, then an openening bracket, then the next line is its title on the Advanced Options page. The line after that is what the value is (a BOOL, STRING, NUMBER, or LIST) and its allowed range. The last line is the base value. Now add in those CVARs and allow admins around the world to customize their servers! Good day!
You must log in to post a comment. You can login or register a new account.