Scripting
API reference
Every function a script can call: the player, the world, chat, modules, input, drawing, timers and storage.
Arguments in square brackets can be left out.
client
| Function | Returns | What it does |
|---|---|---|
client.print(...) | Writes to your chat. Only you see it. Plain print does the same | |
client.notify(title, [text], [seconds]) | Shows a Lumen notification, for 4 seconds unless you say otherwise | |
client.say(text) | Sends a chat message. Text starting with / is sent as a game command | |
client.command(line) | true, or false and the reason | Runs a Lumen command without the prefix, for example "toggle zoom" |
client.time() | number | Milliseconds from a steady clock. Use differences for timing |
client.screen() | string | The screen on show, like "hud_screen" in game, "chat_screen" or "pause_screen" |
client.server() | string | The address of the server you are on |
client.accent() | string | The menu’s accent colour as "RRGGBB" |
client.version() | string | Lumen’s version |
client.command does not run the commands that reach your files, load other scripts or change your setup: config (all but config reload), path, steal path, cape path, lua, panic, prefix, bind and unbind. For those it returns false and the reason.
player
Outside a world, player.inWorld() is false and the rest return zeros, empty text or nothing.
| Function | Returns |
|---|---|
player.inWorld() | true while you are in a world |
player.name() | Your name |
player.position() | x, y, z of your feet |
player.eyes() | x, y, z of your eyes |
player.velocity() | x, y, z in blocks per tick. Multiply by 20 for blocks per second |
player.rotation() | yaw, pitch in degrees |
player.health() | health, max health (2 points per heart) |
player.onGround() | true when standing on something |
player.sneaking() | true when sneaking |
player.sprinting() | true when sprinting |
player.moving() | true when a movement key is held |
Functions return several values at once, so take them like this:
local x, y, z = player.position()
local health, max = player.health()
Tick and frame positions
The game moves you 20 times a second and draws you many more times in between. Inside a render handler, player.position() and player.eyes() are where you are in the frame being drawn, so what you draw on your character stays on it while you move. Anywhere else they are the last tick’s values, which is what game logic wants. The other values always come from the last tick.
| Function | Returns |
|---|---|
player.renderPosition() | x, y, z of your feet in the frame being drawn, wherever it is called |
player.renderEyes() | x, y, z of your eyes in the frame being drawn |
player.tickPosition() | x, y, z of your feet at the last tick |
Take the position inside the render handler, each frame. One saved in a tick handler and drawn later trails behind you.
What you carry
These only read. A script cannot move or use items.
| Function | Returns |
|---|---|
player.inventory() | A list of the slots that hold something |
player.heldItem() | The item in your hand, or nothing |
player.offhand() | The item in your other hand, or nothing |
player.armor() | A table with head, chest, legs and feet. A piece you do not wear is left out |
player.effects() | A list of your potion effects, each with name, level, seconds and infinite |
An item is a table with these fields:
| Field | What it is |
|---|---|
name | The item, like "diamond_sword" |
count | How many are in the stack |
durability, maxDurability | Uses left and uses when new. Only on items that wear |
slot | 1 to 36, with 1 to 9 the hotbar. On inventory() and heldItem() entries |
selected | true for the slot in your hand. On inventory() entries |
local held = player.heldItem()
if held and held.durability and held.durability < 20 then
client.notify("Tool", held.name .. " is about to break")
end
What you look at
player.lookingAt() returns what is under your crosshair, or nothing. It reports what the game itself picked for the crosshair, so it reaches only as far as that does.
target | Other fields |
|---|---|
"block" | name, x, y, z, distance, and face: "up", "down", "north", "south", "west" or "east" |
"entity" | The same fields as an entry of world.entities() |
Moving the player
| Function | What it does |
|---|---|
player.setVelocity(x, y, z) | Sets your velocity, in blocks per tick |
player.setPosition(x, y, z) | Moves your feet to a point |
player.jump([height]) | Sets your upward velocity, a normal jump when left out |
Inside a tick handler they apply at once; anywhere else, at the start of the next tick. Servers check movement, and many will pull you back or flag you for it.
These three need a Premium key. On a free key they are not in the player table, so check before you call one: if player.setVelocity then ... end.
world
| Function | Returns |
|---|---|
world.players() | Every other player near you |
world.entities() | Every entity near you: players, mobs, items and the rest |
world.dimension() | The dimension’s name: "Overworld", "Nether" or "TheEnd" |
world.time() | The time of day from 0 to 1: 0 is noon, 0.25 sunset, 0.5 midnight, 0.75 sunrise |
world.serverAddress() | The address and the port. The address is "world" in a world of your own and "realm" on a Realm, with no port |
The last three return nothing while you are not in a world.
world.players() and world.entities() return a list of tables with these fields:
| Field | What it is |
|---|---|
name | Name, formatting removed |
type | The entity type, like "zombie" or "armor_stand"; for a dropped item, the item |
kind | "player", "hostile", "passive", "item" or "other" |
x, y, z | Position of its feet, in the frame being drawn |
distance | Blocks from you |
health, maxHealth | Health |
yaw, pitch | Where it is looking |
id | Its id in this world |
friend | true when it is on your friends list |
teammate | true when it is on your team |
bot | true when Anti Bot is on and is sure it is a server bot |
maybeBot | true when Anti Bot is on and only doubts it: new in view and not in the server’s player list yet, or sharing a name tag with another player |
invisible | true when invisible |
hurtTime | Ticks left of its hurt flash, 0 when not hurt |
held | The item it is holding, like "diamond_sword", or empty |
for _, p in ipairs(world.players()) do
print(p.name, math.floor(p.distance))
end
Reading blocks
| Function | Returns |
|---|---|
world.getBlock(x, y, z) | The block’s name, whether it is air, and whether it is solid. Nothing for a place that is not loaded |
local name, air, solid = world.getBlock(0, 64, 0)
solid is a guess from the name: false for air, liquids, plants and the other things you walk through. One block costs little to read, but a big scan every tick adds up against the limits, so spread it over ticks.
world.getBlock needs a Premium key. On a free key it is not in the world table, so check before you call it: if world.getBlock then ... end. player.lookingAt() gives the block under your crosshair on any key.
modules
Module names are matched loosely: "killaura", "Kill Aura" and "KillAura" all find the same module.
| Function | What it does |
|---|---|
modules.isEnabled(name) | true when that module is on |
modules.toggle(name, [on]) | Flips a module, or turns it on or off when on is given |
modules.list() | The name of every module |
input
Both return false while the game window is not focused.
| Function | What it does |
|---|---|
input.isKeyDown(key) | true while the key is held. Takes a Windows key code or a name like "F", "SPACE" or "SHIFT" |
input.isMouseDown(button) | true while the button is held. 1 is left, 2 right, 3 middle |
draw
These only work inside a render handler. Positions are screen pixels, with 0, 0 at the top left.
Colours can be "RRGGBB", "RRGGBBAA" (the last two digits are opacity), or a number like 0xFF8800.
| Function | What it does |
|---|---|
draw.size() | The screen’s width, height |
draw.text(text, x, y, [size], [colour], [align], [shadow]) | Draws text. size is 16 when left out, align is "left", "center" or "right", shadow is on unless false |
draw.textSize(text, [size]) | The width, height the text would take. draw.measureText is another name for it |
draw.rect(x, y, w, h, colour, [radius]) | A filled rectangle, rounded by radius |
draw.outline(x, y, w, h, colour, [width], [radius]) | A rectangle’s outline |
draw.line(x1, y1, x2, y2, colour, [width]) | A line |
draw.circle(x, y, radius, colour, [filled], [width]) | A circle, filled unless filled is false |
draw.project(x, y, z) | Where a world point is on screen, as x, y. Nothing when it is behind you. draw.worldToScreen is another name for it |
draw.worldLine(x1, y1, z1, x2, y2, z2, colour, [width]) | A line between two world points |
draw.worldBox(x1, y1, z1, x2, y2, z2, colour, [width]) | The outline of a box between two world corners |
draw.worldText(text, x, y, z, [size], [colour], [shadow]) | Text centred on a world point. Returns true when the point is on screen |
draw.tracer(x, y, z, colour, [width]) | A line from the middle of the screen to a world point. Not drawn while the point is behind you |
lumen.on("render", function()
if not player.inWorld() then return end
local w, h = draw.size()
draw.rect(w - 130, 10, 120, 30, "00000088", 6)
draw.text("Hello", w - 70, 17, 16, client.accent(), "center")
end)
lumen.on("render", function()
for _, p in ipairs(world.players()) do
draw.worldText(p.name, p.x, p.y + 2.3, p.z, 14, p.friend and "55FF55" or "FFFFFF")
if p.distance < 30 then draw.tracer(p.x, p.y + 1, p.z, "FF5555AA", 1.5) end
end
end)
timer
| Function | What it does |
|---|---|
timer.after(seconds, function) | Runs the function once, after that many seconds |
timer.every(seconds, function) | Runs the function again and again, that many seconds apart |
Both return a handle:
| Method | What it does |
|---|---|
handle:cancel() | Stops the timer. true when it was still running |
handle:active() | true while the timer is still going to fire |
timer.after(3, function() print("three seconds later") end)
local ticker = timer.every(0.5, function() print("twice a second") end)
ticker:cancel()
- Timers run with the game’s ticks, so they wait while you are not in a world and are never finer than a tick (0.05 seconds).
timer.every(0, f)runs every tick. - A repeating timer that fell behind runs once, not once for every turn it missed.
- A timer whose function fails is cancelled.
- A script can have 256 timers at a time. They all go when the script is unloaded.
- Timers need a script file, so they do not work in
.lua run.
storage
Each script has its own storage that survives reloads and restarts.
| Function | What it does |
|---|---|
storage.set(key, value) | Keeps a value under a key. Setting nil removes the key |
storage.get(key, [default]) | The value, as a fresh copy each time. default comes back when the key is not there |
storage.remove(key) | Removes a key. true when it was there |
storage.keys() | A list of every key |
storage.set("home", { x = 100, y = 64, z = -20, tags = { "base", "bed" } })
local home = storage.get("home")
local kills = storage.get("kills", 0)
storage.set("kills", kills + 1)
- A value is a boolean, a number, text, or a table of those. A table is either a list (
{1, 2, 3}) or has text keys ({x = 1}), not both, and at most 16 tables deep. Functions and numbers that are not finite are refused with an error. - Keys are text, 1 to 128 characters. A script may keep 1 MB in total. Past that,
storage.setfails with an error. - Changes are written about two seconds after they are made, and when the script unloads. Setting a key to what it already holds writes nothing, so calling
storage.setevery tick is fine. - The storage is one JSON file named after the script, in the
ScriptDatafolder besideScripts. A script cannot choose the file or reach another script’s. - Storage needs a script file, so it does not work in
.lua run.
lumen
| Function | What it does |
|---|---|
lumen.module{name, description, category} | Makes a module. See Script modules |
lumen.on(event, function) | Adds a handler. See Events and commands |
lumen.command(name, description, function) | Adds a chat command |
lumen.script | Not a function: the script’s name, its file name without .lua |
Lua itself
Scripts have Lua’s string, table, math, utf8 and coroutine libraries, and os.clock, os.time, os.date and os.difftime. load works on Lua source text. See Limits and safety for what is left out.