globals & Global Functions
A live instance of Source engineโs global_vars_t along with built-in global utility functions.
globals Table
Section titled โglobals TableโAll fields on the globals table are read-only properties (direct field reads, not function calls).
| Field | Type | Description |
|---|---|---|
curtime |
number |
Server time of the frame being simulated. |
realtime |
number |
Wall-clock time in seconds since engine start (continues running while paused). |
frametime |
number |
Duration of the last rendered frame in seconds. |
framecount |
number |
Total number of frames rendered since engine start. |
tickcount |
number |
Current tick count. |
tickinterval |
number |
Simulation interval per tick (1/64 = 0.015625, 1/128 = 0.0078125). |
max_players |
number |
Maximum allowed player slots on current server. |
is_connected |
boolean |
true if connected to a game server. |
is_in_game |
boolean |
true if fully loaded and currently in-game. |
choked_commands |
number |
Number of user commands choked this frame (fake lag). |
commandack |
number |
Sequence number of the last acknowledged command from the server. |
commandack_prev |
number |
Sequence number of the command acknowledged prior to commandack. |
last_outgoing_command |
number |
Sequence number of the last transmitted user command. |
server_tick |
number |
Server tick estimated by the clock drift manager. |
client_tick |
number |
Client tick estimated by the clock drift manager. |
delta_tick |
number |
Tick on which the last delta update was based (-1 for full updates). |
clock_offset |
number |
Estimated clock offset in ticks between client and server. |
Example
Section titled โExampleโif not globals.is_in_game then returnend
local latency_seconds = to_time(globals.server_tick - globals.client_tick)print("Estimated latency: " .. string.format("%.1f ms", latency_seconds * 1000))Global Functions
Section titled โGlobal FunctionsโThese helper functions are available globally in all scripts without requiring any library prefix.
| Function | Parameters | Returns | Description |
|---|---|---|---|
print |
value: any |
nil |
Converts value via tostring and writes it to the cheat console with the script name prefix. |
error |
message: string |
nil |
Outputs a red error line to the console. Does not raise a Lua runtime error. |
print_raw |
text: string, color?: color |
nil |
Direct console output without prefix or trailing newline. Supports console inline \a escape codes. |
safe_call |
fn: function, ... |
any |
Executes fn within a protected call, catching and logging any errors to console. |
to_ticks |
seconds: number |
number |
Converts seconds to tick count: math.floor(0.5 + seconds / globals.tickinterval). |
to_time |
ticks: number |
number |
Converts tick count to seconds: ticks * globals.tickinterval. |
math.angle_diff |
a: number, b: number |
number |
Calculates the shortest signed difference between two angles in degrees (-180..180). |
math.clamp |
val: number, min: number, max: number |
number |
Clamps a numeric value between bounds. |
math.lerp |
from: number, to: number, fraction: number |
number |
Linear interpolation between two numbers. |
math.normalize_yaw |
yaw: number |
number |
Normalizes an angle into the range [-180, 180]. |
Console Inline Color Codes (print_raw)
Section titled โConsole Inline Color Codes (print_raw)โThe print_raw function supports special inline \a escape sequences to format console output:
| Code | Effect |
|---|---|
\aRRGGBB |
Switches console text color to the specified hex code (uppercase only, e.g. \aFF0000). |
\aACCENT |
Switches to the menuโs theme accent color. |
\a_MAIN_ |
Switches to standard log grey. |
\aDEFAULT |
Resets to the color passed in the color parameter. |
\aCLEAN |
Switches to invisible/transparent text while maintaining character width (for indentation alignment). |
print_raw("\aACCENTaimsense \a_MAIN_ยท \aFFFFFFTarget hit for \aFF4040100 \aFFFFFFdmg\n")