Skip to content
Plugins

Crosshairs of your own

Add a crosshair style with records, make it kick when the player shoots and dim while they reload, and take the crosshair over for a gamemode or a weapon.


Every crosshair in Evil Engine is a crosshair record: Garry’s Mod’s dot, its classic cross and Half-Life 2’s, and the engine’s own white cross. One renderer draws them all in the window’s own pixels, blending in linear light as Source does, so a style you write draws as exactly on any screen as the games’ own.

A HUD offers a list of styles and the player picks one in the client settings’ Crosshair tab, where they tune the keys the style lets them: colour, opacity, length, gap, thickness, outline, additive, dot and top arm. A gamemode or a weapon can lay its own over theirs.

A style of your own

A Plugin with only records can add a style. Make a folder in user://plugins/ (on Linux, ~/.local/share/godot/app_userdata/Evil Engine/plugins/):

mycross/
  plugin.toml
  Records/crosshairs.toml
id = "mycross"
name = "My crosshair"
version = "1.0.0"
api = 1

Then Records/crosshairs.toml, a classic cross that widens when you shoot and fades while you reload:

[crosshair."crosshair/rifle"]
title = "Rifle"
draws = "lines"
colour = "#40ff80ff"
length = 6
gap = 4
thickness = 1
outline = 1
scale = 1080
scaled = ["length", "gap", "thickness"]
player = ["colour", "length", "gap", "thickness", "outline"]

[crosshair."crosshair/rifle".on.shot]
spread = 5
attack = 0.02
release = 0.4
max = 16

[crosshair."crosshair/rifle".on.reload]
opacity = 0.3
attack = 0.15
release = 0.25
ease = "out"

draws is lines for a cross built from length, gap, thickness, outline, dot and top; image for a texture (any texture content, a region of it if it’s a sheet) drawn texel for texel; or glyph for one character of a font at size pixels to the em. Lengths are screen pixels unless the style names a scale, a screen height its scaled lengths are measured against, so the rifle above is the same share of the screen at 720p and 4K. player lists the keys the player may set over yours; leave it empty to draw exactly as you wrote it. A style may take a base and leave out whatever it shares with it.

It’s in the Crosshair tab as soon as the Plugin loads, and a player who picks it, or sets crosshair_style mycross:crosshair/rifle in the console, keeps it on every map. A HUD’s own records put its styles first in the tab with crosshairs and name the one shown until the player picks with crosshair.

Moving it

A style’s on table says how it reacts to events by name. Each reaction rises to its peak over attack seconds, stays there hold seconds and eases back over release, shaped by ease (smooth, linear or out). At the peak it widens the classic cross’s gap by spread and keeps opacity of its alpha. Reactions add, up to the largest max among them, so a burst widens the cross and it tightens shot by shot as it recovers.

The engine raises shot and reload once weapons fire and reload. Until then, and for any event of your own, play them from the console:

crosshair_play shot
crosshair_hold reload
crosshair_release reload

The Crosshair tab’s Shoot and Reload buttons play them on its preview, too. A style with no reaction to an event ignores it, which is why Garry’s Mod’s own styles never move.

Taking it over

A gamemode or a weapon takes the crosshair over through its context’s Crosshairs, its view of ICrosshairs, the server’s hold on every player’s crosshair. It sets layers: overrides named by their source, stacked by priority, whose keys beat the player’s, which can swap the style or hide it, and which can lock keys away from the player while they stand.

var crosshairs = context.Crosshairs!;
crosshairs.Everyone.Set(new CrosshairLayer("ctf:teams")
{
    Style = ContentId.Parse("ctf:crosshair/team"),
    Locked = [CrosshairKey.Colour]
});

var mine = crosshairs.Of(player)!;
mine.Set(new CrosshairLayer("ctf:shotgun") { Priority = CrosshairLayer.Weapon, Gap = 14, Thickness = 2 });
mine.Play(new CrosshairReaction { Spread = 8, Release = 0.6, Max = 20 });
mine.Hold("reload");

mine.Release("reload");
mine.Clear("ctf:shotgun");

The server sends each player their layers whenever they change and their events in their next snapshot, so a client never decides what a gamemode locked, and the motion eases on their screen at its own frame rate. The player’s crosshair 0 still hides it: no layer shows a crosshair they turned off.

A Plugin’s layers are named for it, ctf: for the Plugin ctf: setting or clearing another source throws, so two Plugins never fight over one layer, and a Plugin’s layers go when it unloads. just map-shot sets a layer without a Plugin, for checking how one looks:

just map-shot gmod:gm_construct --walk=-:1 "--crosshair-layer=style=gmod:crosshair/classic;gap=10;colour=#ff3030ff;lock=colour" --screenshot=layer.png
just map-shot gmod:gm_construct --walk=-:1 --crosshair=evil:crosshair/cross --crosshair-hold=reload --screenshot=reload.png