Nuclide
Software Development Kit for id Technology

Skill/Difficulty related APIs. More...

Detailed Description

Skill/Difficulty related APIs.

The skill/difficulty APIs are used to retrieve values that differ based on the selected game difficulty setting.

The setting is controlled via the skill console variable, which is represented by three different modes:

  1. Easy
  2. Medium
  3. Hard

The framework will then query the active skill variables. If a skill value isn't set, a fallback value (defined by your code, querying the API) will be used.

If the console variable skill is empty, or 0 it will assume the default setting of 2 - which is the medium difficulty.

You can technically query higher values then 3, just ensure you set them all up in your skill manifest.

Setting Skill Defaults

Default values are loaded from <gamedir>/cfg/skill_manifest.cfg.

The format looks like this:

set sk_starthealth1 "100"
set sk_starthealth2 "75"
set sk_starthealth3 "25"

While you can set these in the skill_manifest.cfg file directly, it is encouraged to put your own values in a separate config.
That way when people mod your game, they can inherit updates from the other, separate config without having to duplicate the variables every time your game updates.

Also, if there is no difference whatsoever between your different skill values, or you don't want to have a concept of difficulty in your game (but still allow players or server operators to change game variables defined through them) you can define a single skill variable in the configs too:

set sk_starthealth 100

Querying Skill Variables

Developers can query the variable set in the skill system using Skill_GetValue():

player.health = Skill_GetValue("starthealth", 75);
var playerAPI_t player
Definition: api_func.h:122
float Skill_GetValue(string, float)
Return a skill variable's value or return a defaultvalue if it's undefined.
Definition: skill.qc:49

And entity declarations can query skills like so:

entityDef some_def
{
"spawnclass" "TestClass"
"health" "skill:starthealth"
}
entityDefAPI_t entityDef
Definition: api.h:363

You will see most reference defs use them like so.

Functions

void Skill_Init (void)
 Called by Nuclide in init() before entities, or even EntityDef are initialized. More...
 
float Skill_GetValue (string, float)
 Return a skill variable's value or return a defaultvalue if it's undefined. More...
 
bool Skill_ParseConfig (string fileName)
 Parses a specified config file. More...
 

Function Documentation

◆ Skill_GetValue()

float Skill_GetValue ( string  variable,
float  defaultValue 
)

Return a skill variable's value or return a defaultvalue if it's undefined.

◆ Skill_Init()

void Skill_Init ( void  )

Called by Nuclide in init() before entities, or even EntityDef are initialized.

◆ Skill_ParseConfig()

bool Skill_ParseConfig ( string  fileName)

Parses a specified config file.

This should ideally be done before entities spawn. You are only allowed to parse files from a sub-directory such as gamedir/cfg/. Some directories are blocked by the engine for security reasons.