Chimera includes a powerful Lua scripting engine that allows you to extend and customize Halo’s behavior. Scripts can respond to game events, modify game state, and create custom functionality.
Overview
Chimera’s Lua scripting system provides:
- Event callbacks - React to game events like map loads, ticks, frames, and player spawns
- Game API - Access and modify game state, objects, players, and tags
- File I/O - Read and write files (global scripts only)
- Timers - Schedule functions to run at specific intervals
- Two script types - Global scripts (persistent) and map scripts (map-specific)
Script Types
Global Scripts
Global scripts are loaded when Halo starts and remain active until the game exits or scripts are reloaded.
Location:
Characteristics:
- Persist across map changes
- Can use file I/O operations
- Not sandboxed
- Ideal for persistent functionality
Example use cases:
- Custom HUD overlays
- Statistics tracking
- Server browser enhancements
- Input remapping
Map Scripts
Map scripts are loaded when a specific map loads and unload when the map changes.
Location:
Characteristics:
- Loaded when map loads
- Unloaded when map changes
- Can use file I/O operations
- Not sandboxed
- Map-specific functionality
Example: bloodgulch.lua loads only when playing Blood Gulch.
Embedded Scripts
Maps can contain embedded Lua scripts in their tag data.
Characteristics:
- Embedded in map file
- Sandboxed (restricted I/O)
- Loaded with map
- Requires
load_embedded_lua=1 in chimera.ini (or map-specific flag)
Embedded scripts are sandboxed and have restricted access to I/O operations for security. They cannot execute system commands or access arbitrary files.
Enable embedded scripts in chimera.ini:
Basic Script Structure
Minimal Script
Chimera provides global variables in every script:
Event System
Chimera’s event system allows scripts to react to game events using callbacks.
Registering Callbacks
Parameters:
event_name - Name of the event to listen for
function_name - Name of your callback function (or empty string to unregister)
priority - (Optional) “before”, “default”, “after”, or “final”
Event Priorities
Callbacks can be registered with different priorities:
"before" - Runs before default callbacks
"default" - Normal priority (default)
"after" - Runs after default callbacks
"final" - Runs last, cannot modify event data
Available Events
map_load
Called when a map finishes loading.
map_preload
Called before a map loads.
tick
Called every game tick (~30 times per second).
pretick
Called before the game tick is processed.
frame
Called every frame (as fast as your FPS).
preframe
Called before each frame is rendered.
precamera
Called before camera is updated. Can modify camera position and orientation.
Parameters:
x, y, z - Camera position
fov - Field of view
vx, vy, vz - Forward vector
v2x, v2y, v2z - Up vector
Returns: Modified camera values (non-final priorities only)
command
Called when a console command is executed.
Returns:
true - Allow command
false - Block command
nil - Allow command (default)
rcon_message
Called when an RCON message is received.
spawn
Called when an object spawns.
prespawn
Called before an object spawns.
unload
Called when the script is being unloaded.
Timers
Schedule functions to run at specific intervals.
Creating a Timer
Timer Return Values
Timer callbacks should return:
true - Continue running the timer
false - Stop the timer (automatically removed)
Removing Timers
One-Shot Timer
Example Scripts
FPS Display
Player Join Monitor
Command Blocker
Custom Camera Shake
Map-Specific Script
API Version Compatibility
Always declare your API version:
Chimera will warn you if:
- Your script uses a newer API version than supported
- Your script uses an older API version (may have compatibility issues)
- No API version is declared
Best Practices
- Always declare
clua_version - Ensures compatibility
- Use appropriate script types - Global for persistent, map for specific
- Clean up in unload - Remove timers, reset state
- Handle nil values - Game data may not always be available
- Avoid heavy operations in frame callbacks - Can impact FPS
- Use timers instead of tick counting - More reliable
- Test thoroughly - Scripts can crash the game if buggy
- Comment your code - Future you will appreciate it
Debugging
Console Output
Error Messages
Lua errors are printed to the console with stack traces. Check the console after script loading to see if any errors occurred.
Reloading Scripts
Use the console command to reload scripts:
This reloads all global scripts without restarting the game.
Script Locations Summary
Security Notes
- Global and map scripts run with full permissions - Be careful with scripts from untrusted sources
- Embedded scripts are sandboxed - Limited I/O access for safety
- Scripts can execute console commands - Including potentially dangerous ones
- Scripts have file system access - Global/map scripts can read/write files
- Always review scripts before running - Especially from unknown sources