Scripting
Examples
Complete scripts to copy: a CPS counter, a low health warning, a chat filter, a calculator, a death counter and more.
Save any of these as a .lua file in the Scripts folder (.lua folder opens it), then run .lua reload.
Low health warning
A module that warns you once each time your health drops below a level you pick.
local warn = lumen.module{
name = "Low Health",
description = "Warns you when your health drops low.",
category = "HUD",
}
warn:addSlider("at", "Warn at", 6, 1, 20, "Health points, 2 per heart")
local warned = false
function warn:onTick()
local health = player.health()
if health <= self:get("at") then
if not warned then
client.notify("Low health", string.format("%.0f health left", health), 3)
warned = true
end
else
warned = false
end
end
Clicks per second
Counts your left and right clicks over the last second and draws them where you choose.
local cps = lumen.module{
name = "Script CPS",
description = "Left and right clicks per second.",
category = "HUD",
}
cps:addSlider("x", "Across", 5, 0, 100, "Percent of the screen's width")
cps:addSlider("y", "Down", 30, 0, 100, "Percent of the screen's height")
cps:addColor("color", "Colour", "FFFFFF")
local clicks = { {}, {} }
local held = { false, false }
local function count(list, now)
while list[1] and now - list[1] > 1000 do table.remove(list, 1) end
return #list
end
function cps:onRender()
if not player.inWorld() then return end
local now = client.time()
for button = 1, 2 do
local down = input.isMouseDown(button)
if down and not held[button] then table.insert(clicks[button], now) end
held[button] = down
end
local w, h = draw.size()
local text = string.format("%d | %d CPS", count(clicks[1], now), count(clicks[2], now))
draw.text(text, w * self:get("x") / 100, h * self:get("y") / 100, 18, self:get("color"))
end
Chat filter
Hides chat messages that contain any word on your list. The list is a text setting, so you can change it from the menu or with .set chat filter words ....
local filter = lumen.module{
name = "Chat Filter",
description = "Hides chat messages with words you pick.",
category = "Misc",
}
filter:addText("words", "Words", "discord.gg,free rank", "Comma separated")
function filter:onChat(message, sender)
local text = message:lower()
for entry in self:get("words"):lower():gmatch("[^,]+") do
local word = entry:match("^%s*(.-)%s*$")
if word ~= "" and text:find(word, 1, true) then return true end
end
end
Calculator command
.calc 2 * (3 + 4) prints the answer.
lumen.command("calc", "Works out a sum. .calc 2 * (3 + 4)", function(args)
local sum = table.concat(args, " ")
if not sum:match("^[%d%s%.%+%-%*/%%%^%(%)]+$") then
print("Only numbers and + - * / % ^ ( )")
return
end
local run = load("return " .. sum, "calc", "t", {})
local ok, answer = pcall(run or error)
print(ok and (sum .. " = " .. tostring(answer)) or "That isn't a sum")
end)
Coordinates with direction
Your position and the way you are facing, under the hotbar’s corner.
local coords = lumen.module{
name = "Script Coords",
description = "Your coordinates and facing.",
category = "HUD",
}
local directions = { "South", "South West", "West", "North West", "North", "North East", "East", "South East" }
function coords:onRender()
if not player.inWorld() then return end
local x, y, z = player.position()
local yaw = player.rotation()
local facing = directions[math.floor(((yaw % 360) + 22.5) / 45) % 8 + 1]
local w, h = draw.size()
draw.text(string.format("%d, %d, %d", math.floor(x), math.floor(y), math.floor(z)), 10, h - 50, 16, client.accent())
draw.text(facing, 10, h - 30, 14, "CCCCCC")
end
Good game
Says gg once when a game ends. Change the phrase to the one your server uses.
local phrase = "won the game"
local last = -math.huge
lumen.on("chat", function(message)
local now = client.time()
if message:lower():find(phrase, 1, true) and now - last > 10000 then
last = now
client.say("gg")
end
end)
Death counter
Counts your deaths across sessions with storage, prints where each one happened, and reminds you of the place a minute later with a timer.
lumen.on("death", function(x, y, z)
local deaths = storage.get("deaths", 0) + 1
storage.set("deaths", deaths)
local where = string.format("%d, %d, %d", math.floor(x), math.floor(y), math.floor(z))
print("Death " .. deaths .. " at " .. where)
timer.after(60, function()
client.notify("Your items", "You died at " .. where, 6)
end)
end)
lumen.command("deaths", "Shows how many times you have died.", function()
print("Deaths: " .. storage.get("deaths", 0))
end)