# WeaponRecord record

> 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.

Namespace `EvilEngine.Formats.Records`, assembly `EvilEngine.Formats`. Engine commit 4ff877b1.

```csharp
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](/docs/plugins/weapons#the-weapon-record) and [the weapon wheel](/docs/plugins/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](/docs/api/iweaponholder#record) and from the factory it gave [IWeapons.RegisterBehaviour](/docs/api/iweapons#registerbehaviour). Every property but [Id](#id) is `null` or empty when the record leaves its key out, so read each with a fallback:

```csharp
sealed class Slugger(WeaponRecord record) : IWeaponBehaviour
{
    readonly double damage = record.Damage ?? 10;
    readonly ContentId? swing = record.Sound("miss");
    readonly WeaponWorldModel? held = record.WorldModelIn(0);
}
```

## Members

### WeaponRecord (constructor)

```csharp
public WeaponRecord(ContentId Id)
```

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

### Id (property)

```csharp
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)

```csharp
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)

```csharp
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)

```csharp
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)

```csharp
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)

```csharp
public WeaponIcon? Icon { get; init; }
```

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

### IconSelected (property)

```csharp
public WeaponIcon? IconSelected { get; init; }
```

The icon drawn in place of [Icon](#icon) while the weapon is hovered, from `icon_selected`, or `null` to keep `Icon`.

### AmmoIcon (property)

```csharp
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)

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

The weapon's modes, from the `modes` list, each a [WeaponMode](/docs/api/weaponmode). A player picks one by holding Alt, and [IWeaponHolder.Mode](/docs/api/iweaponholder#mode) is its index, 0 for the first. Empty for a weapon with one way of working.

### ViewModel (property)

```csharp
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)

```csharp
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](#worldmodelin).

### Hold (property)

```csharp
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](#holdin), and [IWeaponHolder.Hold](/docs/api/iweaponholder#hold) changes it while the weapon is out.

### ClipSize (property)

```csharp
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](#ammo).

### DefaultClip (property)

```csharp
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](#clipsize) and the rest go to the body's reserve of its [Ammo](#ammo). `null`, 0 or -1 gives none.

### Ammo (property)

```csharp
public ContentId? Ammo { get; init; }
```

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

### Ammo2 (property)

```csharp
public ContentId? Ammo2 { get; init; }
```

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

### Damage (property)

```csharp
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)

```csharp
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](#sound).

### Behaviour (property)

```csharp
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](/docs/api/iweapons#register) ignores it.

### Tuning (property)

```csharp
public WeaponTuning Tuning { get; init; }
```

The `tuning` table the behaviour reads, a [WeaponTuning](/docs/api/weapontuning), [Empty](/docs/api/weapontuning#empty) when the record has none.

### Effects (property)

```csharp
public WeaponEffects Effects { get; init; }
```

The weapon's muzzle flash, impact, tracer and casing, from `effects`, as [WeaponEffects](/docs/api/weaponeffects). A mode can have its own, so read them through [EffectsIn](#effectsin).

### Attachments (property)

```csharp
public WeaponAttachments Attachments { get; init; }
```

The attachments on its models the looks come from, from `attachments`, as [WeaponAttachments](/docs/api/weaponattachments). A mode can have its own, so read them through [AttachmentsIn](#attachmentsin).

### Events (property)

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

What plays at moments in its model's animation, from the `events` list, each a [WeaponEvent](/docs/api/weaponevent). Empty for none.

### EffectsIn (method)

```csharp
public WeaponEffects EffectsIn(int mode)
```

The effects in `mode`: the mode's own over the weapon's, slot by slot. A mode outside [Modes](#modes) gets the weapon's.

### WorldModelIn (method)

```csharp
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](#modes).

### HoldIn (method)

```csharp
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](#modes).

### AttachmentsIn (method)

```csharp
public WeaponAttachments AttachmentsIn(int mode)
```

The attachments in `mode`: the mode's own over the weapon's, name by name. A mode outside [Modes](#modes) gets the weapon's.

### Sound (method)

```csharp
public ContentId? Sound(string slot)
```

The id of the sound named `slot` in [Sounds](#sounds), matched exactly, or `null` when the record has none by that name.

### Over (method)

```csharp
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](#sounds) merge name by name, [Tuning](#tuning) key by key, [Effects](#effects) and [Attachments](#attachments) slot by slot, while [Modes](#modes) and [Events](#events) are taken whole from whichever sets any. The [Id](#id) and [Base](#base) stay this one's.
