Nuclide
Software Development Kit for id Technology (BETA)
api.h
1/*
2 * Copyright (c) 2016-2024 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{
370 float Model(string);
371 float Sound(string);
374
375
376
377typedef struct
378{
379 float Play(string soundDef, float level = 75, float pitch = 100, float volume = 100, float channel = CHAN_AUTO);
380} soundAPI_t;
382
383
384typedef string decl;
385
386typedef struct
387{
390 decl New(void);
391
397 string GetString(decl declHandle, string keyName);
403 int GetInteger(decl declHandle, string keyName);
409 float GetFloat(decl declHandle, string keyName);
415 bool GetBool(decl declHandle, string keyName);
421 vector GetVector(decl declHandle, string keyName);
422
429 void AddKey(decl declHandle, string keyName, string setValue);
430
435 void RemoveKey(decl declHandle, string keyName);
436
440 void Delete(decl declHandle);
441} declAPI_t;
442
443declAPI_t declManager; // end of shared
445
446__variant
447linkToSharedProgs(string funcName)
448{
449 static void empty(void)
450 {
451 print("Called unimplemented shared API call.\n");
452 breakpoint();
453 }
454
455 float func = externvalue( 0, funcName);
456
457 if (func) {
458 return ((__variant)func);
459 } else {
460 return (empty);
461 }
462}
463
464void
465_shared_main(void)
466{
467 ammo.NameForNum = linkToSharedProgs("SHPF_ammo_NameForNum");
468 ammo.NumForName = linkToSharedProgs("SHPF_ammo_NumForName");
469 ammo.MaxForName = linkToSharedProgs("SHPF_ammo_MaxForName");
470 ammo.MaxForNum = linkToSharedProgs("SHPF_ammo_MaxForNum");
471
472 cvars.SetString = linkToSharedProgs("SHPF_cvars_SetString");
473 cvars.SetBool = linkToSharedProgs("SHPF_cvars_SetBool");
474 cvars.SetInteger = linkToSharedProgs("SHPF_cvars_SetInteger");
475 cvars.SetFloat = linkToSharedProgs("SHPF_cvars_SetFloat");
476 cvars.SetVector = linkToSharedProgs("SHPF_cvars_SetVector");
477 cvars.GetString = linkToSharedProgs("SHPF_cvars_GetString");
478 cvars.GetInteger = linkToSharedProgs("SHPF_cvars_GetInteger");
479 cvars.GetBool = linkToSharedProgs("SHPF_cvars_GetBool");
480 cvars.GetFloat = linkToSharedProgs("SHPF_cvars_GetFloat");
481 cvars.GetVector = linkToSharedProgs("SHPF_cvars_GetVector");
482
483 declManager.New = linkToSharedProgs("SHPF_declManager_New");
484 declManager.GetFloat = linkToSharedProgs("SHPF_declManager_GetFloat");
485 declManager.GetString = linkToSharedProgs("SHPF_declManager_GetString");
486 declManager.GetVector = linkToSharedProgs("SHPF_declManager_GetVector");
487 declManager.GetBool = linkToSharedProgs("SHPF_declManager_GetBool");
488 declManager.AddKey = linkToSharedProgs("SHPF_declManager_AddKey");
489 declManager.RemoveKey = linkToSharedProgs("SHPF_declManager_RemoveKey");
490 declManager.Delete = linkToSharedProgs("SHPF_declManager_Delete");
491
492 userinfo.SetString = linkToSharedProgs("SHPF_userinfo_SetString");
493 userinfo.SetBool = linkToSharedProgs("SHPF_userinfo_SetBool");
494 userinfo.SetInteger = linkToSharedProgs("SHPF_userinfo_SetInteger");
495 userinfo.SetFloat = linkToSharedProgs("SHPF_userinfo_SetFloat");
496 userinfo.SetVector = linkToSharedProgs("SHPF_userinfo_SetVector");
497 userinfo.GetString = linkToSharedProgs("SHPF_userinfo_GetString");
498 userinfo.GetInteger = linkToSharedProgs("SHPF_userinfo_GetInteger");
499 userinfo.GetBool = linkToSharedProgs("SHPF_userinfo_GetBool");
500 userinfo.GetFloat = linkToSharedProgs("SHPF_userinfo_GetFloat");
501 userinfo.GetVector = linkToSharedProgs("SHPF_userinfo_GetVector");
502
503 serverinfo.SetString = linkToSharedProgs("SHPF_serverinfo_SetString");
504 serverinfo.SetBool = linkToSharedProgs("SHPF_serverinfo_SetBool");
505 serverinfo.SetInteger = linkToSharedProgs("SHPF_serverinfo_SetInteger");
506 serverinfo.SetFloat = linkToSharedProgs("SHPF_serverinfo_SetFloat");
507 serverinfo.SetVector = linkToSharedProgs("SHPF_serverinfo_SetVector");
508 serverinfo.GetString = linkToSharedProgs("SHPF_serverinfo_GetString");
509 serverinfo.GetInteger = linkToSharedProgs("SHPF_serverinfo_GetInteger");
510 serverinfo.GetBool = linkToSharedProgs("SHPF_serverinfo_GetBool");
511 serverinfo.GetFloat = linkToSharedProgs("SHPF_serverinfo_GetFloat");
512 serverinfo.GetVector = linkToSharedProgs("SHPF_serverinfo_GetVector");
513
514 teams.BestAutoJoinTeam = linkToSharedProgs("SHPF_teams_BestAutoJoinTeam");
515 teams.TeamCount = linkToSharedProgs("SHPF_teams_TeamCount");
516 teams.OpenTeamCount = linkToSharedProgs("SHPF_teams_OpenTeamCount");
517 teams.Color = linkToSharedProgs("SHPF_teams_Color");
518 teams.Name = linkToSharedProgs("SHPF_teams_Name");
519 teams.Score = linkToSharedProgs("SHPF_teams_Score");
520 teams.SpawnPoint = linkToSharedProgs("SHPF_teams_SpawnPoint");
521 teams.NumPlayers = linkToSharedProgs("SHPF_teams_NumPlayers");
522 teams.NumAlivePlayers = linkToSharedProgs("SHPF_teams_NumAlivePlayers");
523 teams.NumDeadPlayers = linkToSharedProgs("SHPF_teams_NumDeadPlayers");
524 teams.TotalDeaths = linkToSharedProgs("SHPF_teams_TotalDeaths");
525 teams.TotalFrags = linkToSharedProgs("SHPF_teams_TotalFrags");
526 teams.Valid = linkToSharedProgs("SHPF_teams_Valid");
527 teams.RandomPlayer = linkToSharedProgs("SHPF_teams_RandomPlayer");
528
529 /* server */
530 teams.AddScore = linkToSharedProgs("SHPF_teams_AddScore");
531 teams.SetScore = linkToSharedProgs("SHPF_teams_SetScore");
532 teams.SetUp = linkToSharedProgs("SHPF_teams_SetUp");
533 teams.AddClass = linkToSharedProgs("SHPF_teams_AddClass");
534 teams.TotalClasses = linkToSharedProgs("SHPF_teams_TotalClasses");
535 teams.ClassForIndex = linkToSharedProgs("SHPF_teams_ClassForIndex");
536 teams.SetSpawnPoint = linkToSharedProgs("SHPF_teams_SetSpawnPoint");
537
538 precache.Model = linkToSharedProgs("SHPF_precache_Model");
539 precache.Sound = linkToSharedProgs("SHPF_precache_Sound");
540
541 soundKit.Play = linkToSharedProgs("SHPF_sounds_Play");
542
543 weaponInfo.Type = linkToSharedProgs("SHPF_weaponInfo_Type");
544 weaponInfo.StartAmmo = linkToSharedProgs("SHPF_weaponInfo_StartAmmo");
545 weaponInfo.MaxAmmo = linkToSharedProgs("SHPF_weaponInfo_MaxAmmo");
546 weaponInfo.IsSemiAuto = linkToSharedProgs("SHPF_weaponInfo_IsSemiAuto");
547 weaponInfo.InventoryType = linkToSharedProgs("SHPF_weaponInfo_InventoryType");
548 weaponInfo.FireTime = linkToSharedProgs("SHPF_weaponInfo_FireTime");
549 weaponInfo.ClipSize = linkToSharedProgs("SHPF_weaponInfo_ClipSize");
550 weaponInfo.Class = linkToSharedProgs("SHPF_weaponInfo_Class");
551 weaponInfo.IsClipOnly = linkToSharedProgs("SHPF_weaponInfo_IsClipOnly");
552 weaponInfo.IsDetonationTimed = linkToSharedProgs("SHPF_weaponInfo_IsDetonationTimed");
553
554 entityDef.GetString = linkToSharedProgs("SHPF_entityDef_GetString");
555 entityDef.GetInteger = linkToSharedProgs("SHPF_entityDef_GetInteger");
556 entityDef.GetBool = linkToSharedProgs("SHPF_entityDef_GetBool");
557 entityDef.GetFloat = linkToSharedProgs("SHPF_entityDef_GetFloat");
558 entityDef.GetVector = linkToSharedProgs("SHPF_entityDef_GetVector");
559}
weaponInfo_t weaponInfo
Definition: api.h:267
userinfoAPI_t userinfo
Definition: api.h:225
precacheAPI_t precache
Definition: api.h:373
soundAPI_t soundKit
Definition: api.h:381
declAPI_t declManager
Definition: api.h:443
cvarAPI_t cvars
Definition: api.h:101
string decl
Definition: api.h:384
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:387
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)
float Sound(string)
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:378
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)