Script lifecycle
Script directories, the require search path, metadata tags, Library actions, autoreload, MCP tools, load and unload order, error handling and what the configuration persists.
Directories and modules
| Purpose | Location |
|---|---|
| Scripts | %SystemDrive%\nix\scripts\ |
| Shared Lua modules | %SystemDrive%\nix\scripts\lib\ |
| Script data | %SystemDrive%\nix\script_data\<script file name without .lua>\ |
If SystemDrive is unset, the scripts directory is C:\nix\scripts.
The Library lists .lua files directly in the scripts directory; extension matching is case-insensitive. Subdirectories are not listed. The list is read when the Scripts tab is first built, when Refresh is selected and after a file is deleted; ui.panel also lists its own script's file. Refresh drops the rows of deleted files that are not loaded; a running script whose file is gone keeps running and keeps its row, marked Loaded · File Missing (see Autoreload), until it is unloaded. The folder is not watched for new or deleted files; a loaded script's own file is checked by Autoreload. Open folder creates and opens the scripts directory.
require 'name' uses the standard Lua loader with this search path:
scripts\?.lua;scripts\?\init.lua;scripts\lib\?.luaEach script loads its own copy of a module. C module loading through require is disabled because package.cpath is empty; this does not disable ffi.load. require('jit.util') raises before any searcher runs.
Metadata
Metadata is read from comments at the beginning of the file without executing the script.
-- @name Watermark
-- @author you
-- @version 1.2
-- @description A boxed watermark in the top-right corner.| Tag | Limit | Behaviour |
|---|---|---|
@name | 128 bytes | First non-empty value; defaults to the file name without .lua. |
@author | 128 bytes | First non-empty value. |
@version | 128 bytes | First non-empty value. |
@description | 512 bytes | Multiple values are joined with spaces. |
The parser reads at most 4096 bytes and 64 lines. It skips a UTF-8 BOM and blank lines, and stops at the first non-comment line. Values are truncated at a UTF-8 boundary.
Supported comment forms are --, --- and --[[ ... ]]. Block comments may contain one tag per line; long-bracket forms such as --[==[ are not supported. Tags use @key value; keys are lowercase. Unknown keys are ignored.
Library actions
| Action | Effect |
|---|---|
| Load / Unload | Creates or closes the script's Lua state. Also available through the row's start/stop button. |
| Reload | Unloads the script, then loads its file again. |
| Open settings | Selects the script's settings sub-tab, if one exists. |
| Show in folder | Locates the script file. |
| Autoload | Saves the autoload flag in the configuration. |
| Copy error | Copies the full error and traceback. |
| Delete | Unloads the script and permanently deletes its file. |
Load and unload are available on the script card. Reload is in its title bar; Show in folder, Autoload, Copy error and Delete are in the card's overflow menu.
Autoreload
A loaded script whose file changed on disk is reloaded, exactly as Reload does (shutdown callbacks, then a fresh Lua state; control values and binds are kept). Files are checked only:
- on the first frame the menu is open after being closed (the frame that first paints it open);
- on the next frame after the game window regains focus (alt-tab back).
There is no polling and no per-frame check. A file counts as changed when its last-write time or its size differs from when the script loaded it. The reload runs at the start of the frame, before the frame's script callbacks, so the reloaded script's UI predicates run before the menu is drawn.
- Unchanged file: nothing happens.
- New file fails to load: the script stays unloaded and displays Error, as after Reload. Its file is still checked, so the next save is tried again.
- Deleted or moved file: the script keeps running. The card shows
Loaded · File Missingand MCP'slua_list_scriptsreportsfile_missing. A file put back unchanged clears the mark; a changed one is reloaded. Refresh (and MCP'slua_scripts_refresh) leaves such a script running too, with the same mark; once it is unloaded, the next Refresh drops its row.
Only scripts that are running (or whose last autoreload failed) are checked; new files are listed by Refresh.
MCP tools
With Misc → Utility → General → MCP Server on, an agent drives scripts through these tools. They act on the same scripts, states and controls as the Scripts tab; they add no Lua API.
| Tool | Effect |
|---|---|
lua_list_scripts | Every .lua in the scripts folder with its status (loaded, error, not_loaded), metadata, autoload flag, last error, live callbacks per kind, output_cursor and panel (the menu path of its ui.panel sub-tab, or null); a running script whose file is gone is listed with file_missing. Reads the folder itself. |
lua_scripts_refresh | Refresh, as on the Scripts tab: lists new files and drops the rows of deleted files that are not loaded (see Autoreload). Answers what lua_list_scripts does. |
lua_load_script, lua_unload_script | Load / Unload. Loading works without the menu or the Library ever having been opened; ui.panel builds the sub-tab on demand. |
lua_reload_script | Reload, then waits until the reloaded script has run verify_frames frames (default 3, 0–30) of timers, UI tick and render with no error; answers ok, frames_run, or failure with the error and error_frame. |
lua_script_error | The latest load or callback error with its traceback, and the number of disabled callbacks. |
lua_script_output | The script's print / color_print output, its errors and its load and unload edges; 256 lines kept, polled with a cursor that continues across reloads. |
lua_eval | Runs a snippet (tried as return <code> first) in a persistent scratch state, <scratch>, with the full API, or inside a loaded script's own state with script. Answers the returned values, printed output and the error. timeout_ms is the budget (default 1000, at most 2000); past it the snippet raises eval budget of N ms exhausted. reset unloads the scratch state first: its shutdown callbacks run, then its globals, callbacks, timers and UI go, its MCP Scratch settings sub-tab included. |
lua_ui_get, lua_ui_set | Read or write a loaded script's control by its id. lua_ui_set writes as a user edit does and runs the control's on_change handlers before it answers. |
panorama_eval | Runs JavaScript in a panel's context (default CSGOMainMenu) through the engine's runner, tried as return ( <code> ) first; no time budget. |
Load and unload order
On load:
- A new Lua state is created and the API is registered.
- The file executes from top to bottom.
- Per-frame callbacks (
render,key, timers, UI) begin on the next frame; hook and game-event callbacks can run as soon as the file has executed.
If execution fails during load, registered shutdown callbacks run and the state is closed.
On unload:
shutdowncallbacks run while the script's UI and controls are still available.- Control values, key binds, the settings of the script's ESP elements and the elements' choice of its styles with their settings are retained for the next load.
- UI nodes, textures, particle effects, ESP elements, styles, callbacks and timers are removed.
- The Lua state is closed, including
__gcprocessing.
utils.unload_script() schedules unloading at the end of the current frame, after render callbacks.
Errors
Calls into Lua are protected. Error handling depends on where the failure occurs:
| Context | Result |
|---|---|
| Initial file execution | The script remains unloaded and displays Error. |
| Callback | The failing callback is disabled until reload; other callbacks continue. |
| Timer | The timer is removed, including repeating timers. |
| UI handler | The failing handler is disabled; see the relevant UI method. |
| ESP element function | That element is disabled until reload and counts as a disabled callback; see esp errors. |
| Style function | That style is disabled for that element until reload, counts as a disabled callback, and the element draws its built-in look; see styles. |
Runtime errors include a file name, line number and traceback; a syntax error has the file name and line only. They are printed in red in the game console as [lua] name.lua: ..., shown on the script card, and displayed as a notification containing the first line for five seconds. A loaded script with disabled callbacks displays Loaded · N Callbacks Disabled (translated with the menu language).
A numeric error value is converted to text. Other non-string error values use __tostring if it returns a string; otherwise the message is (error object is a <type> value).
An error whose message names a removed global, such as attempt to call global 'color_t' (a nil value), gets a line appended after the message and its traceback naming the replacement, for example 'color_t' was removed from the Lua API; use color(r, g, b, a) instead.
Configuration and persistence
Lua globals, module state and upvalues are not shared between scripts and do not survive unload or reload. Files remain accessible through io, os and fs; Lua-state isolation is not filesystem isolation.
The configuration stores the following under each script's file name:
- loaded and autoload flags;
- control values, keyed by control ID;
- control key binds.
Renaming the file loses this association. File-name characters above U+00FF do not survive a configuration round trip. Hotkey modes, labels, item lists and tooltips are not saved; they are supplied by the script.
When a configuration is loaded:
- scripts marked loaded or autoload are loaded;
- scripts marked neither are unloaded;
- scripts that remain loaded receive the configuration's control values, triggering
on_changehandlers for the values that change; - scripts absent from the configuration remain running.
Saving a configuration while a script is loaded records that loaded state, so the script is loaded with that configuration even without a separate autoload flag.
