Nuclide
Software Development Kit for id Technology (BETA)
API: Client-side

Client-side Game-Logic APIs. More...

Detailed Description

Client-side Game-Logic APIs.

APIs used by HudC progs and the client progs exclusively.

HudC

By default, a HudC progs is loaded from <gamedir>/hud.dat.

If it is present, it is the chosen default. If it doesn't exist, Nuclide will not display a Heads-Up-Display. The game-specific code (non-Nuclide) can also choose to draw its own HUD by providing implementations of the following functions:

void HUD_Init(void);
void HUD_Draw(void);
void HUD_DrawSpectator(void);
void HUD_SendStat(string statName, string statValue);
float HUD_ClientInputFrame(float inputButtons);
bool HUD_ConsoleCommand(string fullCommandString);
void HUD_WeaponSwitched(string weaponName);

This will force that HUD, if implemented within the game's csprogs.dat.

Example HudC Progs Code

From base/src/client/hud.qc

#pragma PROGS_DAT "../../hud.dat"
#include "../../../src/client/api.h"
const float baseIconSize = 32.0;
const float baseIconPadding = 16.0;
font_s FONT_HUD;
var string g_ammoPic;
void
HUD_Init(void)
{
font.Load("fonts/font16.font", FONT_HUD);
g_ammoPic = 0;
}
void
HUD_Draw(void)
{
vector hud_mins = screen.HUDMins();
vector hud_size = screen.HUDSize();
vector hudSize = hud_size;
vector iconPos = hud_mins + (hudSize / 2);
iconPos[1] = (hudSize[1] - baseIconSize) - baseIconPadding;
string healthValue = ftos(player.GetHealth());
string armorValue = ftos(player.GetArmor());
string ammoValue = ftos(weapon.GetAmmo1());
if (weapon.AmmoRequired() == true) {
draw.RText([hudSize[0] - baseIconPadding - baseIconSize - baseIconPadding, iconPos[1]], ammoValue, FONT_HUD);
}
if (g_ammoPic != "") {
draw.Pic([hudSize[0] - baseIconPadding - baseIconSize, iconPos[1]], g_ammoPic, [baseIconSize, baseIconSize], [1,1,1], 1.0f);
}
draw.RText(iconPos + [-((baseIconSize/2) + (baseIconPadding/2)) - baseIconPadding, 0], healthValue, FONT_HUD);
draw.Pic(iconPos + [-((baseIconSize/2) + (baseIconPadding/2)), 0], "gfx/hud/health", [baseIconSize, baseIconSize], [1,1,1], 1.0f);
draw.Text(iconPos + [(baseIconSize/2) + (baseIconPadding/2) + baseIconSize + baseIconPadding, 0], armorValue, FONT_HUD);
draw.Pic(iconPos + [(baseIconSize/2) + (baseIconPadding/2), 0], "gfx/hud/armor", [baseIconSize, baseIconSize], [1,1,1], 1.0f);
}
void
HUD_WeaponSwitched(string weaponName)
{
g_ammoPic = entityDef.GetString(weaponName, "ammoIcon");
}
var surfaceAPI_t screen
Access surfaceAPI_t functions using this variable.
Definition: api_func.h:201
var fontAPI_t font
Access fontAPI_t functions using this variable.
Definition: api_func.h:188
var weaponAPI_t weapon
Access weaponAPI_t functions using this variable.
Definition: api_func.h:519
var drawAPI_t draw
Access drawAPI_t functions using this variable.
Definition: api_func.h:325
var playerAPI_t player
Access playerAPI_t functions using this variable.
Definition: api_func.h:421
entityDefAPI_t entityDef
Access entityDefAPI_t functions using this variable.
Definition: api.h:454
void Text(vector vecOrigin, string strText, font_s fnt)
Draw text on the screen at the desired position with a desired font.
void Pic(vector imagePos, string imageName, vector imageSize, vector imageColor, float imageAlpha, float imageFlags)
Draws an image from either the virtual file-system, or the materials.
void RText(vector vecOrigin, string strText, font_s fnt)
Right-aligned variant of Text().
string GetString(string defName, string keyName)
Returns the string value of a EntityDef key.
void Load(string fontDef, font_s &fntNew)
Load a desired .font definition into memory.
Representation of a font.
Definition: api_func.h:39
float GetHealth(void)
Get the current player's health value.
float GetArmor(void)
Get the current player's armor value.
vector HUDSize(void)
Returns the size of the HUD.
vector HUDMins(void)
Returns the top-left starting position of the HUD on the surface.
int GetAmmo1(entity weaponRef=__NULL__)
Returns if the current/active weapons present reserve ammo.
bool AmmoRequired(entity weaponRef=__NULL__)
Returns if the specified weapon item in the player's inventory requires ammo.

As you can see, you'll be primarily using functions from the drawAPI in order to display text and images on screen. You also can load external font definitions and query the display properties using the fontAPI and screenAPI

Classes

struct  fontAPI_t
 Font library. More...
 
struct  surfaceAPI_t
 Surface library. More...
 
struct  drawAPI_t
 Draw library. More...
 
struct  playerAPI_t
 Player library. More...
 
struct  weaponAPI_t
 Weapon library. More...
 
struct  spectatingAPI_t
 Spectating library. More...
 
struct  atlasPicAPI_t
 atlasPic library More...
 
struct  materialAPI_t
 material library More...
 

Variables

var fontAPI_t font
 Access fontAPI_t functions using this variable. More...
 
var surfaceAPI_t screen
 Access surfaceAPI_t functions using this variable. More...
 
var drawAPI_t draw
 Access drawAPI_t functions using this variable. More...
 
var playerAPI_t player
 Access playerAPI_t functions using this variable. More...
 
var weaponAPI_t weapon
 Access weaponAPI_t functions using this variable. More...
 
var spectatingAPI_t spectating
 Access spectatingAPI_t functions using this variable. More...
 
var atlasPicAPI_t atlasPic
 Access atlasPicAPI_t functions using this variable. More...
 
var materialAPI_t material
 Access atlasPicAPI_t functions using this variable. More...
 

Variable Documentation

◆ atlasPic

var atlasPicAPI_t atlasPic

Access atlasPicAPI_t functions using this variable.

◆ draw

var drawAPI_t draw

Access drawAPI_t functions using this variable.

◆ font

var fontAPI_t font

Access fontAPI_t functions using this variable.

◆ material

var materialAPI_t material

Access atlasPicAPI_t functions using this variable.

◆ player

var playerAPI_t player

Access playerAPI_t functions using this variable.

◆ screen

var surfaceAPI_t screen

Access surfaceAPI_t functions using this variable.

◆ spectating

var spectatingAPI_t spectating

Access spectatingAPI_t functions using this variable.

◆ weapon

var weaponAPI_t weapon

Access weaponAPI_t functions using this variable.