Guides

Examples

Complete scripts you can paste and adapt.

Hello world#

print("Hello from Luna!")

events.present_queue:add(function()
    render.text(10, 10, "Hello World!", Color(255, 255, 255))
end)

Player boxes#

local g = ui.Group("lua esp")
local boxes = g.Checkbox("boxes", true)
local names = g.Checkbox("names", true)
local enemies_only = g.Checkbox("enemies only", true)
local box_color = g.ColorPicker("box color", Color(255, 90, 90))

events.present_queue:add(function()
    local me = entity.get_local_player()
    entity.players:for_each(function(pawn)
        if pawn == me or not pawn:is_alive() or pawn:is_dormant() then return end
        if enemies_only:get() and not pawn:is_enemy() then return end
        local box = pawn:get_bounding_box()
        if not box then return end
        local x, y, w, h = box.mins.x, box.mins.y, box:width(), box:height()
        if boxes:get() then
            render.rect(x, y, w, h, box_color:get())
            local hp = math.clamp(pawn.m_iHealth / 100, 0, 1)
            render.rect_filled(x - 6, y + h * (1 - hp), 3, h * hp, Color.Percent(hp))
        end
        if names:get() then
            render.text(x + w / 2, y - 14, pawn:get_name(), Color.White(), "regular", nil, "co")
        end
    end)
end)

Hit log#

local g = ui.Group("hit log")
local log_hits = g.Checkbox("log hits", true)
local log_kills = g.Checkbox("log kills", true)

events.event:add(function(e)
    local me = entities.get_local_controller()
    local attacker = e:get_controller("attacker")
    if not me or attacker ~= me then return end
    local victim = e:get_controller("userid")
    local name = victim and victim:get_name() or "?"
    if e:get_name() == "player_hurt" and log_hits:get() then
        print(string.format("[HIT] %s for %d (hp left %d, hitgroup %d)", name, e:get_int("dmg_health"), e:get_int("health"), e:get_int("hitgroup")))
    elseif e:get_name() == "player_death" and log_kills:get() then
        print(string.format("[KILL] %s%s", name, e:get_bool("headshot") and " (HS)" or ""))
    end
end)

Saved settings#

local g = ui.Group("fov circle")
local enabled = g.Checkbox({id = "enabled", label = "Enabled"}, true)
local radius = g.SliderInt("radius", 10, 400, 120)
local tint = g.ColorPicker("color", Color(255, 255, 255, 200))

local stats = database.load()
stats.loads = (stats.loads or 0) + 1
database.save(stats)
print("loaded " .. stats.loads .. " times")

events.present_queue:add(function()
    if not enabled:get() then return end
    local w, h = render.screen_size()
    render.circle(w / 2, h / 2, radius:get(), tint:get(), 1.5)
end)
local g = ui.Page("settings").Group("lua theme")
local accent = g.ColorPicker("accent", Color(255, 120, 180))
local background = g.ColorPicker("window background", Color(10, 10, 14))

local function apply()
    menu.set_accent(accent:get())
    menu.set_color("window_bg", background:get())
end

accent:on_change(apply)
background:on_change(apply)
apply()

Websocket#

local socket = websocket.connect("wss://echo.websocket.org", {["User-Agent"] = "luna"})

socket:on_open(function()
    socket:send({type = "hello", map = globals.mapname()})
end)

socket:on_message(function(data, binary)
    print("received", data)
end)

socket:on_close(function(code, reason)
    print("closed", code, reason)
end)

socket:on_error(function(err)
    print("websocket error", err)
end)

Talking to other Luna users#

relay.user = "luna user"
relay.join("global")

relay.on_message(function(room, data, user)
    print(user .. " in " .. room .. ": " .. tostring(data.text))
end)

relay.send("global", {text = "hello"})

relay.get("visits", function(value)
    relay.set("visits", (tonumber(value) or 0) + 1)
end)