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
31typedef struct
32{
34 string NameForNum(int);
36 int NumForName(string);
38 int MaxForName(string);
40 int MaxForNum(int);
41} ammoAPI_t;
42
44
45
46/* CVar library */
47typedef struct
48{
53 string GetString(string cvarName);
58 int GetInteger(string cvarName);
63 float GetFloat(string cvarName);
68 bool GetBool(string cvarName);
73 vector GetVector(string cvarName);
78 void SetString(string cvarName, string setValue);
83 void SetInteger(string cvarName, int setValue);
88 void SetBool(string cvarName, bool setValue);
93 void SetFloat(string cvarName, float setValue);
98 void SetVector(string cvarName, vector setValue);
99} cvarAPI_t;
100
102
103/* ServerInfo library */
104typedef struct
105{
110 string GetString(string serverKey);
115 int GetInteger(string serverKey);
120 float GetFloat(string serverKey);
125 bool GetBool(string serverKey);
130 vector GetVector(string serverKey);
135 void SetString(string serverKey, string setValue);
140 void SetInteger(string serverKey, int setValue);
145 void SetBool(string serverKey, bool setValue);
150 void SetFloat(string serverKey, float setValue);
155 void SetVector(string serverKey, vector setValue);
157
159
160/* UserInfo library */
161typedef struct
162{
168 string GetString(entity clientEnt, string userKey);
174 int GetInteger(entity clientEnt, string userKey);
180 float GetFloat(entity clientEnt, string userKey);
186 bool GetBool(entity clientEnt, string userKey);
192 vector GetVector(entity clientEnt, string userKey);
198 void SetString(entity clientEnt, string userKey, string setValue);
204 void SetInteger(entity clientEnt, string userKey, int setValue);
210 void SetBool(entity clientEnt, string userKey, bool setValue);
216 void SetFloat(entity clientEnt, string userKey, float setValue);
222 void SetVector(entity clientEnt, string userKey, vector setValue);
224
226
227typedef struct
228{
232 string Type(string weaponDef);
235 int StartAmmo(string weaponDef);
238 int MaxAmmo(string weaponDef);
241 bool IsSemiAuto(string weaponDef);
242
245 string InventoryType(string weaponDef);
248 float FireTime(string weaponDef);
252 int ClipSize(string weaponDef);
256 string Class(string weaponDef);
260 bool IsClipOnly(string weaponDef);
264 bool IsDetonationTimed(string weaponDef);
266
268
269/* Team library */
270typedef struct
271{
273 int TeamCount(void);
274 int OpenTeamCount(void);
275 vector Color(int);
276 string Name(int);
277 int Score(int);
278 string SpawnPoint(int);
279 int NumPlayers(int);
282 int TotalDeaths(int);
283 int TotalFrags(int);
284 bool Valid(int);
285
286 void AddScore(int, int);
287 void SetScore(int, int);
288 entity RandomPlayer(int);
289
290
297 void SetUp(int teamID, string teamTitle, vector teamColor, bool openTeam);
298
299
305 void AddClass(int teamID, string classType);
306
307
311 int TotalClasses(int teamID);
312
317 string ClassForIndex(int teamID, int classIndex);
318
325 void SetSpawnPoint(int teamID, string spawnPointEntityClassname);
326} teamAPI_t;
327
329
330
331
332/* ServerInfo library */
333typedef struct
334{
340 string GetString(string defName, string keyName);
346 int GetInteger(string defName, string keyName);
352 float GetFloat(string defName, string keyName);
358 bool GetBool(string defName, string keyName);
364 vector GetVector(string defName, string keyName);
367
368typedef struct
369{
376 float Model(string pathToModel);
377
385 float Sound(string soundDef);
386
395 float Particle(string particleEffect);
396
403 bool Entity(string className);
406
407
408
409typedef struct
410{
411 float Play(string soundDef, float level = 75, float pitch = 100, float volume = 100, float channel = CHAN_AUTO);
412} soundAPI_t;
414
415
416typedef string decl;
417
418typedef struct
419{
422 decl New(void);
423
429 string GetString(decl declHandle, string keyName);
435 int GetInteger(decl declHandle, string keyName);
441 float GetFloat(decl declHandle, string keyName);
447 bool GetBool(decl declHandle, string keyName);
453 vector GetVector(decl declHandle, string keyName);
454
461 void AddKey(decl declHandle, string keyName, string setValue);
462
467 void RemoveKey(decl declHandle, string keyName);
468
472 void Delete(decl declHandle);
473} declAPI_t;
474
475declAPI_t declManager; // end of shared
477
478void
479setorigin_safe(entity target, vector testorg)
480{
481 for (int i = 0; i < 16; i++) {
482 tracebox(testorg, target.mins, target.maxs, testorg, MOVE_NORMAL, target);
483
484 if (!trace_startsolid) {
485 break;
486 }
487
488 testorg[2] += 1.0;
489 }
490
491 setorigin(target, testorg);
492}
493
494__variant
495linkToSharedProgs(string funcName)
496{
497 static void empty(void)
498 {
499 print("Called unimplemented shared API call.\n");
500 breakpoint();
501 }
502
503 float func = externvalue( 0, funcName);
504
505 if (func) {
506 return ((__variant)func);
507 } else {
508 return (empty);
509 }
510}
511
512void
513_shared_main(void)
514{
515 ammo.NameForNum = linkToSharedProgs("SHPF_ammo_NameForNum");
516 ammo.NumForName = linkToSharedProgs("SHPF_ammo_NumForName");
517 ammo.MaxForName = linkToSharedProgs("SHPF_ammo_MaxForName");
518 ammo.MaxForNum = linkToSharedProgs("SHPF_ammo_MaxForNum");
519
520 cvars.SetString = linkToSharedProgs("SHPF_cvars_SetString");
521 cvars.SetBool = linkToSharedProgs("SHPF_cvars_SetBool");
522 cvars.SetInteger = linkToSharedProgs("SHPF_cvars_SetInteger");
523 cvars.SetFloat = linkToSharedProgs("SHPF_cvars_SetFloat");
524 cvars.SetVector = linkToSharedProgs("SHPF_cvars_SetVector");
525 cvars.GetString = linkToSharedProgs("SHPF_cvars_GetString");
526 cvars.GetInteger = linkToSharedProgs("SHPF_cvars_GetInteger");
527 cvars.GetBool = linkToSharedProgs("SHPF_cvars_GetBool");
528 cvars.GetFloat = linkToSharedProgs("SHPF_cvars_GetFloat");
529 cvars.GetVector = linkToSharedProgs("SHPF_cvars_GetVector");
530
531 declManager.New = linkToSharedProgs("SHPF_declManager_New");
532 declManager.GetFloat = linkToSharedProgs("SHPF_declManager_GetFloat");
533 declManager.GetString = linkToSharedProgs("SHPF_declManager_GetString");
534 declManager.GetVector = linkToSharedProgs("SHPF_declManager_GetVector");
535 declManager.GetBool = linkToSharedProgs("SHPF_declManager_GetBool");
536 declManager.AddKey = linkToSharedProgs("SHPF_declManager_AddKey");
537 declManager.RemoveKey = linkToSharedProgs("SHPF_declManager_RemoveKey");
538 declManager.Delete = linkToSharedProgs("SHPF_declManager_Delete");
539
540 userinfo.SetString = linkToSharedProgs("SHPF_userinfo_SetString");
541 userinfo.SetBool = linkToSharedProgs("SHPF_userinfo_SetBool");
542 userinfo.SetInteger = linkToSharedProgs("SHPF_userinfo_SetInteger");
543 userinfo.SetFloat = linkToSharedProgs("SHPF_userinfo_SetFloat");
544 userinfo.SetVector = linkToSharedProgs("SHPF_userinfo_SetVector");
545 userinfo.GetString = linkToSharedProgs("SHPF_userinfo_GetString");
546 userinfo.GetInteger = linkToSharedProgs("SHPF_userinfo_GetInteger");
547 userinfo.GetBool = linkToSharedProgs("SHPF_userinfo_GetBool");
548 userinfo.GetFloat = linkToSharedProgs("SHPF_userinfo_GetFloat");
549 userinfo.GetVector = linkToSharedProgs("SHPF_userinfo_GetVector");
550
551 serverinfo.SetString = linkToSharedProgs("SHPF_serverinfo_SetString");
552 serverinfo.SetBool = linkToSharedProgs("SHPF_serverinfo_SetBool");
553 serverinfo.SetInteger = linkToSharedProgs("SHPF_serverinfo_SetInteger");
554 serverinfo.SetFloat = linkToSharedProgs("SHPF_serverinfo_SetFloat");
555 serverinfo.SetVector = linkToSharedProgs("SHPF_serverinfo_SetVector");
556 serverinfo.GetString = linkToSharedProgs("SHPF_serverinfo_GetString");
557 serverinfo.GetInteger = linkToSharedProgs("SHPF_serverinfo_GetInteger");
558 serverinfo.GetBool = linkToSharedProgs("SHPF_serverinfo_GetBool");
559 serverinfo.GetFloat = linkToSharedProgs("SHPF_serverinfo_GetFloat");
560 serverinfo.GetVector = linkToSharedProgs("SHPF_serverinfo_GetVector");
561
562 teams.BestAutoJoinTeam = linkToSharedProgs("SHPF_teams_BestAutoJoinTeam");
563 teams.TeamCount = linkToSharedProgs("SHPF_teams_TeamCount");
564 teams.OpenTeamCount = linkToSharedProgs("SHPF_teams_OpenTeamCount");
565 teams.Color = linkToSharedProgs("SHPF_teams_Color");
566 teams.Name = linkToSharedProgs("SHPF_teams_Name");
567 teams.Score = linkToSharedProgs("SHPF_teams_Score");
568 teams.SpawnPoint = linkToSharedProgs("SHPF_teams_SpawnPoint");
569 teams.NumPlayers = linkToSharedProgs("SHPF_teams_NumPlayers");
570 teams.NumAlivePlayers = linkToSharedProgs("SHPF_teams_NumAlivePlayers");
571 teams.NumDeadPlayers = linkToSharedProgs("SHPF_teams_NumDeadPlayers");
572 teams.TotalDeaths = linkToSharedProgs("SHPF_teams_TotalDeaths");
573 teams.TotalFrags = linkToSharedProgs("SHPF_teams_TotalFrags");
574 teams.Valid = linkToSharedProgs("SHPF_teams_Valid");
575 teams.RandomPlayer = linkToSharedProgs("SHPF_teams_RandomPlayer");
576
577 /* server */
578 teams.AddScore = linkToSharedProgs("SHPF_teams_AddScore");
579 teams.SetScore = linkToSharedProgs("SHPF_teams_SetScore");
580 teams.SetUp = linkToSharedProgs("SHPF_teams_SetUp");
581 teams.AddClass = linkToSharedProgs("SHPF_teams_AddClass");
582 teams.TotalClasses = linkToSharedProgs("SHPF_teams_TotalClasses");
583 teams.ClassForIndex = linkToSharedProgs("SHPF_teams_ClassForIndex");
584 teams.SetSpawnPoint = linkToSharedProgs("SHPF_teams_SetSpawnPoint");
585
586 precache.Model = linkToSharedProgs("SHPF_precache_Model");
587 precache.Sound = linkToSharedProgs("SHPF_precache_Sound");
588 precache.Particle = linkToSharedProgs("SHPF_precache_Particle");
589 precache.Entity = linkToSharedProgs("EntityDef_Precache");
590
591 soundKit.Play = linkToSharedProgs("SHPF_sounds_Play");
592
593 weaponInfo.Type = linkToSharedProgs("SHPF_weaponInfo_Type");
594 weaponInfo.StartAmmo = linkToSharedProgs("SHPF_weaponInfo_StartAmmo");
595 weaponInfo.MaxAmmo = linkToSharedProgs("SHPF_weaponInfo_MaxAmmo");
596 weaponInfo.IsSemiAuto = linkToSharedProgs("SHPF_weaponInfo_IsSemiAuto");
597 weaponInfo.InventoryType = linkToSharedProgs("SHPF_weaponInfo_InventoryType");
598 weaponInfo.FireTime = linkToSharedProgs("SHPF_weaponInfo_FireTime");
599 weaponInfo.ClipSize = linkToSharedProgs("SHPF_weaponInfo_ClipSize");
600 weaponInfo.Class = linkToSharedProgs("SHPF_weaponInfo_Class");
601 weaponInfo.IsClipOnly = linkToSharedProgs("SHPF_weaponInfo_IsClipOnly");
602 weaponInfo.IsDetonationTimed = linkToSharedProgs("SHPF_weaponInfo_IsDetonationTimed");
603
604 entityDef.GetString = linkToSharedProgs("SHPF_entityDef_GetString");
605 entityDef.GetInteger = linkToSharedProgs("SHPF_entityDef_GetInteger");
606 entityDef.GetBool = linkToSharedProgs("SHPF_entityDef_GetBool");
607 entityDef.GetFloat = linkToSharedProgs("SHPF_entityDef_GetFloat");
608 entityDef.GetVector = linkToSharedProgs("SHPF_entityDef_GetVector");
609}
weaponInfo_t weaponInfo
Definition: api.h:267
userinfoAPI_t userinfo
Definition: api.h:225
precacheAPI_t precache
Definition: api.h:405
soundAPI_t soundKit
Definition: api.h:413
declAPI_t declManager
Definition: api.h:475
cvarAPI_t cvars
Definition: api.h:101
string decl
Definition: api.h:416
entityDefAPI_t entityDef
Definition: api.h:366
teamAPI_t teams
Definition: api.h:328
serverinfoAPI_t serverinfo
Definition: api.h:158
ammoAPI_t ammo
Definition: api.h:43
Definition: api.h:32
string NameForNum(int)
Returns the name of the specified ammo type.
int NumForName(string)
Returns the ammo id of a given name of ammo.
int MaxForNum(int)
Returns the max ammo given name of ammo.
int MaxForName(string)
Returns the max ammo given name of ammo.
Definition: api.h:48
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.
Definition: api.h:419
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.
Definition: api.h:334
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:369
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.
Definition: api.h:105
void SetBool(string serverKey, float setValue)
Sets the specified server info-key to a set boolean value.
void SetVector(string serverKey, vector setValue)
Sets the specified server info-key to a set vector.
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)
Sets the specified server info-key to a set string value.
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)
Sets the specified server info-key to a set integer value.
void SetFloat(string serverKey, float setValue)
Sets the specified server info-key to a set floating-point value.
Definition: api.h:410
float Play(string soundDef, float level=75, float pitch=100, float volume=100, float channel=CHAN_AUTO)
Definition: api.h:271
string ClassForIndex(int teamID, int classIndex)
Returns the class type of a given team + index.
int TotalDeaths(int)
void SetUp(int teamID, string teamTitle, vector teamColor, float openTeam)
Sets up a team for the current session.
int TotalFrags(int)
int NumPlayers(int)
string SpawnPoint(int)
void SetSpawnPoint(int teamID, string spawnPointEntityClassname)
Sets up a team spawn point for the current session.
entity RandomPlayer(int)
int TeamCount(void)
int TotalClasses(int teamID)
Returns the maximum number of classes this team can select.
void AddScore(int, int)
void AddClass(int teamID, string classType)
Sets up a team class for the current session.
int NumAlivePlayers(int)
vector Color(int)
float Valid(int)
int NumDeadPlayers(int)
int Score(int)
string Name(int)
void SetScore(int, int)
int BestAutoJoinTeam(void)
int OpenTeamCount(void)
Definition: api.h:162
float GetBool(entity clientEnt, string userKey)
Returns the boolean value of a user info-key.
void SetString(entity clientEnt, string userKey, string setValue)
Sets the specified user info-key to a set string value.
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)
Sets the specified user info-key to a set floating-point value.
int GetInteger(entity clientEnt, string userKey)
Returns the integer value of a user info-key.
void SetInteger(entity clientEnt, string userKey, int setValue)
Sets the specified user info-key to a set integer value.
void SetVector(entity clientEnt, string userKey, vector setValue)
Sets the specified user info-key to a set vector.
Definition: api.h:228
string InventoryType(string weaponDef)
float FireTime(string weaponDef)
string Type(string weaponDef)
float IsSemiAuto(string weaponDef)
int StartAmmo(string weaponDef)
float IsClipOnly(string weaponDef)
int MaxAmmo(string weaponDef)
float IsDetonationTimed(string weaponDef)
string Class(string weaponDef)
int ClipSize(string weaponDef)