Script Lifecycle
Aimsense isolates scripts into private sandboxes with automatic resource tracking and UI state serialization.
Isolated Environments
Section titled “Isolated Environments”Each script runs inside its own lua_State sandbox:
- Globals declared in one script do not pollute or conflict with other scripts.
- Engine namespaces (
render,entity,ui,client) are globally accessible across all scripts. - Memory and state are fully scoped per script instance.
Automatic Cleanup on Unload
Section titled “Automatic Cleanup on Unload”When a script unloads:
- UI Widgets: All custom tabs, groupboxes, widgets, and popup gears are removed from the menu.
- Callbacks: Callbacks registered via
client.add_callbackare detached. - Timers: Delayed calls scheduled via
client.delay_callare cancelled. - Network Requests: Pending async
networkandhttprequests are cancelled to avoid invoking dead callback scopes.
State Persistence
Section titled “State Persistence”Menu widgets created by scripts are automatically saved to disk:
- Path:
aimsense/scripts/data/<script_name>.cfg - Trigger: Serialized whenever the script unloads or when saving a cheat config in Settings.
- Key Index: Values are mapped by
Groupbox Name + Widget Name + Widget Type.
Reloading & Deferred Memory Cleanup
Section titled “Reloading & Deferred Memory Cleanup”- When a script reloads or unloads, the engine defers freeing the Lua environment by 5 seconds.
- This prevents game crashes if in-flight callbacks finish executing during the unload operation.
Triggering reloads programmatically:
-- Unload current scriptclient.unload_script()
-- Reload current scriptclient.reload_script()The unload Callback
Section titled “The unload Callback”Use the unload callback to restore engine state or external changes that cannot be cleaned up automatically:
- Restoring modified ConVars (
cvar.*) - Releasing custom materials (
material:decrement_ref_count()) - Freeing animated GIF memory (
gif:release())
local sv_cheats = cvar.sv_cheatslocal original_val = sv_cheats:int()
-- Enable sv_cheatssv_cheats:int(1)
-- Restore on unloadclient.add_callback("unload", function() sv_cheats:int(original_val)end)