Lua · Examples · Drawing

Spray crosshair

A crosshair that opens up while you spray, run or jump, and turns red during a spray.

Uses: entity.local_player, shots_fired, smooth animation

spray_crosshair.lua
-- name: Spray Crosshair
-- author: Adolfjon
-- version: 1.0
-- description: Crosshair that reacts to spraying, speed and jumps.

ui.color("col", "Colour", color(255, 255, 255, 230))
ui.color("spray", "Spraying colour", color(255, 90, 90, 230))
ui.slider("len", "Arm length", 3, 20, 7)

local gap = 3

function on_frame()
    local me = entity.local_player()
    if not me or me.scoped then return end
    local w, h = draw.screen()
    local cx, cy = math.floor(w / 2), math.floor(h / 2)
    local shots = me.shots_fired or 0
    local speed = me.velocity and math.sqrt(me.velocity.x ^ 2 + me.velocity.y ^ 2) or 0
    local air = me.on_ground == false and 8 or 0
    local target = 3 + math.min(shots, 10) * 1.5 + math.min(speed, 250) / 25 + air
    gap = math.lerp(gap, target, 1 - math.exp(-14 * globals.frametime()))
    local col = shots > 1 and ui.get("spray") or ui.get("col")
    local len = ui.get("len")
    draw.rect_filled(cx - gap - len, cy - 1, len, 2, col)
    draw.rect_filled(cx + gap, cy - 1, len, 2, col)
    draw.rect_filled(cx - 1, cy - gap - len, 2, len, col)
    draw.rect_filled(cx - 1, cy + gap, 2, len, col)
    draw.rect_filled(cx - 1, cy - 1, 2, 2, col)
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.