Skip to Content

Script lifecycle

Script directories, the require search path, metadata tags, Library actions, load and unload order, error handling and what the configuration persists.


Directories and modules

PurposeLocation
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 refreshed when the menu opens, when Refresh is selected, and after a file is deleted. Files are not watched for changes. 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\?.lua

Each 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.

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.
TagLimitBehaviour
@name128 bytesFirst non-empty value; defaults to the file name without .lua.
@author128 bytesFirst non-empty value.
@version128 bytesFirst non-empty value.
@description512 bytesMultiple 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

ActionEffect
Load / UnloadCreates or closes the script's Lua state. Also available through the row's start/stop button.
ReloadUnloads the script, then loads its file again.
Open settingsSelects the script's settings sub-tab, if one exists.
Show in folderLocates the script file.
AutoloadSaves the autoload flag in the configuration.
Copy errorCopies the full error and traceback.
DeleteUnloads 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.

Load and unload order

On load:

  1. A new Lua state is created and the API is registered.
  2. The file executes from top to bottom.
  3. Registered callbacks begin on the next frame.

If execution fails during load, registered shutdown callbacks run and the state is closed.

On unload:

  1. shutdown callbacks run while the script's UI and controls are still available.
  2. Control values, key binds and the settings of the script's ESP elements are retained for the next load.
  3. UI nodes, textures, particle effects, ESP elements, callbacks and timers are removed.
  4. The Lua state is closed, including __gc processing.

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:

ContextResult
Initial file executionThe script remains unloaded and displays Error.
CallbackThe failing callback is disabled until reload; other callbacks continue.
TimerThe timer is removed, including repeating timers.
UI handlerThe failing handler is disabled; see the relevant UI method.
ESP element functionThat element is disabled until reload and counts as a disabled callback; see esp errors.

Errors include a file name, line number and traceback. 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.

Non-string error values use __tostring, if available; 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 second line 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. Non-ASCII file names 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_change handlers;
  • 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.

On this page