Examples
Complete example scripts that ship with Nyx.
watermark.lua
Section titled watermark.lua-- A draggable watermark: name, the script frame rate and the time. Script paint runs once per game tick-- (64 a second), whatever the render rate, so this is the script's rate, not the game's fps.ui.sidebar("Watermark", "tag")local window = ui.window("watermark", "Watermark", vector.create(250, 28, 0))local accent = ui.color("accent", "Accent", color(150, 120, 255))local font = render.font("ui", 16.5)local fps, frames, since = 0, 0, os.clock()
window:on_paint(function(r) frames += 1 if os.clock() - since >= 1 then fps, frames, since = frames, 0, os.clock() end r.rect_filled(vector.create(0, 0, 0), vector.create(4, 28, 0), accent:get()) local me = entities.local_player() local name = me and me:name() or "nyx" r.text(font, vector.create(12, 6, 0), color(235, 235, 245), string.format("%s | %d script fps | %s", name, fps, os.date("%H:%M")))end)spectators.lua
Section titled spectators.lua-- Dead teammates (a true spectator list needs Player:observer_target for every player, coming in part B).ui.sidebar("Spectators", "eye")local window = ui.window("spectators", "Spectators", vector.create(180, 120, 0))local font = render.font("ui", 15.5)
window:on_paint(function(r) local me = entities.local_player() if not me then return end local y = 4 for _, p in entities.players() do if not p:is_local() and not p:is_alive() and p:team() == me:team() then r.text(font, vector.create(8, y, 0), color(220, 220, 230), p:name()) y += 18 end endend)hit_indicator.lua
Section titled hit_indicator.lua-- A short-lived "-damage" next to the crosshair when you hit someone, and rising over the player you hit.ui.sidebar("Hit indicator", "burst")local enabled = ui.toggle("enabled", "Show hit damage", true)local font = render.font("ui_bold", 18)local hits = {}
events.game_event:add(function(name, e) if name ~= "player_hurt" or not enabled:get() then return end local me = entities.local_player() if e.attacker and me and e.attacker:index() == me:index() then table.insert(hits, { text = "-" .. e.damage, until_t = os.clock() + 0.8, victim = e.victim }) endend)
events.paint:add(function() local size = render.screen_size() local y = size.y / 2 + 20 for i = #hits, 1, -1 do local h = hits[i] if os.clock() > h.until_t then table.remove(hits, i) else render.text(font, vector.create(size.x / 2 + 20, y, 0), color(255, 90, 90), h.text, "outline") y += 20 -- World-space text is projected every rendered frame, so it stays over the player while you move. local pos = h.victim and h.victim:origin() if pos then local rise = (0.8 - (h.until_t - os.clock())) * 40 render.text_3d(font, pos + vector.create(0, 0, 80 + rise), color(255, 90, 90), h.text, "center outline") end end endend)Nyx Lua API v1 · release commit-4b659d9c3810 · d0f772c99281