Skip to content
EvilEngine.Formats.Records

WeaponRecord record

public sealed record WeaponRecord

A weapon record: how a weapon shows on the wheel, what it looks and sounds like, and which behaviour makes it do something. The TOML format is in Making weapons and the weapon wheel. Garry’s Mod’s adapter writes its weapons’ records from the game’s own files, so they read the same way.

A behaviour gets the record resolved down its bases, from IWeaponHolder.Record and from the factory it gave IWeapons.RegisterBehaviour. Every property but Id is null or empty when the record leaves its key out, so read each with a fallback:

sealed class Slugger(WeaponRecord record) : IWeaponBehaviour
{
    readonly double damage = record.Damage ?? 10;
    readonly ContentId? swing = record.Sound("miss");
    readonly WeaponWorldModel? held = record.WorldModelIn(0);
}
Assembly
EvilEngine.Formats
Commit
4ff877b1

Members

WeaponRecord constructor

public WeaponRecord(ContentId Id)

Makes a record with its id and nothing else, for setting what you need.

Id property

public ContentId Id { get; init; }

The record’s id, its name in its set under the namespace of the Plugin or mount that gives it: [weapon."weapon/pulse"] in the pulse Plugin is pulse:weapon/pulse. It’s what a kit’s give and the give command name.

Base property

public ContentId? Base { get; init; }

The record this one is built on, from base, or null. On a resolved record it’s null once every base has been folded in, or the base the chain stopped at, when that one is missing or the chain comes back round to a record it already took in.

Title property

public string? Title { get; init; }

The name the wheel shows, from title, or null for the weapon’s id. It may be a #token a Plugin’s text tables translate.

Slot property

public int? Slot { get; init; }

The wheel segment the weapon sits in, from slot, counting from 0 to 9, or null for the last one.

Order property

public int? Order { get; init; }

Where the weapon sits among its slot’s others, from order, lower first, from -1,000,000 to 1,000,000. null counts as 0.

Icon property

public WeaponIcon? Icon { get; init; }

The wheel’s icon for the weapon, from icon, or null for none.

IconSelected property

public WeaponIcon? IconSelected { get; init; }

The icon drawn in place of Icon while the weapon is hovered, from icon_selected, or null to keep Icon.

AmmoIcon property

public WeaponIcon? AmmoIcon { get; init; }

The icon the wheel’s hub shows beside the hovered weapon’s ammo, from ammo_icon, or null.

Modes property

public IReadOnlyList<WeaponMode> Modes { get; init; }

The weapon’s modes, from the modes list, each a WeaponMode. A player picks one by holding Alt, and IWeaponHolder.Mode is its index, 0 for the first. Empty for a weapon with one way of working.

ViewModel property

public ContentId? ViewModel { get; init; }

The viewmodel record drawn in the holder’s hands in first person, from viewmodel, or null for none. A mode’s own replaces it while that mode is picked.

WorldModel property

public WeaponWorldModel? WorldModel { get; init; }

The model everyone else sees in the holder’s hand, from worldmodel, a model id or a table, or null for none. A mode can have its own, so read it through WorldModelIn.

Hold property

public string? Hold { get; init; }

The hold type the holder’s body takes while it’s held, from hold, such as pistol or ar2, or null for the body’s own motion. It’s lowercase letters, digits and underscores. A mode can have its own, so read it through HoldIn, and IWeaponHolder.Hold changes it while the weapon is out.

ClipSize property

public int? ClipSize { get; init; }

Rounds in a clip, from clip_size, from -1 to 1,000,000. null, 0 or -1 is a weapon with no clip, which fires straight from the reserve of its Ammo.

DefaultClip property

public int? DefaultClip { get; init; }

Rounds a newly given weapon comes with, from a kit or from give with no clip or reserve, from default_clip, from -1 to 1,000,000. They fill the clip up to ClipSize and the rest go to the body’s reserve of its Ammo. null, 0 or -1 gives none.

Ammo property

public ContentId? Ammo { get; init; }

The ammo type the weapon and its clip use, from ammo, or null for none.

Ammo2 property

public ContentId? Ammo2 { get; init; }

The ammo type its second trigger uses, from ammo2, or null.

Damage property

public double? Damage { get; init; }

Damage per bullet or hit, from damage, 0 or more, or null for whatever the behaviour falls back on.

Sounds property

public IReadOnlyList<KeyValuePair<string, ContentId>> Sounds { get; init; }

The weapon’s named sounds, from the sounds table, each a slot name and a sound’s id, in the order the table gives them. The behaviour decides which names it plays: evil.weapons plays fire, alt, empty, reload, draw, hit, miss, stop and others. Read one with Sound.

Behaviour property

public ContentId? Behaviour { get; init; }

The behaviour that makes the weapon do something, from behaviour, by the id a Plugin registered it under, or null. A weapon registered with its own behaviour through IWeapons.Register ignores it.

Tuning property

public WeaponTuning Tuning { get; init; }

The tuning table the behaviour reads, a WeaponTuning, Empty when the record has none.

Effects property

public WeaponEffects Effects { get; init; }

The weapon’s muzzle flash, impact, tracer and casing, from effects, as WeaponEffects. A mode can have its own, so read them through EffectsIn.

Attachments property

public WeaponAttachments Attachments { get; init; }

The attachments on its models the looks come from, from attachments, as WeaponAttachments. A mode can have its own, so read them through AttachmentsIn.

Events property

public IReadOnlyList<WeaponEvent> Events { get; init; }

What plays at moments in its model’s animation, from the events list, each a WeaponEvent. Empty for none.

EffectsIn method

public WeaponEffects EffectsIn(int mode)

The effects in mode: the mode’s own over the weapon’s, slot by slot. A mode outside Modes gets the weapon’s.

WorldModelIn method

public WeaponWorldModel? WorldModelIn(int mode)

The world model in mode: the mode’s own, or the weapon’s when it has none or the mode is outside Modes.

HoldIn method

public string? HoldIn(int mode)

The hold type in mode: the mode’s own, or the weapon’s when it has none or the mode is outside Modes.

AttachmentsIn method

public WeaponAttachments AttachmentsIn(int mode)

The attachments in mode: the mode’s own over the weapon’s, name by name. A mode outside Modes gets the weapon’s.

Sound method

public ContentId? Sound(string slot)

The id of the sound named slot in Sounds, matched exactly, or null when the record has none by that name.

Over method

public WeaponRecord Over(WeaponRecord under)

This record over under, as a record over its base: every value this one sets wins, and the rest come from under. Sounds merge name by name, Tuning key by key, Effects and Attachments slot by slot, while Modes and Events are taken whole from whichever sets any. The Id and Base stay this one’s.