Lua · Examples · UI
Script with its own page
A page inside the Lua tab with stats, a list, buttons and a notepad that saves to a file.
Uses: on_menu, menu.*, notepad, files
script_with_its_own_page.lua
-- name: Match Notes
-- author: Adolfjon
-- version: 1.0
-- description: A page with match stats and a notes notepad.
local kills, deaths, hs = 0, 0, 0
local log = {}
local pick = 0
local note_title = "Match notes"
function on_kill(e)
kills = kills + 1
if e.headshot then hs = hs + 1 end
table.insert(log, 1, (e.victim ~= "" and e.victim or "?") .. " " .. e.weapon .. (e.headshot and " HS" or ""))
if #log > 50 then table.remove(log) end
end
function on_death() deaths = deaths + 1 end
function on_menu()
menu.section("THIS MATCH")
menu.text("Kills " .. kills .. " Deaths " .. deaths .. " HS " .. hs)
menu.progress("Headshot rate", kills > 0 and hs / kills or 0)
pick = menu.list("Kill log", pick, log, 6)
if menu.button("Reset") then kills, deaths, hs, log, pick = 0, 0, 0, {}, 0 end
menu.same_line()
if menu.button("Copy log") then clipboard.set(table.concat(log, "\n")) end
menu.section("NOTES")
note_title = menu.input("Title", note_title)
if menu.button("Open notes") then
notepad.open("notes", note_title, files.read("notes.txt") or "")
end
menu.tooltip("Save in the notepad writes notes.txt to this script's data folder.")
end
function on_notepad_save(id, text)
if id == "notes" then files.write("notes.txt", text) end
endInstall it
- Press Copy on the code above.
- In the menu, open Lua and press From Clipboard. The file is named from its
-- name:line. - Turn the script on in the list. Its settings show on its own tab.
Change anything you like and press Save (Ctrl+S) in the editor; the script reloads at once. See Getting started for the other ways to add scripts.