Hosting and domain costs until October 2024 have been generously sponsored by dumptruck_ds. Thank you!

Editing QuakeC Globals

From Quake Wiki

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
Globals are variables that aren't entity specific and can be accessed from anywhere at any time. Much like fields, they're broken down into system globals and QuakeC globals. Valid global data types include <code>string</code>, <code>vector</code>, <code>float</code>, and <code>entity</code>. Globals are declared via:
+
Globals are variables that aren't entity specific and can be accessed from anywhere at any time. Much like fields, they're broken down into system globals and QuakeC globals. Valid global data types include <code>string</code>, <code>vector</code>, <code>float</code>, and <code>entity</code>. Function pointers are also allowed by specifying the return type and any parameters that need to be passed to it. The return type should be void if it doesn't return anything. Globals are declared via:
 
     datatype globalName;
 
     datatype globalName;
 +
    returntype(datatype param1) globalFunction;
 +
Global functions are less useful but have a possible usage with setting up world data processing. When setting a function pointer, only the name of the function is needed e.g. <code>globalFunction = MyFunction;</code>. It can then be called like any other function by invoking the pointer.
  
System globals are globals defined within the engine itself and must be present for the game to work. These are always defined before anything else. The end of them is denoted by the <code>void end_sys_globals;</code> declaration. System globals must always be declared in the order defined within the vanilla QuakeC files as they are linked by memory offsets internally. Changing the order will break logic.
+
System globals are globals defined within the engine itself and must be present for the game to work. These are always defined before anything else. The end of them is denoted by the void <code>end_sys_globals;</code> declaration. System globals must always be declared in the order defined within the vanilla QuakeC files as they are linked by memory offsets internally. Changing the order will break logic.
  
QuakeC globals are standard globals that have no internal linkage and can be defined freely anywhere.
+
QuakeC globals are standard globals that have no internal linkage and can be defined freely anywhere. Note that these are not stored between maps and will be reset upon changing levels.
 
 
Note that these are not stored between maps and will be reset upon changing levels.
 
  
 
== System Globals ==
 
== System Globals ==
 
The following globals should be defined in the exact order of this list, otherwise memory offset errors can occur.
 
The following globals should be defined in the exact order of this list, otherwise memory offset errors can occur.
*''entity'' '''self'''
+
*''entity'' '''self''' - The entity that the physics frame is currently processing.
:The entity that the physics frame is currently processing.
+
*''entity'' '''other''' - If a collision is occurring, this is the entity '''self''' is colliding with. This should only be used from <code>touch()</code> functions.
*''entity'' '''other'''
+
*''entity'' '''world''' - The default world entity. This entity's fields cannot be written to directly and it is considered null in conditional checks.
:If a collision is occurring, this is the entity '''self''' is colliding with. This should only be used from <code>touch()</code> functions.
+
*''float'' '''time''' - The current game time in seconds.
*''entity'' '''world'''
+
*''float'' '''frametime''' - The difference between the previous physics frame and the current one in seconds.
:The default world entity. This entity's fields cannot be written to directly and it is considered null in conditional checks.
+
*''float'' '''force_retouch''' - If greater than 0, relinks all entities into the world. Useful for getting entities to touch newly created triggers. This should be set to 2 to properly reset everything since setting it to 1 will only relink entities starting from the current '''self''' onward.
*''float'' '''time'''
+
*''string'' '''mapname''' - The name of the current map e.g. start, e2m1, etc.
:The current game time in seconds.
+
*''float'' '''deathmatch''' - If non-zero, PvP is enabled. If set to 2, uses the classic deathmatch rules.
*''float'' '''frametime'''
+
*''float'' '''coop''' - If non-zero, co-op is enabled.
:The difference between the previous physics frame and the current one in seconds.
+
*''float'' '''teamplay''' - If non-zero while PvP is active, team PvP is enabled. If set to 1, friendly fire is disabled.
*''float'' '''force_retouch'''
+
*''float'' '''serverflags''' - Tracks the state of the game across the entire session. This doesn't get reset between level changes. The first 4 bits are reserved for the runes with each bit corresponding to its respective episode e.g. episode 1 is the first bit. If this is non-zero when going back to the start map, the player's inventory will be cleared.
:If greater than 0, relinks all entities into the world. Useful for getting entities to touch newly created triggers. This should be set to 2 to properly reset everything since setting it to 1 will only relink entities starting from the current '''self''' onward.
+
*''float'' '''total_secrets''' - The total secret count for the current map.
*''string'' '''mapname'''
+
*''float'' '''total_monsters''' - The total monster count for the current map.
:The name of the current map e.g. start, e2m1, etc.
+
*''float'' '''found_secrets''' - How many secrets have been found in the current map.
*''float'' '''deathmatch'''
+
*''float'' '''killed_monsters''' - How many monsters have been killed in the current map.
:If non-zero, PvP is enabled. If set to 2, uses the classic deathmatch rules.
 
*''float'' '''coop'''
 
:If non-zero, co-op is enabled.
 
*''float'' '''teamplay'''
 
:If non-zero while PvP is active, team PvP is enabled. If set to 1, friendly fire is disabled.
 
*''float'' '''serverflags'''
 
:Tracks the state of the game across the entire session. This doesn't get reset between level changes. The first 4 bits are reserved for the runes with each bit corresponding to its respective episode e.g. episode 1 is the first bit. If this is non-zero when going back to the start map, the player's inventory will be cleared.
 
*''float'' '''total_secrets'''
 
:The total secret count for the current map.
 
*''float'' '''total_monsters'''
 
:The total monster count for the current map.
 
*''float'' '''found_secrets'''
 
:How many secrets have been found in the current map.
 
*''float'' '''killed_monsters'''
 
:How many monsters have been killed in the current map.
 
 
Parms store information about each player when moving between levels. Players have their own set of parms, but the globals act as an interface for setting them. These can be changed to however the modder wants to encode information, but below is how they're handled by default.
 
Parms store information about each player when moving between levels. Players have their own set of parms, but the globals act as an interface for setting them. These can be changed to however the modder wants to encode information, but below is how they're handled by default.
*''float'' '''parm1'''
+
*''float'' '''parm1''' - Stores the player's '''items''' field minus any keys and power ups.
:Stores the player's '''items''' field minus any keys and power ups.
+
*''float'' '''parm2''' - Stores the player's health. This is capped between 50 and 100.
*''float'' '''parm2'''
+
*''float'' '''parm3''' - Stores the amount of armor the player has.
:Stores the player's health. This is capped between 50 and 100.
+
*''float'' '''parm4''' - Stores the amount of shells the player has. This has a minimum amount of 25.
*''float'' '''parm3'''
+
*''float'' '''parm5''' - Stores the amount of nails the player has.
:Stores the amount of armor the player has.
+
*''float'' '''parm6''' - Stores the amount of rockets the player has.
*''float'' '''parm4'''
+
*''float'' '''parm7''' - Stores the amount of cells the player has.
:Stores the amount of shells the player has. This has a minimum amount of 25.
+
*''float'' '''parm8''' - Stores the player's '''weapon''' field.
*''float'' '''parm5'''
+
*''float'' '''parm9''' - Stores the player's armor damage reduction multiplied by 100 to give two decimal places of accuracy (decimal places beyond this get discarded).
:Stores the amount of nails the player has.
 
*''float'' '''parm6'''
 
:Stores the amount of rockets the player has.
 
*''float'' '''parm7'''
 
:Stores the amount of cells the player has.
 
*''float'' '''parm8'''
 
:Stores the player's '''weapon''' field.
 
*''float'' '''parm9'''
 
:Stores the player's armor damage reduction multiplied by 100 to give two decimal places of accuracy (decimal places beyond this get discarded).
 
 
*''float'' '''parm10'''
 
*''float'' '''parm10'''
 
*''float'' '''parm11'''
 
*''float'' '''parm11'''
Line 66: Line 42:
 
*''float'' '''parm15'''
 
*''float'' '''parm15'''
 
*''float'' '''parm16'''
 
*''float'' '''parm16'''
:Unused
+
:-Unused
 
The following are used by <code>makevectors()</code> to store the local axes that the function generates from the passed angles.
 
The following are used by <code>makevectors()</code> to store the local axes that the function generates from the passed angles.
*''vector'' '''v_forward'''
+
*''vector'' '''v_forward''' - The facing direction of the passed angles.
:The facing direction of the passed angles.
+
*''vector'' '''v_up''' - The direction pointing directly up from the facing direction of the passed angles.
*''vector'' '''v_up'''
+
*''vector'' '''v_right''' - The direction pointing directly to the right of the facing direction of the passed angles.
:The direction pointing 90 degrees up from the facing direction of the passed angles.
 
*''vector'' '''v_right'''
 
:The direction pointing 90 degrees to the right of the facing direction of the passed angles.
 
 
The following are used by <code>traceline()</code> to pass information from the function to QuakeC.
 
The following are used by <code>traceline()</code> to pass information from the function to QuakeC.
*''float'' '''trace_allsolid'''
+
*''float'' '''trace_allsolid''' - If <code>TRUE</code>, the trace was stuck entirely in solids.
:If <code>TRUE</code>, the trace was stuck entirely in solids.
+
*''float'' '''trace_startsolid''' - If <code>TRUE</code>, the trace started inside of a solid.
*''float'' '''trace_startsolid'''
+
*''float'' '''trace_fraction''' - The fraction of the total distance the trace traveled before stopping. Ranges from [0, 1].
:If <code>TRUE</code>, the trace started inside of a solid.
+
*''vector'' '''trace_endpos''' - The position the trace stopped.
*''float'' '''trace_fraction'''
+
*''vector'' '''trace_plane_normal''' - The normal of the plane that the trace hit.
:The fraction of the total distance the trace traveled before stopping. Ranges from [0, 1].
+
*''float'' '''trace_plane_dist''' - The distance from the world origin of the plane that the trace hit. This is d in the plane equation ax + by + cz + d = 0.
*''vector'' '''trace_endpos'''
+
*''entity'' '''trace_ent''' - The entity that the trace hit.
:The position the trace stopped.
+
*''float'' '''trace_inopen''' - If <code>TRUE</code>, the trace traveled through open air.
*''vector'' '''trace_plane_normal'''
+
*''float'' '''trace_inwater''' - If <code>TRUE</code>, the trace traveled through a liquid.
:The normal of the plane that the trace hit.
+
*''entity'' '''msg_entity''' - When sending a network message to a specific player via <code>MSG_ONE</code>, this is the player the message is sent to.
*''float'' '''trace_plane_dist'''
 
:The distance from the world origin of the plane that the trace hit. This is d in the plane equation ax + by + cz + d = 0.
 
*''entity'' '''trace_ent'''
 
:The entity that the trace hit.
 
*''float'' '''trace_inopen'''
 
:If <code>TRUE</code>, the trace traveled through open air.
 
*''float'' '''trace_inwater'''
 
:If <code>TRUE</code>, the trace traveled through a liquid.
 
*''entity'' '''msg_entity'''
 
:When sending a network message to a specific player via <code>MSG_ONE</code>, this is the player the message is sent to.
 
 
Below are a special set of global functions the engine calls. These have no internal definitions so the function body must be defined somewhere in QuakeC to work. As such, their functionality is entirely customizable.
 
Below are a special set of global functions the engine calls. These have no internal definitions so the function body must be defined somewhere in QuakeC to work. As such, their functionality is entirely customizable.
*''void()'' '''main'''
+
*''void()'' '''main''' - Unused.
:Unused.
+
*''void()'' '''StartFrame''' - Called at the start of every physics frame before anything else is processed.
*''void()'' '''StartFrame'''
+
*''void()'' '''PlayerPreThink''' - Called before the player's physics is ran.
:Called at the start of every physics frame before anything else is processed.
+
*''void()'' '''PlayerPostThink''' - Called after the player's physics is ran.
*''void()'' '''PlayerPreThink'''
+
*''void()'' '''ClientKill''' - Called when the player kills themselves via the console command.
:Called before the player's physics is ran.
+
*''void()'' '''ClientConnect''' - Called when a player joins the game, either for the first time or from changing levels.
*''void()'' '''PlayerPostThink'''
+
*''void()'' '''PutClientInServer''' - Called when a player is set to spawn or respawn.
:Called after the player's physics is ran.
+
*''void()'' '''ClientDisconnect''' - Called when a player leaves the game, either from disconnecting or changing levels.
*''void()'' '''ClientKill'''
+
*''void()'' '''SetNewParms''' - Sets the default parms for the player when they join the game for the first time or when respawning in deathmatch.
:Called when the player kills themselves via the console command.
+
*''void()'' '''SetChangeParms''' - Called when the player is about to change levels and their parms need to be set so they can be decoded when joining the new map.
*''void()'' '''ClientConnect'''
 
:Called when a player joins the game, either for the first time or from changing levels.
 
*''void()'' '''PutClientInServer'''
 
:Called when a player is set to spawn or respawn.
 
*''void()'' '''ClientDisconnect'''
 
:Called when a player leaves the game, either from disconnecting or changing levels.
 
*''void()'' '''SetNewParms'''
 
:Sets the default parms for the player when they join the game for the first time or when respawning in deathmatch.
 
*''void()'' '''SetChangeParms'''
 
:Called when the player is about to change levels and their parms need to be set so they can be decoded when joining the new map.
 
  
 
== QuakeC Globals ==
 
== QuakeC Globals ==
Line 121: Line 74:
  
 
=== World Globals ===
 
=== World Globals ===
*''string'' '''string_null'''
 
:Null string. This differs from empty strings in that it's not considered a valid string in conditional checks while empty strings are.
 
*''float'' '''skill'''
 
:The current difficulty of the map. Can be one of the following:
 
:*<code>0</code> (Easy)
 
:*<code>1</code> (Normal)
 
:*<code>2</code> (Hard)
 
:*<code>3</code> (Nightmare)
 
*''float'' '''framecount'''
 
:The total number of physics frames the server has processed.
 
*''float'' '''gameover'''
 
:If <code>TRUE</code>, the server is changing levels and players should not be considered fully disconnected.
 
*''string'' '''nextmap'''
 
:Stores the name of the next map to go to when changing levels e.g. start, e4m4, etc.
 
*''float'' '''intermission_running'''
 
:Stores the type of intermission cutscene currently being played. Can be one of the following:
 
:*<code>1</code> (Stats screen)
 
:*<code>2</code> (End of episode text crawl)
 
:*<code>3</code> (All runes collected text crawl)
 
*''float'' '''intermission_exittime'''
 
:Stores the time stamp for when the intermission should end and change levels.
 
*''entity'' '''lastspawn'''
 
:Stores the last multiplayer spawn point found in order to cycle through them when spawning players in.
 
*''entity'' '''bodyque_head'''
 
:Stores a queue of entities to track player corpses. Tracks up to 4 corpses by default.
 
 
=== Map Entity Globals ===
 
*''entity'' '''s'''
 
:Tracks the last teleport fog entity that was spawned.
 
 
=== General Entity Globals ===
 
*''entity'' '''activator'''
 
:The entity that's considered the activator when calling <code>SUB_UseTargets()</code>.
 
*''entity'' '''damage_attacker'''
 
:The source of the attack when an entity takes damage.
 
*''entity'' '''newmis'''
 
:Set by <code>launch_spike()</code> to store the newly created projectile entity.
 
*''entity'' '''multi_ent'''
 
:When firing a shotgun attack, stores the entity that's currently being damaged by tracers.
 
*''float'' '''multi_damage'''
 
:When firing a shotgun attack, stores the total amount of damage to apply to '''multi_ent''' after the tracers are done or when hitting a different entity.
 
 
=== Monster Entity Globals ===
 
*''float'' '''movedist'''
 
:When attempting to move, stores how far the current monster is trying to travel in map units.
 
*''entity'' '''sight_entity'''
 
:The monster that just woke up from finding a valid target. This is used so other monsters can see it and check to wake up themselves.
 
*''float'' '''sight_entity_time'''
 
:The time stamp for when the monster woke up from finding a valid target. In order for '''sight_entity''' to be valid other monsters must have seen it within 0.1 seconds.
 
*''float'' '''enemy_vis'''
 
:If <code>TRUE</code>, the current monster was able to see its enemy while chasing.
 
*''float'' '''enemy_infront'''
 
:If <code>TRUE</code>, the current monster's enemy was in front of the direction it's facing while chasing.
 
*''float'' '''enemy_range'''
 
:Determines how far away the current monster's enemy is while chasing. Can be one of the following:
 
:*<code>RANGE_MELEE</code> (within 120 map units)
 
:*<code>RANGE_NEAR</code> (within 500 map units)
 
:*<code>RANGE_MID</code> (within 1000 map units)
 
:*<code>RANGE_FAR</code> (1000+ map units)
 
*''float'' '''enemy_yaw'''
 
:The yaw that points towards the current monster's enemy while chasing.
 
*''float'' '''hknight_type'''
 
:Determines what type of melee attack Death Knights will perform. Can be one of the following:
 
:*<code>0</code> (Slice attack)
 
:*<code>1</code> (Overhead attack)
 
:*<code>2</code> (Long combo slice attack)
 
*''entity'' '''le1'''
 
:When fighting Chthon, stores the first pillar that lowers in the lightning trap.
 
*''entity'' '''le2'''
 
:When fighting Chthon, stores the second pillar that lowers in the lightning trap.
 
*''float'' '''lightning_end'''
 
:When fighting Chthon, stores the time stamp for when the pillars in the lightning trap should raise back up after being activated.
 
*''entity'' '''shub'''
 
:Stores a pointer to Shub-Niggurath so the finale cutscene can play out correctly.
 
  
=== Player Entity Globals ===
+
=== Entity Globals ===
*''float'' '''modelindex_eyes'''
 
:Stores the model index in the cache for the eyes when the player is invisible.
 
*''float'' '''modelindex_player'''
 
:Stores the model index in the cache for the player.
 

Please note that all contributions to Quake Wiki are considered to be released under the GNU Free Documentation License 1.3 or later (see Quake Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel | Editing help (opens in new window)