Scripting

Script modules

Make a module with settings, a keybind and its own handlers.

Making a module

local hud = lumen.module{
    name = "My HUD",
    description = "What it does, shown in the menu.",
    category = "HUD",
}

lumen.module returns the module’s table. The module shows up in the menu under its category, can be bound to a key, shows in the array list when it is on, and its settings and on/off state are saved in your config like any other module.

FieldNeededWhat it is
nameYesThe module’s name, 1 to 40 characters. It has to be new: a script cannot replace a built-in module
descriptionNoThe text under its name in the menu
categoryNoCombat, Movement, Render, HUD, Player, World or Misc. Misc when left out

Settings

Add settings right after making the module. Each one has an id, which you use in your code, and a label, which the menu shows.

hud:addToggle("shadow", "Text shadow", true, "A soft shadow under the text")
hud:addSlider("size", "Size", 18, 8, 40, "Text size in pixels")
hud:addDropdown("corner", "Corner", {"Left", "Right"}, "Left", "Which side it sits on")
hud:addText("label", "Label", "Hello", "The text it shows")
hud:addColor("color", "Colour", "FFC566", "The text colour")
MethodArguments
addToggleid, label, default (true or false), description
addSliderid, label, default, min, max, description
addDropdownid, label, list of options, default option, description
addTextid, label, default text, description
addColorid, label, default colour as "RRGGBB", description

The label and description can be left out.

Reading and changing settings

local size = hud:get("size")        -- 18
hud:set("label", "Goodbye")
  • Toggles come back as true or false, sliders as numbers, dropdowns and text as strings.
  • Colours come back as "RRGGBBAA", with the opacity from the colour picker as the last two digits. The draw functions take that form as it is.
  • set keeps a slider inside its min and max.

Settings can also be changed from chat with .set, using the module’s name and the setting’s label.

Handlers

Give the module functions with these names and Lumen calls them while the module is on:

function hud:onEnable() print("on") end
function hud:onDisable() print("off") end
function hud:onTick() end                    -- every game tick, 20 a second
function hud:onRender() end                  -- every frame; the draw functions work here
function hud:onChat(message, sender) end     -- a chat message arrived; return true to hide it
function hud:onAttack(name) end              -- you hit something; return true to cancel the hit
function hud:onKey(key, down) end            -- a key was pressed or released

Write them with a colon, as above. Lumen passes the module as the first argument, so self inside a handler is the module, and self:get("size") reads its settings. If you write function hud.onChat(message, sender) with a dot, message will be the module instead of the message.

These are the common ones. Every event has a module handler, named on plus the event with a capital, like onPlayerJoin or onDeath. Events and commands lists them all and explains what each handler gets.

Other methods

MethodWhat it does
module:isEnabled()true when the module is on
module:setEnabled(on)Turns it on or off
module:toggle()Flips it
module:name()Its name

Reloading

When a script reloads, its modules are made again from the new code. They keep their place in the menu, their keybinds and their saved settings, and they come back on if they were on.

When you unload or delete a script, its modules turn off but stay in the menu until the game restarts; their settings page says the script is not loaded. They work again as soon as the script loads again.