Snippets
Small, self-contained pieces. For full worked examples see the game pages under Games.
Watermark
Section titled “Watermark”-- draw ping-free info: the time and the frame the runtime is onclient.set_event_callback("paint", function() local w, h = client.screen_size() local hour, minute, second = client.system_time() local text = string.format("%02d:%02d:%02d | %d fps", hour, minute, second, 0) local tw, th = renderer.measure_text(nil, text) renderer.rectangle(w - tw - 22, 14, tw + 8, th + 8, 32, 32, 32, 200) renderer.text(w - tw - 18, 18, 235, 235, 235, 255, nil, 0, text)end)A menu toggle with a callback
Section titled “A menu toggle with a callback”local toggle = ui.new_checkbox("Lua", "Main", "My feature")ui.set_callback(toggle, function(item) ui.notify(ui.get(item) and "on" or "off")end)Persisting a value
Section titled “Persisting a value”local runs = (database.read("runs") or 0) + 1database.write("runs", runs)client.log("loaded", runs, "times")An HTTP GET (needs the http capability)
Section titled “An HTTP GET (needs the http capability)”if http then http.get("https://api.ipify.org?format=json", function(ok, res) if ok then client.log(json.decode(res.body).ip) end end)endA delayed call
Section titled “A delayed call”client.delay_call(2.0, function(msg) client.log(msg) end, "two seconds later")