Quick start
From an empty folder to a running script in two minutes.
1. Add a script
Scripts are plain .lua text files. Open the Lua tab in the menu and pick one of three ways:
New Script
Creates script_1.lua from a template and opens it in the built-in editor.
From Clipboard
Copy any example from these docs and press it. The file is named after the -- name: line; Markdown code fences are removed for you.
Folder
Opens the scripts folder. Drop .lua files in; they show up within 2 seconds.
The folder is adolfjon_files\scripts\ next to the program. New scripts start turned off; switch them on in the list.
2. The header
The first lines of a script describe it. They are shown on the script's page. All lines are optional, but write them: they make a script easy to share.
-- name: Kill Feed
-- author: someone
-- version: 1.2
-- description: Shows kills top right
-- permissions: settings, chat, network| Line | Meaning |
|---|---|
name | Display name. From Clipboard also uses it for the file name. |
author | Who wrote it. |
version | Any text, for example 1.2. |
description | One line about what it does (120 characters shown). |
permissions | Which of settings, chat, network the script asks for. The user still ticks each one; see Sandbox and limits. |
Only the first 40 lines are read for the header.
3. Your first script
-- name: First Script
-- author: you
-- version: 1.0
-- description: A panel with your health and a setting.
ui.slider("size", "Text size", 12, 30, 18)
local white = color(240, 242, 246)
function on_frame()
local me = game.local_player()
if not me then return end
local x, y, shown = hud.panel("hp", "Health", 140, 34)
if shown then
draw.text(x + 10, y + 6, me.health .. " HP", white, ui.get("size"))
end
end
function on_kill(e)
print("killed " .. e.victim .. " with " .. e.weapon)
end- Code at the top runs once when the script loads: make settings, colours and images there.
on_frameruns every frame. Drawing works only here.on_killruns when you get a kill. See Events for all of them.printgoes to the console on the Lua page.
4. How a script runs
- Turning a script on creates a fresh Lua state for it alone. Scripts never see each other's variables, and one broken script cannot break another.
- The API is added, then the helper prelude (
events,vec,bit, math extras), then your file runs from top to bottom. - From then on your callbacks are called:
on_tick,on_frame, events,on_menuwhile its tab is open. - When the file changes on disk (checked every second) or you press Save in the editor, the script unloads and loads again.
on_unloadruns first. Local variables start over;ui.*values,dband files are kept. - If anything throws an error, the script stops and the error shows in a box on its page with Copy and Edit. Fix it and save; it loads again. See Errors and fixes.
5. Where things are stored
| Path | What |
|---|---|
scripts/*.lua | Your scripts. |
scripts/data/<script>/ | The script's own folder: images, fonts and files it reads and writes. |
scripts/_settings.json | Which scripts are on, ui.* values, granted permissions, db storage, HUD panel positions and load order. |
Three samples are written on first run: snake (F6 to open, arrow keys, Space restarts), hello_esp (names above enemies) and kill_counter. Read them; they are short.