Nuclide
Software Development Kit for id Technology (BETA)
api.h
1/*
2 * Copyright (c) 2016-2025 Vera Visions LLC.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16
17#define bool float
18#define true 1
19#define false 0
20
37typedef struct
38{
42 string NameForNum(int ammoID);
46 int NumForName(string ammoName);
50 int MaxForName(string ammoName);
54 int MaxForNum(int ammoID);
55} ammoAPI_t;
56
67typedef struct
68{
73 string GetString(string cvarName);
78 int GetInteger(string cvarName);
83 float GetFloat(string cvarName);
88 bool GetBool(string cvarName);
93 vector GetVector(string cvarName);
98 void SetString(string cvarName, string setValue);
103 void SetInteger(string cvarName, int setValue);
108 void SetBool(string cvarName, bool setValue);
113 void SetFloat(string cvarName, float setValue);
118 void SetVector(string cvarName, vector setValue);
119} cvarAPI_t;
120
124typedef struct
125{
130 string GetString(string serverKey);
135 int GetInteger(string serverKey);
140 float GetFloat(string serverKey);
145 bool GetBool(string serverKey);
150 vector GetVector(string serverKey);
155 void SetString(string serverKey, string setValue);
160 void SetInteger(string serverKey, int setValue);
165 void SetBool(string serverKey, bool setValue);
170 void SetFloat(string serverKey, float setValue);
175 void SetVector(string serverKey, vector setValue);
177
181typedef struct
182{
188 string GetString(entity clientEnt, string userKey);
194 int GetInteger(entity clientEnt, string userKey);
200 float GetFloat(entity clientEnt, string userKey);
206 bool GetBool(entity clientEnt, string userKey);
212 vector GetVector(entity clientEnt, string userKey);
218 void SetString(entity clientEnt, string userKey, string setValue);
224 void SetInteger(entity clientEnt, string userKey, int setValue);
230 void SetBool(entity clientEnt, string userKey, bool setValue);
236 void SetFloat(entity clientEnt, string userKey, float setValue);
242 void SetVector(entity clientEnt, string userKey, vector setValue);
244
248typedef struct
249{
253 string Type(string weaponDef);
257 int StartAmmo(string weaponDef);
261 int MaxAmmo(string weaponDef);
265 bool IsSemiAuto(string weaponDef);
266
270 string InventoryType(string weaponDef);
274 float FireTime(string weaponDef);
278 int ClipSize(string weaponDef);
282 string Class(string weaponDef);
286 bool IsClipOnly(string weaponDef);
290 bool IsDetonationTimed(string weaponDef);
292
296typedef struct
297{
303 int TeamCount(void);
306 int OpenTeamCount(void);
310 vector Color(int teamID);
314 string Name(int teamID);
318 int Score(int teamID);
322 string SpawnPoint(int teamID);
326 int NumPlayers(int teamID);
330 int NumAlivePlayers(int teamID);
334 int NumDeadPlayers(int teamID);
338 int TotalDeaths(int teamID);
343 int TotalFrags(int teamID);
347 bool Valid(int teamID);
348
352 void AddScore(int teamID, int addedScore);
356 void SetScore(int teamID, int scoreValue);
360 entity RandomPlayer(int teamID);
361
362
369 void SetUp(int teamID, string teamTitle, vector teamColor, bool openTeam);
370
371
377 void AddClass(int teamID, string classType);
378
379
383 int TotalClasses(int teamID);
384
389 string ClassForIndex(int teamID, int classIndex);
390
397 void SetSpawnPoint(int teamID, string spawnPointEntityClassname);
398} teamAPI_t;
399
403typedef struct
404{
410 string GetString(string defName, string keyName);
416 int GetInteger(string defName, string keyName);
422 float GetFloat(string defName, string keyName);
428 bool GetBool(string defName, string keyName);
434 vector GetVector(string defName, string keyName);
439typedef struct
440{
447 float Model(string pathToModel);
448
456 float Sound(string soundDef);
457
466 float Particle(string particleEffect);
467
474 bool Entity(string className);
479typedef struct
480{
481 void Play(string soundDef, float level = 75, float pitch = 100, float volume = 100, float channel = CHAN_AUTO);
482} soundAPI_t;
485typedef struct
486{
490 bool AI(entity entityToCheck);
494 bool Alive(entity entityToCheck);
498 bool GodMode(entity entityToCheck);
502 bool Client(entity entityToCheck);
506 bool Player(entity entityToCheck);
510 bool Sentient(entity entityToCheck);
514 bool Bot(entity entityToCheck);
515} isAPI_t;
518typedef struct
519{
524 entity Item(entity lastItem);
525
526
531 entity Weapon(entity lastWeapon);
532
533
538 entity Actor(entity lastActor);
539
540
545 entity Player(entity lastPlayer);
546} nextAPI_t;
549typedef string decl;
552typedef struct
553{
556 decl New(void);
557
563 string GetString(decl declHandle, string keyName);
569 int GetInteger(decl declHandle, string keyName);
575 float GetFloat(decl declHandle, string keyName);
581 bool GetBool(decl declHandle, string keyName);
587 vector GetVector(decl declHandle, string keyName);
588
595 void AddKey(decl declHandle, string keyName, string setValue);
596
601 void RemoveKey(decl declHandle, string keyName);
602
606 void Delete(decl declHandle);
607} declAPI_t;
608
609declAPI_t declManager; // end of shared
611
612void
613setorigin_safe(entity target, vector testorg)
614{
615 for (int i = 0; i < 16; i++) {
616 tracebox(testorg, target.mins, target.maxs, testorg, MOVE_NORMAL, target);
617
618 if (!trace_startsolid) {
619 break;
620 }
621
622 testorg[2] += 1.0;
623 }
624
625 setorigin(target, testorg);
626}
627
628__variant
629linkToSharedProgs(string funcName)
630{
631 static void empty(void)
632 {
633 print("Called unimplemented shared API call.\n");
634 breakpoint();
635 }
636
637 float func = externvalue( 0, funcName);
638
639 if (func) {
640 return ((__variant)func);
641 } else {
642 return (empty);
643 }
644}
645
646void
647_shared_main(void)
648{
649 ammo.NameForNum = linkToSharedProgs("SHPF_ammo_NameForNum");
650 ammo.NumForName = linkToSharedProgs("SHPF_ammo_NumForName");
651 ammo.MaxForName = linkToSharedProgs("SHPF_ammo_MaxForName");
652 ammo.MaxForNum = linkToSharedProgs("SHPF_ammo_MaxForNum");
653
654 cvars.SetString = linkToSharedProgs("SHPF_cvars_SetString");
655 cvars.SetBool = linkToSharedProgs("SHPF_cvars_SetBool");
656 cvars.SetInteger = linkToSharedProgs("SHPF_cvars_SetInteger");
657 cvars.SetFloat = linkToSharedProgs("SHPF_cvars_SetFloat");
658 cvars.SetVector = linkToSharedProgs("SHPF_cvars_SetVector");
659 cvars.GetString = linkToSharedProgs("SHPF_cvars_GetString");
660 cvars.GetInteger = linkToSharedProgs("SHPF_cvars_GetInteger");
661 cvars.GetBool = linkToSharedProgs("SHPF_cvars_GetBool");
662 cvars.GetFloat = linkToSharedProgs("SHPF_cvars_GetFloat");
663 cvars.GetVector = linkToSharedProgs("SHPF_cvars_GetVector");
664
665 declManager.New = linkToSharedProgs("SHPF_declManager_New");
666 declManager.GetFloat = linkToSharedProgs("SHPF_declManager_GetFloat");
667 declManager.GetString = linkToSharedProgs("SHPF_declManager_GetString");
668 declManager.GetVector = linkToSharedProgs("SHPF_declManager_GetVector");
669 declManager.GetBool = linkToSharedProgs("SHPF_declManager_GetBool");
670 declManager.AddKey = linkToSharedProgs("SHPF_declManager_AddKey");
671 declManager.RemoveKey = linkToSharedProgs("SHPF_declManager_RemoveKey");
672 declManager.Delete = linkToSharedProgs("SHPF_declManager_Delete");
673
674 userinfo.SetString = linkToSharedProgs("SHPF_userinfo_SetString");
675 userinfo.SetBool = linkToSharedProgs("SHPF_userinfo_SetBool");
676 userinfo.SetInteger = linkToSharedProgs("SHPF_userinfo_SetInteger");
677 userinfo.SetFloat = linkToSharedProgs("SHPF_userinfo_SetFloat");
678 userinfo.SetVector = linkToSharedProgs("SHPF_userinfo_SetVector");
679 userinfo.GetString = linkToSharedProgs("SHPF_userinfo_GetString");
680 userinfo.GetInteger = linkToSharedProgs("SHPF_userinfo_GetInteger");
681 userinfo.GetBool = linkToSharedProgs("SHPF_userinfo_GetBool");
682 userinfo.GetFloat = linkToSharedProgs("SHPF_userinfo_GetFloat");
683 userinfo.GetVector = linkToSharedProgs("SHPF_userinfo_GetVector");
684
685 serverinfo.SetString = linkToSharedProgs("SHPF_serverinfo_SetString");
686 serverinfo.SetBool = linkToSharedProgs("SHPF_serverinfo_SetBool");
687 serverinfo.SetInteger = linkToSharedProgs("SHPF_serverinfo_SetInteger");
688 serverinfo.SetFloat = linkToSharedProgs("SHPF_serverinfo_SetFloat");
689 serverinfo.SetVector = linkToSharedProgs("SHPF_serverinfo_SetVector");
690 serverinfo.GetString = linkToSharedProgs("SHPF_serverinfo_GetString");
691 serverinfo.GetInteger = linkToSharedProgs("SHPF_serverinfo_GetInteger");
692 serverinfo.GetBool = linkToSharedProgs("SHPF_serverinfo_GetBool");
693 serverinfo.GetFloat = linkToSharedProgs("SHPF_serverinfo_GetFloat");
694 serverinfo.GetVector = linkToSharedProgs("SHPF_serverinfo_GetVector");
695
696 teams.BestAutoJoinTeam = linkToSharedProgs("SHPF_teams_BestAutoJoinTeam");
697 teams.TeamCount = linkToSharedProgs("SHPF_teams_TeamCount");
698 teams.OpenTeamCount = linkToSharedProgs("SHPF_teams_OpenTeamCount");
699 teams.Color = linkToSharedProgs("SHPF_teams_Color");
700 teams.Name = linkToSharedProgs("SHPF_teams_Name");
701 teams.Score = linkToSharedProgs("SHPF_teams_Score");
702 teams.SpawnPoint = linkToSharedProgs("SHPF_teams_SpawnPoint");
703 teams.NumPlayers = linkToSharedProgs("SHPF_teams_NumPlayers");
704 teams.NumAlivePlayers = linkToSharedProgs("SHPF_teams_NumAlivePlayers");
705 teams.NumDeadPlayers = linkToSharedProgs("SHPF_teams_NumDeadPlayers");
706 teams.TotalDeaths = linkToSharedProgs("SHPF_teams_TotalDeaths");
707 teams.TotalFrags = linkToSharedProgs("SHPF_teams_TotalFrags");
708 teams.Valid = linkToSharedProgs("SHPF_teams_Valid");
709 teams.RandomPlayer = linkToSharedProgs("SHPF_teams_RandomPlayer");
710 teams.TotalClasses = linkToSharedProgs("SHPF_teams_TotalClasses");
711 teams.ClassForIndex = linkToSharedProgs("SHPF_teams_ClassForIndex");
712
713 /* server */
714 teams.AddScore = linkToSharedProgs("SHPF_teams_AddScore");
715 teams.SetScore = linkToSharedProgs("SHPF_teams_SetScore");
716 teams.SetUp = linkToSharedProgs("SHPF_teams_SetUp");
717 teams.AddClass = linkToSharedProgs("SHPF_teams_AddClass");
718 teams.SetSpawnPoint = linkToSharedProgs("SHPF_teams_SetSpawnPoint");
719
720 precache.Model = linkToSharedProgs("SHPF_precache_Model");
721 precache.Sound = linkToSharedProgs("SHPF_precache_Sound");
722 precache.Particle = linkToSharedProgs("SHPF_precache_Particle");
723 precache.Entity = linkToSharedProgs("SHPF_precache_Entity");
724
725 soundKit.Play = linkToSharedProgs("SHPF_sounds_Play");
726
727 weaponInfo.Type = linkToSharedProgs("SHPF_weaponInfo_Type");
728 weaponInfo.StartAmmo = linkToSharedProgs("SHPF_weaponInfo_StartAmmo");
729 weaponInfo.MaxAmmo = linkToSharedProgs("SHPF_weaponInfo_MaxAmmo");
730 weaponInfo.IsSemiAuto = linkToSharedProgs("SHPF_weaponInfo_IsSemiAuto");
731 weaponInfo.InventoryType = linkToSharedProgs("SHPF_weaponInfo_InventoryType");
732 weaponInfo.FireTime = linkToSharedProgs("SHPF_weaponInfo_FireTime");
733 weaponInfo.ClipSize = linkToSharedProgs("SHPF_weaponInfo_ClipSize");
734 weaponInfo.Class = linkToSharedProgs("SHPF_weaponInfo_Class");
735 weaponInfo.IsClipOnly = linkToSharedProgs("SHPF_weaponInfo_IsClipOnly");
736 weaponInfo.IsDetonationTimed = linkToSharedProgs("SHPF_weaponInfo_IsDetonationTimed");
737
738 entityDef.GetString = linkToSharedProgs("SHPF_entityDef_GetString");
739 entityDef.GetInteger = linkToSharedProgs("SHPF_entityDef_GetInteger");
740 entityDef.GetBool = linkToSharedProgs("SHPF_entityDef_GetBool");
741 entityDef.GetFloat = linkToSharedProgs("SHPF_entityDef_GetFloat");
742 entityDef.GetVector = linkToSharedProgs("SHPF_entityDef_GetVector");
743
744 is.AI = linkToSharedProgs("SHPF_is_AI");
745 is.Bot = linkToSharedProgs("SHPF_is_Bot");
746 is.Alive = linkToSharedProgs("SHPF_is_Alive");
747 is.GodMode = linkToSharedProgs("SHPF_is_GodMode");
748 is.Client = linkToSharedProgs("SHPF_is_Client");
749 is.Player = linkToSharedProgs("SHPF_is_Player");
750 is.Sentient = linkToSharedProgs("SHPF_is_Sentient");
751
752 /* helpful finder */
753 next.Actor = linkToSharedProgs("SHPF_next_Actor");
754 next.Item = linkToSharedProgs("SHPF_next_Item");
755 next.Weapon = linkToSharedProgs("SHPF_next_Weapon");
756 next.Player = linkToSharedProgs("SHPF_next_Player");
757}
nextAPI_t next
Access nextAPI_t functions using this variable.
Definition: api.h:547
weaponInfo_t weaponInfo
Access weaponInfo_t functions using this variable.
Definition: api.h:293
userinfoAPI_t userinfo
Access userinfoAPI_t functions using this variable.
Definition: api.h:245
precacheAPI_t precache
Access precacheAPI_t functions using this variable.
Definition: api.h:476
soundAPI_t soundKit
Access soundAPI_t functions using this variable.
Definition: api.h:483
declAPI_t declManager
Access declAPI_t functions using this variable.
Definition: api.h:609
cvarAPI_t cvars
Access cvarAPI_t functions using this variable.
Definition: api.h:121
string decl
storage type of a decl reference.
Definition: api.h:549
isAPI_t is
Access nextAPI_t functions using this variable.
Definition: api.h:516
entityDefAPI_t entityDef
Access entityDefAPI_t functions using this variable.
Definition: api.h:436
teamAPI_t teams
Access teamAPI_t functions using this variable.
Definition: api.h:400
serverinfoAPI_t serverinfo
Access serverinfoAPI_t functions using this variable.
Definition: api.h:178
ammoAPI_t ammo
Access ammoAPI_t functions using this variable.
Definition: api.h:57
Ammo library.
Definition: api.h:38
int MaxForNum(int ammoID)
Find out the maximum ammo of a ammo type given the ID.
int NumForName(string ammoName)
Get the internal ID of an ammo type.
string NameForNum(int ammoID)
Find out the internal name of an ammo ID.
int MaxForName(string ammoName)
Find out the maximum ammo of a named ammo type.
CVar library.
Definition: api.h:68
float GetBool(string cvarName)
Returns the boolean value of a console variable.
float GetFloat(string cvarName)
Returns the floating-point value of a console variable.
void SetVector(string cvarName, vector setValue)
Sets the specified console variable to a set vector.
string GetString(string cvarName)
Returns the string value of a console variable.
void SetString(string cvarName, string setValue)
Sets the specified console variable to a set string value.
void SetFloat(string cvarName, float setValue)
Sets the specified console variable to a set floating-point value.
vector GetVector(string cvarName)
Returns the vector value of a console variable.
void SetInteger(string cvarName, int setValue)
Sets the specified console variable to a set integer value.
void SetBool(string cvarName, float setValue)
Sets the specified console variable to a set boolean value.
int GetInteger(string cvarName)
Returns the integer value of a console variable.
Decl library.
Definition: api.h:553
string GetString(decl declHandle, string keyName)
Returns the string value of a key from a decl.
vector GetVector(decl declHandle, string keyName)
Returns the vector value of a decl key.
int GetInteger(decl declHandle, string keyName)
Returns the integer value of a decl key.
decl New(void)
Returns the name of a new decl in which you can store key/value pairs in.
float GetBool(decl declHandle, string keyName)
Returns the boolean value of a decl key.
void AddKey(decl declHandle, string keyName, string setValue)
Adds/updates a named key within a decl with a new string value.
float GetFloat(decl declHandle, string keyName)
Returns the floating-point value of a decl key.
void Delete(decl declHandle)
Removes a named decl from the game.
void RemoveKey(decl declHandle, string keyName)
Removes a named key from a decl entirely.
EntityDef library.
Definition: api.h:404
string GetString(string defName, string keyName)
Returns the string value of a EntityDef key.
vector GetVector(string defName, string keyName)
Returns the vector value of a EntityDef key.
float GetFloat(string defName, string keyName)
Returns the floating-point value of a EntityDef key.
float GetBool(string defName, string keyName)
Returns the boolean value of a EntityDef key.
int GetInteger(string defName, string keyName)
Returns the integer value of a EntityDef key.
Definition: api.h:486
float AI(entity entityToCheck)
Returns true/false depending on if the entity is an AI character.
float Sentient(entity entityToCheck)
Returns true/false depending on if the entity is either a player, or AI character.
float Bot(entity entityToCheck)
Returns true/false depending on if the entity is a bot.
float Player(entity entityToCheck)
Returns true/false depending on if the entity is a player.
float Client(entity entityToCheck)
Returns true/false depending on if the entity is a client.
float Alive(entity entityToCheck)
Returns true/false depending on if the entity is alive.
float GodMode(entity entityToCheck)
Returns true/false depending on if the entity is in "god" mode.
Definition: api.h:519
entity Actor(entity lastActor)
Returns the next entity of type 'Actor' in the game.
entity Weapon(entity lastWeapon)
Returns the next entity of type 'Weapon' in the game.
entity Player(entity lastPlayer)
Returns the next entity of type 'Player' in the game.
entity Item(entity lastItem)
Returns the next entity of type 'Item' in the game.
Precaching library.
Definition: api.h:440
float Model(string pathToModel)
Precaches a given model file and additional helper files.
float Particle(string particleEffect)
Precaches a given particle effect.
float Entity(string className)
Precaches a given entity class.
float Sound(string soundDef)
Precaches a given sound def or sample.
ServerInfo library.
Definition: api.h:125
void SetBool(string serverKey, float setValue)
Server only.
void SetVector(string serverKey, vector setValue)
Server only.
float GetBool(string serverKey)
Returns the boolean value of a server info-key.
float GetFloat(string serverKey)
Returns the floating-point value of a server info-key.
void SetString(string serverKey, string setValue)
Server only.
int GetInteger(string serverKey)
Returns the integer value of a server info-key.
vector GetVector(string serverKey)
Returns the vector value of a server info-key.
string GetString(string serverKey)
Returns the string value of a server info-key.
void SetInteger(string serverKey, int setValue)
Server only.
void SetFloat(string serverKey, float setValue)
Server only.
Sound library.
Definition: api.h:480
void Play(string soundDef, float level=75, float pitch=100, float volume=100, float channel=CHAN_AUTO)
Team library.
Definition: api.h:297
string ClassForIndex(int teamID, int classIndex)
Find out the name of a team class given an index.
float Valid(int teamID)
Find out if a given team exists, or valid.
int NumDeadPlayers(int teamID)
Find out how many team players are currently inactive/dead in a match.
int TotalDeaths(int teamID)
Find out how many times all the players in a given team have 'died' in the game.
void SetUp(int teamID, string teamTitle, vector teamColor, float openTeam)
Sets up a team for the current session.
int NumPlayers(int teamID)
Find out how many players are in an active team.
void SetSpawnPoint(int teamID, string spawnPointEntityClassname)
Sets up a team spawn point for the current session.
int TeamCount(void)
Find out how many teams are registered in the current game.
int TotalClasses(int teamID)
Find out how many classes are registered within a team.
int TotalFrags(int teamID)
Find out how many times all the players in a given team have scored 'frags'.
void AddClass(int teamID, string classType)
Sets up a team class for the current session.
void SetScore(int teamID, int scoreValue)
Overridess the score of a specified team.
int NumAlivePlayers(int teamID)
Find out how many team players are active/alive in a match.
string SpawnPoint(int teamID)
Find the entity class name representing individual team spawn points.
int BestAutoJoinTeam(void)
Find out what the best choice of team it is to join.
int Score(int teamID)
Find the current score of a team.
entity RandomPlayer(int teamID)
Find a random player belonging to a given team.
string Name(int teamID)
Find the name of a team, that you can use in prints and written text.
void AddScore(int teamID, int addedScore)
Increases the score of a specified team.
vector Color(int teamID)
Find out which color represents a team.
int OpenTeamCount(void)
Find out how many teams are open to new players.
UserInfo library.
Definition: api.h:182
float GetBool(entity clientEnt, string userKey)
Returns the boolean value of a user info-key.
void SetString(entity clientEnt, string userKey, string setValue)
Server only.
void SetBool(entity clientEnt, string userKey, float setValue)
Sets the specified user info-key to a set boolean value.
float GetFloat(entity clientEnt, string userKey)
Returns the floating-point value of a user info-key.
string GetString(entity clientEnt, string userKey)
Returns the string value of a user info-key.
vector GetVector(entity clientEnt, string userKey)
Returns the vector value of a user info-key.
void SetFloat(entity clientEnt, string userKey, float setValue)
Server only.
int GetInteger(entity clientEnt, string userKey)
Returns the integer value of a user info-key.
void SetInteger(entity clientEnt, string userKey, int setValue)
Server only.
void SetVector(entity clientEnt, string userKey, vector setValue)
Server only.
Weapon library.
Definition: api.h:249
string InventoryType(string weaponDef)
Find out how this weapon is stored.
float FireTime(string weaponDef)
Find out the minimum delay between shots of a weapon, in seconds.
string Type(string weaponDef)
Get the "attack" type of the weapon.
float IsSemiAuto(string weaponDef)
Find out whether the weapon is semi-automatic.
int StartAmmo(string weaponDef)
The amount of ammo the specified weapon is meant to start with, when first given to the player.
float IsClipOnly(string weaponDef)
Find out if a weapon takes its ammo only through its clip.
int MaxAmmo(string weaponDef)
Find the amount of ammo a weapon can hold in total when it comes to reserve ammo.
float IsDetonationTimed(string weaponDef)
Find out whether a weapon has anything to do with a timed detonation.
string Class(string weaponDef)
Find the 'class' of a weapon.
int ClipSize(string weaponDef)
Find out what the clip size of a weapon is.