Lua · Examples · Drawing

Custom watermark

Top-left watermark with your own font, FPS, map and time.

Uses: draw.load_font, draw.text_font, globals

custom_watermark.lua
-- name: Watermark
-- author: Adolfjon
-- version: 1.0
-- description: Watermark with a custom font, FPS and map.

ui.color("accent", "Accent", color(120, 170, 255))

local font = draw.load_font("segoeuib.ttf", 18) or 0
local bg = color(12, 14, 18, 215)
local white = color(240, 242, 246)
local fps, acc, frames = 0, 0, 0

function on_frame()
    acc = acc + globals.frametime()
    frames = frames + 1
    if acc >= 0.5 then
        fps = math.floor(frames / acc + 0.5)
        acc, frames = 0, 0
    end

    local map = globals.map()
    local text = "ADOLFJON  |  " .. fps .. " fps" .. (map ~= "" and ("  |  " .. map) or "")
    local tw, th = draw.text_size_font(font, text)
    local x, y = 16, 16
    draw.rect_filled(x, y, tw + 24, th + 14, bg, 8)
    draw.rect_filled(x, y, 3, th + 14, ui.get("accent"), 2)
    draw.text_font(font, x + 12, y + 7, text, white)
end

Install it

  1. Press Copy on the code above.
  2. In the menu, open Lua and press From Clipboard. The file is named from its -- name: line.
  3. 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.