Lua · Examples · HUD
Spectator list
A HUD panel with everyone watching you, and a notification when someone joins.
Uses: spectators.list, events, hud.panel
spectator_list.lua
-- name: Spectators
-- author: Adolfjon
-- version: 1.0
-- description: Who is watching you.
ui.checkbox("notify", "Notify on join", true)
local modes = { [2] = "eyes", [3] = "chase", [4] = "free" }
local white = color(235, 238, 245)
local dim = color(150, 156, 168)
events.on("spectator_join", function(e)
if ui.get("notify") then notify.push(e.name .. " is watching you") end
end)
function on_frame()
local list = spectators.list()
if #list == 0 and not globals.menu_open() then return end
local x, y, shown = hud.panel("spec", "Spectators", 200, math.max(1, #list) * 18 + 8)
if not shown then return end
if #list == 0 then
draw.text(x + 10, y + 5, "nobody", dim, 13)
return
end
for i, s in ipairs(list) do
local yy = y + 5 + (i - 1) * 18
draw.text(x + 10, yy, s.name, white, 14)
local m = modes[s.mode] or ""
local mw = draw.text_size(m, 12)
draw.text(x + 190 - mw, yy + 1, m, dim, 12)
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.