skill.h
. This file holds all the entries for the skilldata_t
struct, used for gSkillData
. You'll notice a bunch of float
variables declared here. These are the variables which are assigned a value equal to that of a corresponding cvar, and used in setting up a monster's health (or whatever other property).float somemonsterHealth;
There, now we have our variable, next we need to actually give the variable the value of the cvar that corresponds to it. Open up gamerules.cpp
and find the RefreshSkillData
function. In there you'll see all the variables from skill.h
being given values. So, somewhere in the jumble of code, add in:
// Some Monster
gSkillData.somemonsterHealth = GetSkillCvar( "sk_somemonster_health");
This is giving our somemonsterHealth
variable the value of the cvar sk_somemonster_health
. The GetSkillCvar
function returns a different value depending on the difficulty level of the game. So, now we need to make the cvar our entry is trying to use.game.cpp
. You should see a bunch of cvar_t
s declared. Scroll down a while until you find the scientist entry. Below that, let's add in our three cvars.
// Scientist
cvar_t sk_somemonster_health1 = {"sk_somemonster_health1","0"};
cvar_t sk_somemonster_health2 = {"sk_somemonster_health2","0"};
cvar_t sk_somemonster_health3 = {"sk_somemonster_health3","0"};
Now, time to explain the way this works. Each cvar used for a skill.h
entry actually has 3 different cvars, one for each skill. A 1 at the end of the cvar name means it's for easy difficulty, 2 for medium, 3 for hard. The GetSkillCvar
function compares the end number to the current difficulty, and returns the value of the proper cvar so that the corresponding skill.h
entry is given the right value. You'll notice all there are set to 0. This is the actual purpose of the skill.cfg, it sets up all the values for the cvars.CVAR_REGISTER
functions. We have to add our own in here somewhere now so the engine recognizes them as cvars. So...
// Some Monster
CVAR_REGISTER ( &sk_somemonster_health1 );
CVAR_REGISTER ( &sk_somemonster_health2 );
CVAR_REGISTER ( &sk_somemonster_health3 );
There, now our cvars are registered with the engine. Only one more thing left for programming. If you ever want to use the skill.h
entry we just created, you need to:skill.h
included in whichever .cpp file you'll be using gSkillData in.
#include "skill.h"
Then, somewhere in the code.
pev->health = gSkillData.somemonsterHealth;
There, now the value of pev->health will be set to our new entry. Usually a snippet of code like that will be in a monster's Spawn
function.sk_somemonster_health1 "50"
sk_somemonster_health2 "50"
sk_somemonster_health3 "60"
Of course you can use your own values, rather than 50 and 60. I hope you've learned something new today. Now, then, get out there and add those skill entries!
You must log in to post a comment. You can login or register a new account.