Skip to content
EvilEngine.Api.Weapons

IWeaponHolder interface

public interface IWeaponHolder

The body holding a weapon, as one tick’s command left it. Every vector is a MapVector in meters on Godot’s axes. A number or vector it’s given that isn’t finite, or is past a float’s range, throws ArgumentOutOfRangeException naming it, so one bad sum can’t spoil the holder’s aim or the world, and so does a projectile’s mass of 0 or less or a size or damping below 0.

Assembly
EvilEngine.Api
Commit
4ff877b1

Members

Eye property

MapVector Eye { get; }

Where the holder’s eye is.

Aim property

MapVector Aim { get; }

The unit direction the command aims along, from its pitch and yaw. In third person it aims at what the crosshair shows.

Yaw property

double Yaw { get; }

The command’s yaw in degrees.

Velocity property

MapVector Velocity { get; }

How fast the holder is moving, in meters a second, so what it throws carries its speed.

Held property

WeaponButtons Held { get; }

The buttons held on this command.

Pressed property

WeaponButtons Pressed { get; }

The buttons held now that weren’t on the command before.

Released property

WeaponButtons Released { get; }

The buttons held on the command before that aren’t now.

Mode property

int Mode { get; }

The weapon’s mode, as its record’s modes list it, 0 for the first.

Interval property

double Interval { get; }

The tick’s length in seconds.

Wheel property

int Wheel { get; }

The mouse wheel’s notches since the last command while the weapon captures the wheel, up positive, or 0 when it doesn’t.

Steer property

WeaponSteer Steer { get; }

The mouse’s movement since the last command while the weapon captures steering and use is held, which the view doesn’t turn by meanwhile.

Captures property

WeaponCaptures Captures { get; set; }

What the weapon takes from the player in place of the selector and the view, none by default. It holds until the weapon sets it again or is put away. The physics gun takes both while it holds a prop.

Time property

double Time { get; }

The session’s clock in seconds.

Beam property

WeaponBeam? Beam { get; set; }

The beam to draw this tick, or null for none. Set it every tick it should show; a holder starts each tick with none.

Dot property

MapVector? Dot { get; set; }

A laser dot to show where the weapon points this tick, like the RPG’s, or null for none.

Record property

WeaponRecord? Record { get; }

The weapon’s weapon record resolved down its bases, with the simulation keys its game’s adapter writes: clip size, default clip, ammo, damage and named sounds. null when the weapon has none.

Clip property

int Clip { get; set; }

The rounds in this item’s clip, -1 for a weapon without one. Setting it changes the clip the owner’s HUD and wheel show.

Speed property

double Speed { get; set; }

A scale on how fast the holder walks, runs and swims while this weapon is held, 1 for their own speed: 0.8 for a heavy gun, 0.5 while a scope is up. It lasts until it’s set again or the weapon is put away, and noclip flies at full speed whatever it is. Below 0 or not a number, it throws.

Zoomed property

double? Zoomed { get; }

The field of view in degrees the weapon has zoomed to, or null when it hasn’t.

ViewModel property

IWeaponViewModel ViewModel { get; }

The owner’s view model for this weapon: its skin, body groups, pose parameters, a stack swapped in for its own, and whether it shows.

Hold property

string? Hold { get; set; }

The hold type the holder’s body stands, walks and runs in while this weapon is held: pistol, smg, ar2, shotgun, melee, passive or any name a person has holds for. It reads the weapon record’s hold for the held mode until it’s set, and setting it holds another until it’s set back with null or the weapon is put away, as a weapon lowered while sprinting does. A body with no clips for the hold walks on its own. A name is lower-case letters, digits and _; another throws.

holder.Hold = sprinting ? "passive" : null;

Ammo method

int Ammo(ContentId type)

How many rounds of an ammo type the body carries.

SetAmmo method

void SetAmmo(ContentId type, int count)

Sets how many rounds of an ammo type the body carries, never below 0.

Trace method

WeaponTrace Trace(MapVector from, MapVector to)
WeaponTrace Trace(MapVector from, MapVector to, double size)

A line from one point to another through the world, its props and its people, as a WeaponTrace that names the physics body it hit. With a size it sweeps a box that far out from the line on every side, in metres, as a melee swing does when a line misses.

Animate method

void Animate(string activity, double rate = 1, WeaponEase ease = WeaponEase.Linear)

Plays an activity (@ACT_VM_RELOAD) or a sequence by name on the owner’s view model from its start, at a rate and with an ease over the same length, then back to its idle when it ends, or to the idle’s last frame when the idle doesn’t loop.

Duration method

double Duration(string activity)

How long an activity or sequence lasts on this weapon’s view model at rate 1, in seconds, or 0 when it has none, so a weapon times its next shot or reload by its animation.

Sound method

void Sound(ContentId sound)

Plays a sound record from the holder’s eye, heard by everyone.

Punch method

void Punch(double pitch, double yaw)

Adds to the view punch’s speed, in degrees a second of pitch (up) and yaw (left). The engine’s spring brings it back; while it lasts it turns the owner’s camera and the Aim bullets fire along.

Fire method

IReadOnlyList<WeaponTrace> Fire(WeaponBullets bullets)

Fires bullets from the eye along the aim: the engine traces each pellet within the cone, pushes the props it hits, plays each surface’s bullet sound and shows the muzzle flash, impacts and tracers in the looks the weapon’s record names, or the bullets’ own. It hands back what each pellet hit, in order, so a weapon can chain off its hits.

foreach (var hit in holder.Fire(new WeaponBullets(1, 0, 20, 0)))
    if (hit.Person)
        holder.Effect(ContentId.Parse("mygun:effect/zap"), WeaponEffectAt.At(hit.End, hit.Normal));

Effect method

void Effect(ContentId effect, WeaponEffectAt at = default)

Plays an effect record for every player: at a point facing a normal, or on an attachment of the weapon’s own model, which its owner sees on their view model and everyone else at the body’s hand. With no place it plays on the weapon’s muzzle (see WeaponEffectAt).

Impact method

void Impact(WeaponTrace hit, ContentId? effect = null, ContentId? decal = null)

Marks a hit the way a bullet’s is marked: plays an effect record there, the given one or the struck surface’s impact, and leaves a decal record, the given one or the surface’s decals.melee, then its decals.bullet. A melee weapon calls it with what its Trace struck.

Eject method

void Eject(ContentId? casing = null)

Ejects a casing record from the weapon’s eject attachment, the weapon’s own casing when none is named. A weapon whose model has no brass events of its own ejects its casings this way.

Strike method

void Strike(WeaponTrace hit, double damage, MapVector impulse, DamageKind kind = DamageKind.Club)

Hurts the person a Trace this tick just hit, or pushes the prop it hit, with the damage, the impulse in kg·m/s and the kind of damage, a club’s by default. A melee weapon strikes with it.

Launch method

IProjectile Launch(MapVector from, WeaponProjectile projectile, IProjectileBehaviour behaviour)

Launches a projectile from a point and hands back the IProjectile that flies. Its behaviour thinks every tick and decides what happens when it touches something; the weapon can keep the projectile to steer it.

Zoom method

void Zoom(double? fov, double seconds = 0)

Eases the owner’s field of view to a number of degrees over some seconds, or back to their own with null, as a scope or a binocular does. The mouse turns more slowly the further in it is, so a zoomed aim moves as far across the screen as an unzoomed one. It lasts until the weapon zooms again or is put away, which snaps the view back at once. A field of view is kept between 1° and 170°.

if (holder.Pressed.HasFlag(WeaponButtons.Attack2))
    holder.Zoom(holder.Zoomed is null ? 20 : null, 0.2);

Reading method

void Reading(string name, double? value)

Sets a number the HUD and the power bar can show by name, or clears it with null: a charge, a heat, a second clip. A hudfield record shows it with value = "weapon.<name>", and a bar segment with {weapon.<name>}. Readings last until they’re set again or the weapon is put away. A name is lower-case letters, digits and _; another throws.

holder.Reading("heat", _heat);

Gesture method

void Gesture(string? name, double seconds = 0)

Plays a gesture on the holder’s body for everyone to see, over its legs and in its hold type: WeaponGestures.Attack as a shot goes off, WeaponGestures.Reload stretched to last as long as the reload does, or any name a person has a gesture.<name> slot for. A new gesture replaces the last, and null stops it, as an interrupted reload does. A name is lower-case letters, digits and _; another throws, and so do seconds below 0.

holder.Animate("reload");
holder.Gesture(WeaponGestures.Reload, holder.Duration("reload"));