Skip to content
EvilEngine.Api.Weapons

IWeapons interface

public interface IWeapons

The weapons a realm’s Plugins give, each named by its weapon record. A Plugin gets its own view of it from PluginContext.Weapons, so every weapon it registers is listed under its id and goes when it unloads.

A player class’s kit gives only registered weapons, so a weapon record from a mount or a Plugin’s Records/ puts nothing in anyone’s hands until some Plugin registers it. A weapon registered with a behaviour does what its IWeaponBehaviour says while it’s held; one registered without is carried, shown on the wheel and held, and nothing more.

public void Load(PluginContext context)
{
    if (context.Realm == Realm.Server)
        context.Weapons.Register(ContentId.Parse("gmod:weapon/weapon_physgun"), () => new PhysicsGun());
}
Assembly
EvilEngine.Api
Commit
4ff877b1

Members

Registered property

IReadOnlyList<ContentId> Registered { get; }

Every weapon registered in this realm so far, by any Plugin, once each.

Behaviours property

IReadOnlyList<ContentId> Behaviours { get; }

Every behaviour registered by name in this realm so far, by any Plugin, once each.

Register method

void Register(ContentId weapon)
void Register(ContentId weapon, Func<IWeaponBehaviour> behaviour)

Registers a weapon by its weapon record’s id, in any namespace, so the Source systems Plugin registers Garry’s Mod’s gmod:weapon/weapon_physgun. Call it while your Plugin loads, inside Load: a call after Load has returned throws InvalidOperationException.

The overload with a behaviour takes a factory the server calls once for each carried item of that weapon, so every player’s copy keeps its own state.

Two Plugins can register the same weapon. The one that loaded later gives it, and when that one unloads the earlier one gives it again. Only the server realm reads registrations today.

RegisterBehaviour method

void RegisterBehaviour(ContentId behaviour, Func<WeaponRecord, IWeaponBehaviour> factory)

Registers a behaviour by an id in your Plugin’s own namespace, for any weapon record to name with behaviour = "<id>". Every weapon record naming one that’s registered is a registered weapon, so a content pack with no code makes weapons on your behaviour. The factory gets the weapon’s resolved record, base and all, once for each carried item, so one class serves every weapon that names it and reads each one’s own tuning. Read the tuning in the constructor: whatever it hasn’t read by then is noted once as doing nothing. A weapon’s own registration through Register wins over the behaviour its record names.

context.Weapons.RegisterBehaviour(ContentId.Parse("mygun:chain"), record => new ChainLightning(record));

Call it while your Plugin loads. An id outside your namespace throws ArgumentException, and a call after Load returned throws InvalidOperationException. The engine’s own behaviours come from the evil.weapons Plugin (Making weapons).