Skip to content
Plugins

The weapon wheel

Give your weapons a slot and an icon on the wheel, tune a wheel of your own with records, and take weapon selection over for a gamemode or a weapon.


Weapon selection in Evil Engine is one wheel for every game: six segments round the middle of the screen, opened by the number keys and the mouse wheel and steered with the mouse while a number key is held. What’s on it is whatever the player’s body carries, from any Plugin. How each weapon shows is a weapon record, and how the wheel looks and behaves is a selector record with a style page. Garry’s Mod’s own are written from the game’s files, so its wheel draws Half-Life 2’s icons in Half-Life 2’s colours.

Your weapons on the wheel

A weapon your Plugin gives shows on the wheel as its weapon record says. Put them in Records/weapons.toml:

[weapon."weapon/railgun"]
title = "Railgun"
slot = 3
order = 0
icon = { font = "mygun:fonts/icons.ttf", character = "R" }
ammo_icon = { font = "mygun:fonts/icons.ttf", character = "r" }

[weapon."weapon/railgun_mk2"]
base = "mygun:weapon/railgun"
title = "Railgun Mk II"
order = 1

slot counts from 0, so slot 3 is the fourth segment and the 4 key, and order places it among the slot’s other weapons. An icon is a font and one character from it, as Half-Life 2’s are, or an image with an optional region of it. icon_selected draws in place of icon while it’s hovered. title may be a #token your Plugin’s text tables translate. A weapon with no record still shows, as its id at the end of the last slot, with a warning.

A player gets weapons from their player class’s kit when they spawn, and a kit gives only the weapons some loaded Plugin registers, so register each of yours while your Plugin loads:

public void Load(PluginContext context)
{
    if (context.Realm == Realm.Server)
        context.Weapons.Register(ContentId.Parse("mygun:weapon/railgun"));
}

A kit names it as { give = "mygun:weapon/railgun" }, and the class’s hold picks the one held at spawn. A weapon registered with no behaviour is carried, shown and held and does nothing more; Making weapons gives it one, with no code through evil.weapons or with your own. The console hands out any weapon record, registered or not, which is handy for checking how one shows:

give mygun:weapon/railgun 4 40
strip

A wheel of your own

A selector record over the engine’s changes only what it names:

[selector."selector/arena"]
base = "evil:selector/wheel"
title = "Arena"
slots = 4
idle = 3
hold = 0.15
sounds = { open = "mygun:ui.wheel_open", move = "mygun:ui.tick", select = "mygun:ui.pick", close = "none" }
tokens = { accent = "#30c0ff", box = "#101820cc", hovered = "#203040e6" }
ring = { inner = 140, outer = 330 }

open, close and scale shape how it fades in and out, idle and fade how long it waits before fading away when browsed with nothing pressed, hold how long a number key is held before it steers, and scan how long the hub’s name takes to appear. The ring is drawn by the engine from ring (radii, gap and accent width in px at 1080) and the box, empty, hovered, accent and hub tokens. The rest is the style page, evil or suit, picked by style, which reads every other token as --selector-<name>.

It’s in Client Settings’ Weapon wheel tab as soon as the Plugin loads, and a player who picks it, or sets cl_selector mygun:selector/arena in the console, keeps it on every map. A HUD’s own records name the wheel its maps show with selector, and a gamemode’s layer can swap it in whatever the player picked.

Taking it over

A gamemode or a weapon takes weapon selection over through its context’s Selections, its view of ISelections, the server’s hold on every player’s selection. It sets layers, named by their source and stacked by priority, which can hide selection, lock it, take the mouse wheel for the held weapon, swap the wheel or set its slots.

var selections = context.Selections!;
selections.Everyone.Set(new SelectionLayer("arena:rules")
{
    Selector = ContentId.Parse("arena:selector/arena"),
    Slots = 4
});
selections.Everyone.Set(new SelectionLayer("arena:warmup") { Locked = true });

var mine = selections.Of(player)!;
mine.Set(new SelectionLayer("arena:grapple") { Priority = SelectionLayer.Weapon, Scroll = false });

selections.Everyone.Clear("arena:warmup");
mine.Clear("arena:grapple");

The server sends each player their layers whenever they change and refuses the picks of a player whose selection is hidden or locked, so a client never decides what a gamemode locked.

A Plugin’s layers are named for it, arena: for the Plugin arena: setting or clearing another source throws, 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 "--give=gmod:weapon/weapon_smg1;gmod:weapon/weapon_pistol" --walk=-:1,Key3:0.1 "--selection-layer=selector=evil:selector/wheel;slots=4" --screenshot=wheel.png