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

FunctionReturnsWhat 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 reasonRuns a Lumen command without the prefix, for example "toggle zoom"
client.time()numberMilliseconds from a steady clock. Use differences for timing
client.screen()stringThe screen on show, like "hud_screen" in game, "chat_screen" or "pause_screen"
client.server()stringThe address of the server you are on
client.accent()stringThe menu’s accent colour as "RRGGBB"
client.version()stringLumen’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, 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.

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

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

FunctionReturns
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:

FieldWhat it is
nameThe item, like "diamond_sword"
countHow many are in the stack
durability, maxDurabilityUses left and uses when new. Only on items that wear
slot1 to 36, with 1 to 9 the hotbar. On inventory() and heldItem() entries
selectedtrue 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.

targetOther 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()

world

FunctionReturns
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:

FieldWhat it is
nameName, formatting removed
typeThe entity type, like "zombie" or "armor_stand"; for a dropped item, the item
kind"player", "hostile", "passive", "item" or "other"
x, y, zPosition of its feet, in the frame being drawn
distanceBlocks from you
health, maxHealthHealth
yaw, pitchWhere it is looking
idIts id in this world
teammatetrue when it is on your team
invisibletrue when invisible
hurtTimeTicks left of its hurt flash, 0 when not hurt
heldThe item it is holding, like "diamond_sword", or empty
for _, p in ipairs(world.players()) do
    print(p.name, math.floor(p.distance))
end

modules

Module names are matched loosely: "togglesprint", "Toggle Sprint" and "ToggleSprint" all find the same module.

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

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

FunctionWhat 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
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, "FFFFFF")
    end
end)

timer

FunctionWhat 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:

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

FunctionWhat 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.set fails 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.set every tick is fine.
  • The storage is one JSON file named after the script, in the ScriptData folder beside Scripts. 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

FunctionWhat 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.scriptNot 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.