Nuclide
Software Development Kit for id Technology
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
28typedef struct
29{
31 string NameForNum(int);
33 int NumForName(string);
35 int MaxForName(string);
37 int MaxForNum(int);
38} ammoAPI_t;
39
41
42
43/* CVar library */
44typedef struct
45{
50 string GetString(string cvarName);
55 int GetInteger(string cvarName);
60 float GetFloat(string cvarName);
65 bool GetBool(string cvarName);
70 vector GetVector(string cvarName);
75 void SetString(string cvarName, string setValue);
80 void SetInteger(string cvarName, int setValue);
85 void SetBool(string cvarName, bool setValue);
90 void SetFloat(string cvarName, float setValue);
95 void SetVector(string cvarName, vector setValue);
96} cvarAPI_t;
97
99
100/* ServerInfo library */
101typedef struct
102{
107 string GetString(string serverKey);
112 int GetInteger(string serverKey);
117 float GetFloat(string serverKey);
122 bool GetBool(string serverKey);
127 vector GetVector(string serverKey);
132 void SetString(string serverKey, string setValue);
137 void SetInteger(string serverKey, int setValue);
142 void SetBool(string serverKey, bool setValue);
147 void SetFloat(string serverKey, float setValue);
152 void SetVector(string serverKey, vector setValue);
154
156
157/* UserInfo library */
158typedef struct
159{
165 string GetString(entity clientEnt, string userKey);
171 int GetInteger(entity clientEnt, string userKey);
177 float GetFloat(entity clientEnt, string userKey);
183 bool GetBool(entity clientEnt, string userKey);
189 vector GetVector(entity clientEnt, string userKey);
195 void SetString(entity clientEnt, string userKey, string setValue);
201 void SetInteger(entity clientEnt, string userKey, int setValue);
207 void SetBool(entity clientEnt, string userKey, bool setValue);
213 void SetFloat(entity clientEnt, string userKey, float setValue);
219 void SetVector(entity clientEnt, string userKey, vector setValue);
221
223
224typedef struct
225{
229 string Type(string weaponDef);
232 int StartAmmo(string weaponDef);
235 int MaxAmmo(string weaponDef);
238 bool IsSemiAuto(string weaponDef);
239
242 string InventoryType(string weaponDef);
245 float FireTime(string weaponDef);
249 int ClipSize(string weaponDef);
253 string Class(string weaponDef);
257 bool IsClipOnly(string weaponDef);
261 bool IsDetonationTimed(string weaponDef);
263
265
266/* Team library */
267typedef struct
268{
270 int TeamCount(void);
271 int OpenTeamCount(void);
272 vector Color(int);
273 string Name(int);
274 int Score(int);
275 string SpawnPoint(int);
276 int NumPlayers(int);
279 int TotalDeaths(int);
280 int TotalFrags(int);
281 bool Valid(int);
282
283 void AddScore(int, int);
284 void SetScore(int, int);
285 entity RandomPlayer(int);
286
287
294 void SetUp(int teamID, string teamTitle, vector teamColor, bool openTeam);
295
296
302 void AddClass(int teamID, string classType);
303
304
308 int TotalClasses(int teamID);
309
314 string ClassForIndex(int teamID, int classIndex);
315
322 void SetSpawnPoint(int teamID, string spawnPointEntityClassname);
323} teamAPI_t;
324
326
327
328
329/* ServerInfo library */
330typedef struct
331{
337 string GetString(string defName, string keyName);
343 int GetInteger(string defName, string keyName);
349 float GetFloat(string defName, string keyName);
355 bool GetBool(string defName, string keyName);
361 vector GetVector(string defName, string keyName);
364
365typedef struct
366{
367 float Model(string);
368 float Sound(string);
371
372typedef string decl;
373
374typedef struct
375{
378 decl New(void);
379
385 string GetString(decl declHandle, string keyName);
391 int GetInteger(decl declHandle, string keyName);
397 float GetFloat(decl declHandle, string keyName);
403 bool GetBool(decl declHandle, string keyName);
409 vector GetVector(decl declHandle, string keyName);
410
417 void AddKey(decl declHandle, string keyName, string setValue);
418
423 void RemoveKey(decl declHandle, string keyName);
424
428 void Delete(decl declHandle);
429} declAPI_t;
430
432
433__variant
434linkToSharedProgs(string funcName)
435{
436 static void empty(void)
437 {
438 print("Called unimplemented shared API call.\n");
439 breakpoint();
440 }
441
442 float func = externvalue( 0, funcName);
443
444 if (func) {
445 return ((__variant)func);
446 } else {
447 return (empty);
448 }
449}
450
451void
453{
454 ammo.NameForNum = linkToSharedProgs("SHPF_ammo_NameForNum");
455 ammo.NumForName = linkToSharedProgs("SHPF_ammo_NumForName");
456 ammo.MaxForName = linkToSharedProgs("SHPF_ammo_MaxForName");
457 ammo.MaxForNum = linkToSharedProgs("SHPF_ammo_MaxForNum");
458
459 cvars.SetString = linkToSharedProgs("SHPF_cvars_SetString");
460 cvars.SetBool = linkToSharedProgs("SHPF_cvars_SetBool");
461 cvars.SetInteger = linkToSharedProgs("SHPF_cvars_SetInteger");
462 cvars.SetFloat = linkToSharedProgs("SHPF_cvars_SetFloat");
463 cvars.SetVector = linkToSharedProgs("SHPF_cvars_SetVector");
464 cvars.GetString = linkToSharedProgs("SHPF_cvars_GetString");
465 cvars.GetInteger = linkToSharedProgs("SHPF_cvars_GetInteger");
466 cvars.GetBool = linkToSharedProgs("SHPF_cvars_GetBool");
467 cvars.GetFloat = linkToSharedProgs("SHPF_cvars_GetFloat");
468 cvars.GetVector = linkToSharedProgs("SHPF_cvars_GetVector");
469
470 declManager.New = linkToSharedProgs("SHPF_declManager_New");
471 declManager.GetFloat = linkToSharedProgs("SHPF_declManager_GetFloat");
472 declManager.GetString = linkToSharedProgs("SHPF_declManager_GetString");
473 declManager.GetVector = linkToSharedProgs("SHPF_declManager_GetVector");
474 declManager.GetBool = linkToSharedProgs("SHPF_declManager_GetBool");
475 declManager.AddKey = linkToSharedProgs("SHPF_declManager_AddKey");
476 declManager.RemoveKey = linkToSharedProgs("SHPF_declManager_RemoveKey");
477 declManager.Delete = linkToSharedProgs("SHPF_declManager_Delete");
478
479 userinfo.SetString = linkToSharedProgs("SHPF_userinfo_SetString");
480 userinfo.SetBool = linkToSharedProgs("SHPF_userinfo_SetBool");
481 userinfo.SetInteger = linkToSharedProgs("SHPF_userinfo_SetInteger");
482 userinfo.SetFloat = linkToSharedProgs("SHPF_userinfo_SetFloat");
483 userinfo.SetVector = linkToSharedProgs("SHPF_userinfo_SetVector");
484 userinfo.GetString = linkToSharedProgs("SHPF_userinfo_GetString");
485 userinfo.GetInteger = linkToSharedProgs("SHPF_userinfo_GetInteger");
486 userinfo.GetBool = linkToSharedProgs("SHPF_userinfo_GetBool");
487 userinfo.GetFloat = linkToSharedProgs("SHPF_userinfo_GetFloat");
488 userinfo.GetVector = linkToSharedProgs("SHPF_userinfo_GetVector");
489
490 serverinfo.SetString = linkToSharedProgs("SHPF_serverinfo_SetString");
491 serverinfo.SetBool = linkToSharedProgs("SHPF_serverinfo_SetBool");
492 serverinfo.SetInteger = linkToSharedProgs("SHPF_serverinfo_SetInteger");
493 serverinfo.SetFloat = linkToSharedProgs("SHPF_serverinfo_SetFloat");
494 serverinfo.SetVector = linkToSharedProgs("SHPF_serverinfo_SetVector");
495 serverinfo.GetString = linkToSharedProgs("SHPF_serverinfo_GetString");
496 serverinfo.GetInteger = linkToSharedProgs("SHPF_serverinfo_GetInteger");
497 serverinfo.GetBool = linkToSharedProgs("SHPF_serverinfo_GetBool");
498 serverinfo.GetFloat = linkToSharedProgs("SHPF_serverinfo_GetFloat");
499 serverinfo.GetVector = linkToSharedProgs("SHPF_serverinfo_GetVector");
500
501 teams.BestAutoJoinTeam = linkToSharedProgs("SHPF_teams_BestAutoJoinTeam");
502 teams.TeamCount = linkToSharedProgs("SHPF_teams_TeamCount");
503 teams.OpenTeamCount = linkToSharedProgs("SHPF_teams_OpenTeamCount");
504 teams.Color = linkToSharedProgs("SHPF_teams_Color");
505 teams.Name = linkToSharedProgs("SHPF_teams_Name");
506 teams.Score = linkToSharedProgs("SHPF_teams_Score");
507 teams.SpawnPoint = linkToSharedProgs("SHPF_teams_SpawnPoint");
508 teams.NumPlayers = linkToSharedProgs("SHPF_teams_NumPlayers");
509 teams.NumAlivePlayers = linkToSharedProgs("SHPF_teams_NumAlivePlayers");
510 teams.NumDeadPlayers = linkToSharedProgs("SHPF_teams_NumDeadPlayers");
511 teams.TotalDeaths = linkToSharedProgs("SHPF_teams_TotalDeaths");
512 teams.TotalFrags = linkToSharedProgs("SHPF_teams_TotalFrags");
513 teams.Valid = linkToSharedProgs("SHPF_teams_Valid");
514 teams.RandomPlayer = linkToSharedProgs("SHPF_teams_RandomPlayer");
515
516 /* server */
517 teams.AddScore = linkToSharedProgs("SHPF_teams_AddScore");
518 teams.SetScore = linkToSharedProgs("SHPF_teams_SetScore");
519 teams.SetUp = linkToSharedProgs("SHPF_teams_SetUp");
520 teams.AddClass = linkToSharedProgs("SHPF_teams_AddClass");
521 teams.TotalClasses = linkToSharedProgs("SHPF_teams_TotalClasses");
522 teams.ClassForIndex = linkToSharedProgs("SHPF_teams_ClassForIndex");
523 teams.SetSpawnPoint = linkToSharedProgs("SHPF_teams_SetSpawnPoint");
524
525 precache.Model = linkToSharedProgs("SHPF_precache_Model");
526 precache.Sound = linkToSharedProgs("SHPF_precache_Sound");
527
528 weaponInfo.Type = linkToSharedProgs("SHPF_weaponInfo_Type");
529 weaponInfo.StartAmmo = linkToSharedProgs("SHPF_weaponInfo_StartAmmo");
530 weaponInfo.MaxAmmo = linkToSharedProgs("SHPF_weaponInfo_MaxAmmo");
531 weaponInfo.IsSemiAuto = linkToSharedProgs("SHPF_weaponInfo_IsSemiAuto");
532 weaponInfo.InventoryType = linkToSharedProgs("SHPF_weaponInfo_InventoryType");
533 weaponInfo.FireTime = linkToSharedProgs("SHPF_weaponInfo_FireTime");
534 weaponInfo.ClipSize = linkToSharedProgs("SHPF_weaponInfo_ClipSize");
535 weaponInfo.Class = linkToSharedProgs("SHPF_weaponInfo_Class");
536 weaponInfo.IsClipOnly = linkToSharedProgs("SHPF_weaponInfo_IsClipOnly");
537 weaponInfo.IsDetonationTimed = linkToSharedProgs("SHPF_weaponInfo_IsDetonationTimed");
538
539 entityDef.GetString = linkToSharedProgs("SHPF_entityDef_GetString");
540 entityDef.GetInteger = linkToSharedProgs("SHPF_entityDef_GetInteger");
541 entityDef.GetBool = linkToSharedProgs("SHPF_entityDef_GetBool");
542 entityDef.GetFloat = linkToSharedProgs("SHPF_entityDef_GetFloat");
543 entityDef.GetVector = linkToSharedProgs("SHPF_entityDef_GetVector");
544}
string ClassForIndex(int teamID, int classIndex)
Returns the class type of a given team + index.
bool GetBool(string cvarName)
Returns the boolean value of a console variable.
string InventoryType(string weaponDef)
string GetString(decl declHandle, string keyName)
Returns the string value of a key from a decl.
float FireTime(string weaponDef)
void SetUp(int teamID, string teamTitle, vector teamColor, bool openTeam)
Sets up a team for the current session.
string Type(string weaponDef)
string NameForNum(int)
Returns the name of the specified ammo type.
int TotalDeaths(int)
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.
void _shared_main(void)
Definition: api.h:452
decl New(void)
Returns the name of a new decl in which you can store key/value pairs in.
void SetString(entity clientEnt, string userKey, string setValue)
Sets the specified user info-key to a set string value.
float GetFloat(string cvarName)
Returns the floating-point value of a console variable.
void SetVector(string serverKey, vector setValue)
Sets the specified server info-key to a set vector.
int StartAmmo(string weaponDef)
int TotalFrags(int)
int NumPlayers(int)
void SetVector(string cvarName, vector setValue)
Sets the specified console variable to a set vector.
weaponInfo_t weaponInfo
Definition: api.h:264
void AddKey(decl declHandle, string keyName, string setValue)
Adds/updates a named key within a decl with a new string value.
bool IsSemiAuto(string weaponDef)
userinfoAPI_t userinfo
Definition: api.h:222
string SpawnPoint(int)
float Model(string)
void SetSpawnPoint(int teamID, string spawnPointEntityClassname)
Sets up a team spawn point for the current session.
precacheAPI_t precache
Definition: api.h:370
float GetFloat(decl declHandle, string keyName)
Returns the floating-point value of a decl key.
string GetString(string defName, string keyName)
Returns the string value of a EntityDef key.
entity RandomPlayer(int)
int TeamCount(void)
int NumForName(string)
Returns the ammo id of a given name of ammo.
int MaxAmmo(string weaponDef)
vector GetVector(string defName, string keyName)
Returns the vector value of a EntityDef key.
int TotalClasses(int teamID)
Returns the maximum number of classes this team can select.
float GetFloat(string defName, string keyName)
Returns the floating-point value of a EntityDef key.
void AddScore(int, int)
int MaxForNum(int)
Returns the max ammo given name of ammo.
void AddClass(int teamID, string classType)
Sets up a team class for the current session.
int NumAlivePlayers(int)
float GetFloat(entity clientEnt, string userKey)
Returns the floating-point value of a user info-key.
vector Color(int)
string GetString(string cvarName)
Returns the string value of a console variable.
string GetString(entity clientEnt, string userKey)
Returns the string value of a user info-key.
__variant linkToSharedProgs(string funcName)
Definition: api.h:434
int NumDeadPlayers(int)
int Score(int)
void SetBool(string serverKey, bool setValue)
Sets the specified server info-key to a set boolean value.
vector GetVector(entity clientEnt, string userKey)
Returns the vector value of a user info-key.
float GetFloat(string serverKey)
Returns the floating-point value of a server info-key.
void SetBool(entity clientEnt, string userKey, bool setValue)
Sets the specified user info-key to a set boolean value.
bool IsClipOnly(string weaponDef)
bool GetBool(string serverKey)
Returns the boolean value of a server info-key.
declAPI_t declManager
Definition: api.h:431
float Sound(string)
bool GetBool(string defName, string keyName)
Returns the boolean value of a EntityDef key.
void SetString(string serverKey, string setValue)
Sets the specified server info-key to a set string value.
cvarAPI_t cvars
Definition: api.h:98
void SetString(string cvarName, string setValue)
Sets the specified console variable to a set string value.
string Name(int)
string decl
Definition: api.h:372
void SetBool(string cvarName, bool setValue)
Sets the specified console variable to a set boolean value.
void SetScore(int, int)
int GetInteger(string serverKey)
Returns the integer value of a server info-key.
void Delete(decl declHandle)
Removes a named decl from the game.
void SetFloat(entity clientEnt, string userKey, float setValue)
Sets the specified user info-key to a set floating-point value.
int BestAutoJoinTeam(void)
void SetFloat(string cvarName, float setValue)
Sets the specified console variable to a set floating-point value.
int GetInteger(entity clientEnt, string userKey)
Returns the integer value of a user info-key.
bool GetBool(entity clientEnt, string userKey)
Returns the boolean value of a user info-key.
vector GetVector(string serverKey)
Returns the vector value of a server info-key.
string Class(string weaponDef)
bool IsDetonationTimed(string weaponDef)
string GetString(string serverKey)
Returns the string value of a server info-key.
void SetInteger(entity clientEnt, string userKey, int setValue)
Sets the specified user info-key to a set integer value.
int GetInteger(string defName, string keyName)
Returns the integer value of a EntityDef key.
entityDefAPI_t entityDef
Definition: api.h:363
void SetInteger(string serverKey, int setValue)
Sets the specified server info-key to a set integer value.
int MaxForName(string)
Returns the max ammo given name of ammo.
bool Valid(int)
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 SetFloat(string serverKey, float setValue)
Sets the specified server info-key to a set floating-point value.
void SetVector(entity clientEnt, string userKey, vector setValue)
Sets the specified user info-key to a set vector.
int GetInteger(string cvarName)
Returns the integer value of a console variable.
void RemoveKey(decl declHandle, string keyName)
Removes a named key from a decl entirely.
int ClipSize(string weaponDef)
teamAPI_t teams
Definition: api.h:325
bool GetBool(decl declHandle, string keyName)
Returns the boolean value of a decl key.
serverinfoAPI_t serverinfo
Definition: api.h:155
int OpenTeamCount(void)
ammoAPI_t ammo
Definition: api.h:40
Definition: api.h:29
Definition: api.h:45
Definition: api.h:375
Definition: api.h:331
Definition: api.h:366
Definition: api.h:102
Definition: api.h:268
Definition: api.h:159
Definition: api.h:225