BaseCombatWeaponclass

The base for anything a player holds and uses - weapons, tools, cameras, and so on. Adds a first-person view model, a third-person world model attached to the holder's hand, and an aim ray on top of `Sandbox.BaseInventoryItem`. Combat is opt-in: subclass this, override the attack, and call the utility methods (ShootBullet, ShootBullets, ...) - they do the host-authoritative tracing and damage for you. Non-combat items just don't call them.

objectBaseInventoryItemBaseCombatWeapon
Namespace
Sandbox
Assembly
Sandbox.Engine
Declaration
public class Sandbox.BaseCombatWeapon : Sandbox.BaseInventoryItem

Note

Hold-type animation stays animation agnostic: `Sandbox.BaseCombatWeapon.HoldType` is an option name resolved against whatever "holdtype" enum the holder's animgraph defines - the engine ships no hold-type enum of its own.

Constructors1

Showing 1 constructors

Methods61

Showing 61 methods

protected virtual Sandbox.SceneTrace BulletTrace(Ray ray, float distance, float radius)PROTECTEDVIRTUAL

The trace used for this weapon's bullets. Base traces against hitboxes and ignores the `Sandbox.BaseCombatWeapon.Attacker`'s hierarchy. Override to add collision rules or filters.

ParameterTypeDescription
rayRay
distancefloat
radiusfloat
Returns:SceneTrace

public virtual void CancelReload()PUBLICVIRTUAL

Abort a reload before it finishes, loading nothing further.

Returns:void

public virtual bool CanPrimaryAttack()PUBLICVIRTUAL

Can primary fire right now? Base checks the cooldown, that we're not mid-reload, and that there's ammo. A pure check, safe to call from HUDs - the trigger dry-fires on empty, not this. Override to add conditions.

Returns:bool

public virtual bool CanReload()PUBLICVIRTUAL

Can we start a reload? Yes when not already reloading, the magazine isn't full, and there's reserve to load. Override to add conditions.

Returns:bool

public virtual bool CanSecondaryAttack()PUBLICVIRTUAL

Returns:bool

protected virtual void CreateViewModel()PROTECTEDVIRTUAL

Spawns the view model from `Sandbox.BaseCombatWeapon.ViewModelPrefab` and plays its deploy presentation. Owner only, idempotent - safe to call when one already exists.

Returns:void

protected virtual void CreateWorldModel()PROTECTEDVIRTUAL

Spawns the world model from `Sandbox.BaseCombatWeapon.WorldModelPrefab` onto the holder's `Sandbox.BaseCombatWeapon.HoldBone`, replacing any previous one.

Returns:void

protected virtual void DestroyViewModel()PROTECTEDVIRTUAL

Destroys the spawned view model, if any.

Returns:void

protected virtual void DestroyWorldModel()PROTECTEDVIRTUAL

Destroys the spawned world model, if any.

Returns:void

public virtual void DrawCrosshair(Sandbox.Rendering.HudPainter hud, Vector2 center)PUBLICVIRTUAL

Draw this weapon's crosshair at the aim position. Base draws a simple four-line cross.

ParameterTypeDescription
hudHudPainter
centerVector2
Returns:void

public virtual void DryFire()PUBLICVIRTUAL

The player pulled the trigger with no ammo. Base plays `Sandbox.BaseCombatWeapon.DryFireSound`, throttles both triggers so it doesn't spam, and starts a reload when `Sandbox.BaseCombatWeapon.AutoReload` allows. Override to extend.

Returns:void

public bool FirePrimary()PUBLIC

Pull the primary trigger - fires if `Sandbox.BaseCombatWeapon.CanPrimaryAttack` allows, putting it on cooldown. Returns whether it fired. The way to shoot from code (AI, turrets) - calling `Sandbox.BaseCombatWeapon.PrimaryAttack` directly skips the fire rate. Runs on whoever controls the weapon; the attack doesn't re-run on the host.

Returns:bool

public bool FireSecondary()PUBLIC

Returns:bool

public virtual Transform GetMuzzleTransform()PUBLICVIRTUAL

The transform that shots and muzzle effects fire from. Resolves the active weapon model's muzzle attachment, then the weapon itself. Override to add other model-driven resolution.

Returns:Transform

protected virtual int GetReserveAmmo(Sandbox.BaseAmmoResource ammoType)PROTECTEDVIRTUAL

Reserve ammo of the given type available to this weapon. Reads the owning inventory's shared pool (`Sandbox.BaseInventoryComponent.GetAmmo(Sandbox.BaseAmmoResource)`) - reserve ammo lives on the inventory, not the weapon, so guns of the same type share it. A null ammo type is a bottomless reserve. Returns 0 when the weapon isn't in an inventory. Override to use a different store.

ParameterTypeDescription
ammoTypeBaseAmmoResource
Returns:int

public virtual bool HasPrimaryAmmo()PUBLICVIRTUAL

True if primary fire has a round ready - in the magazine, or in reserve for a clipless weapon. Weapons with neither a magazine nor an ammo type are treated as unlimited (melee, tools).

Returns:bool

public virtual bool HasSecondaryAmmo()PUBLICVIRTUAL

Returns:bool

public static void ImpactPrefab(Sandbox.GameObject hitObject, Sandbox.Surface surface, Vector3 position, Vector3 normal)PUBLICSTATIC

Spawn just the surface impact prefab (decal/particles) at a hit, stuck to what was hit - no sound. For attacks that want the visual but their own impact audio (a melee thunk instead of a ricochet).

ParameterTypeDescription
hitObjectGameObject
surfaceSurface
positionVector3
normalVector3
Returns:void

protected virtual void ModifyCamera(Sandbox.CameraComponent camera, Sandbox.CameraView view)PROTECTEDVIRTUAL

Reshape the holder's view while this weapon is deployed - scope zoom, offsets, lean. Runs in the camera's modifier chain on the owning client, after the player's camera and vehicles. Base does nothing.

ParameterTypeDescription
cameraCameraComponent
viewCameraView
Returns:void

protected virtual void OnAdded(Sandbox.BaseInventoryComponent inventory)PROTECTEDVIRTUAL

Seed the magazines with their default contents, and the inventory's reserve pool with `Sandbox.BaseCombatWeapon.StartingAmmo`. Host only, runs once when the weapon enters an inventory.

ParameterTypeDescription
inventoryBaseInventoryComponent
Returns:void

protected virtual bool OnAdding(Sandbox.BaseInventoryComponent inventory)PROTECTEDVIRTUAL

One of each - picking up a weapon the inventory already holds donates its ammo to the reserve instead (GMod's duplicate pickup), when there's an ammo type with room. The duplicate is consumed by the donation, or left where it is.

ParameterTypeDescription
inventoryBaseInventoryComponent
Returns:bool

protected virtual void OnControl()PROTECTEDVIRTUALPER-FRAME

Per-frame weapon logic, pumped by the inventory on the owning client. Reads input and drives the fire/reload loop. Override the individual hooks (PrimaryAttack, Think, ...) rather than this.

Returns:void

protected virtual void OnEquipped()PROTECTEDVIRTUAL

Returns:void

protected virtual void OnHolstered()PROTECTEDVIRTUAL

Returns:void

protected virtual void OnReloadCancelled()PROTECTEDVIRTUAL

The reload was cancelled part-way (fired, holstered). Fires on every peer, alongside `Sandbox.BaseCombatWeapon.OnReloadFinished` - use it to stop timed reload sounds and the like.

Returns:void

protected virtual void OnReloadFinished()PROTECTEDVIRTUAL

Reload ended (finished or cancelled). Drives the active weapon model.

Returns:void

protected virtual void OnReloadInserted()PROTECTEDVIRTUAL

A round was loaded (incremental). Drives the active weapon model's per-shell insert.

Returns:void

protected virtual void OnReloadStarted()PROTECTEDVIRTUALLIFECYCLE

Reload started. Plays the reload animation on the weapon model, and fires the "b_reload" gesture on the holder's body. Fires once, on every peer, off the synced IsReloading.

Returns:void

protected virtual void OnShootEffects(Sandbox.BaseCombatWeapon.ShotEffect shot)PROTECTEDVIRTUAL

Define the presentation for a resolved shot. Base spawns the surface impact and flies the tracer for every pellet, then plays `Sandbox.BaseCombatWeapon.AttackSound`, fires the holder's "b_attack" gesture and runs `Sandbox.BaseWeaponModel.OnAttack(System.Nullable,System.Nullable)` on the shown model (muzzle flash, brass) - those are skipped for `Sandbox.BaseCombatWeapon.ShotEffect.NoEvents` pellets, which share the lead pellet's. Call it when you override. Runs on every peer that should see the shot.

ParameterTypeDescription
shotShotEffect
Returns:void

protected virtual void OnShootImpact(Sandbox.BaseCombatWeapon.ShotEffect& modreq(System.Runtime.InteropServices.InAttribute) shot)PROTECTEDVIRTUAL

ParameterTypeDescription
shotShotEffect& modreq(InAttribute)
Returns:void

protected virtual void OnUpdate()PROTECTEDVIRTUALPER-FRAME

Returns:void

protected virtual bool OnValidateShotClaim(Sandbox.BaseCombatWeapon.ShotClaim& modreq(System.Runtime.InteropServices.InAttribute) claim)PROTECTEDVIRTUAL

ParameterTypeDescription
claimShotClaim& modreq(InAttribute)
Returns:bool

protected virtual void PlaceViewModel(Sandbox.CameraComponent camera, Sandbox.CameraView& modreq(System.Runtime.InteropServices.InAttribute) view)PROTECTEDVIRTUAL

ParameterTypeDescription
cameraCameraComponent
viewCameraView& modreq(InAttribute)
Returns:void

protected void PlayAttackSound()PROTECTED

Play `Sandbox.BaseCombatWeapon.AttackSound` from the weapon - non-spatialized when the local player is the shooter, so your own gun doesn't pan around your head.

Returns:void

public virtual void PrimaryAttack()PUBLICVIRTUAL

Fire the primary attack. The default fires `Sandbox.BaseCombatWeapon.Ballistics` - spends a round, shoots the volley from `Sandbox.BaseCombatWeapon.AimRay` with `Sandbox.BaseCombatWeapon.CurrentSpread`, and plays the effects on every peer. Override for melee, projectiles and tools. Runs once, on whoever controls the weapon - the owning client for a held weapon (its hits reach the host as claims, see `Sandbox.BaseCombatWeapon.ShootBullet(Sandbox.SceneTraceResult,System.Single,System.Single,Sandbox.TagSet,System.Boolean)`), or the host for seat/NPC/world weapons (damage applies directly).

Returns:void

public virtual void Reload()PUBLICVIRTUAL

Begin reloading. Routed to the host, which runs it authoritatively. Override `Sandbox.BaseCombatWeapon.OnReloadStarted` and friends for presentation rather than this.

Returns:void

public virtual void SecondaryAttack()PUBLICVIRTUAL

Fire the secondary attack. Base does nothing - override it. Same contract as `Sandbox.BaseCombatWeapon.PrimaryAttack`: runs once, on whoever controls the weapon.

Returns:void

public void SetNextFire(float delay)PUBLIC

Put both triggers on cooldown for `delay` seconds - for weapons where a shot blocks primary and secondary alike.

ParameterTypeDescription
delayfloat
Returns:void

public void SetNextPrimaryFire(float delay)PUBLIC

Put primary fire on cooldown for `delay` seconds.

ParameterTypeDescription
delayfloat
Returns:void

public void SetNextSecondaryFire(float delay)PUBLIC

Put secondary fire on cooldown for `delay` seconds.

ParameterTypeDescription
delayfloat
Returns:void

public bool TakePrimaryAmmo(int amount = 1)PUBLIC

Spend `amount` rounds for a primary shot - from the magazine if it has one, otherwise reserve, otherwise free. Returns false if there wasn't enough (GMod's TakePrimaryAmmo).

ParameterTypeDescription
amount = 1int
Returns:bool

protected virtual int TakeReserveAmmo(Sandbox.BaseAmmoResource ammoType, int amount)PROTECTEDVIRTUAL

Take up to `amount` reserve ammo of the given type from the owning inventory's pool, returning how much was actually taken. Pairs with `Sandbox.BaseCombatWeapon.GetReserveAmmo(Sandbox.BaseAmmoResource)`.

ParameterTypeDescription
ammoTypeBaseAmmoResource
amountint
Returns:int

public bool TakeSecondaryAmmo(int amount = 1)PUBLIC

ParameterTypeDescription
amount = 1int
Returns:bool

protected virtual void Think()PROTECTEDVIRTUAL

Runs every frame before attack handling - continuous logic (spin-up, charge, ...). Base does nothing.

Returns:void

protected virtual void UpdateBodyAnimations(Sandbox.SkinnedModelRenderer body)PROTECTEDVIRTUALPER-FRAME

Drive the holder's body animation for this weapon. Runs every frame while deployed, on every peer, with the holder's renderer. Base sets the hold type; override to drive aiming, leaning and any other body parameters.

ParameterTypeDescription
bodySkinnedModelRenderer
Returns:void

protected virtual bool WantsPrimaryAttack()PROTECTEDVIRTUAL

Is the player asking to fire primary this frame? Held when automatic, pressed otherwise.

Returns:bool

protected virtual bool WantsReload()PROTECTEDVIRTUAL

Is the player asking to reload this frame?

Returns:bool

protected virtual bool WantsSecondaryAttack()PROTECTEDVIRTUAL

Is the player asking to fire secondary this frame?

Returns:bool

Properties57

Showing 57 properties

public virtual Ray Sandbox.BaseCombatWeapon.AimRay { get; set; }PUBLICVIRTUALGETSET

Where this weapon is aiming. When held by a player: the holder's eye-forward, or the camera-forward in third person (so you aim where the camera looks, not where the head points). When not held it defers to `Sandbox.BaseCombatWeapon.UnheldAimRay`.

Returns:Ray

public int Sandbox.BaseCombatWeapon.Ammo1 { get; set; }PUBLICGETSET

Reserve ammo available to primary fire - the holder's pool of `Sandbox.BaseCombatWeapon.PrimaryAmmoType` (GMod's Ammo1).

Returns:int

public int Sandbox.BaseCombatWeapon.Ammo2 { get; set; }PUBLICGETSET

Reserve ammo available to secondary fire (GMod's Ammo2).

Returns:int

protected virtual Sandbox.GameObject Sandbox.BaseCombatWeapon.Attacker { get; set; }PROTECTEDVIRTUALGETSET

The GameObject credited for this weapon's damage - the holding player, or the weapon itself when unheld. Override to credit someone else (e.g. the driver of a mounted weapon).

Returns:GameObject

public Sandbox.SoundEvent Sandbox.BaseCombatWeapon.AttackSound { get; set; }PUBLICGETSET

Sound played when the weapon attacks - the gunshot, swing, launch. Played by the base `Sandbox.BaseCombatWeapon.OnShootEffects(Sandbox.BaseCombatWeapon.ShotEffect)`, so it reaches every peer that sees the shot.

Returns:SoundEvent

public bool Sandbox.BaseCombatWeapon.AutoReload { get; set; }PUBLICGETSET

Start a reload automatically when the trigger is pulled on an empty magazine.

Returns:bool

public bool Sandbox.BaseCombatWeapon.CanCancelReload { get; set; }PUBLICGETSET

Can the reload be cancelled (e.g. by firing) part-way through?

Returns:bool

public int Sandbox.BaseCombatWeapon.Clip1 { get; set; }PUBLICGETSET

Rounds currently in the primary magazine, or -1 when the weapon doesn't use one (GMod's Clip1). Host owned - the owner spends it locally for instant feedback and the spend is mirrored to the host (see `Sandbox.BaseCombatWeapon.TakePrimaryAmmo(System.Int32)`), whose count is the truth.

Returns:int

public int Sandbox.BaseCombatWeapon.Clip2 { get; set; }PUBLICGETSET

Rounds currently in the secondary magazine, or -1 when unused (GMod's Clip2). Host authoritative.

Returns:int

public int Sandbox.BaseCombatWeapon.ClipMaxSize { get; set; }PUBLICGETSET

Primary magazine size.

Returns:int

protected Color Sandbox.BaseCombatWeapon.CrosshairCanShoot { get; set; }PROTECTEDGETSET

Crosshair colour for a weapon that's ready to fire.

Returns:Color

protected Color Sandbox.BaseCombatWeapon.CrosshairNoShoot { get; set; }PROTECTEDGETSET

Crosshair colour for a weapon that can't fire - empty, reloading, cooling down.

Returns:Color

public virtual Vector2 Sandbox.BaseCombatWeapon.CurrentSpread { get; set; }PUBLICVIRTUALGETSET

The current spread cone in degrees - the base cone widened by recent firing. Override to modify it (e.g. narrow while aiming down sights).

Returns:Vector2

public float Sandbox.BaseCombatWeapon.DeployTime { get; set; }PUBLICGETSET

Seconds after deploying (switching to) this weapon before it can fire.

Returns:float

public Sandbox.SoundEvent Sandbox.BaseCombatWeapon.DryFireSound { get; set; }PUBLICGETSET

Sound played when the trigger is pulled with no ammo.

Returns:SoundEvent

public float Sandbox.BaseCombatWeapon.FirstShellReloadTime { get; set; }PUBLICGETSET

Extra delay after the first round before the rest (e.g. a longer first insert). Incremental only.

Returns:float

public Sandbox.BaseCombatWeapon.WeaponHandedness Sandbox.BaseCombatWeapon.Handedness { get; set; }PUBLICGETSET

Which hand(s) the holder carries this in - drives the holder animgraph's "holdtype_handedness" parameter alongside `Sandbox.BaseCombatWeapon.HoldType`. Only some hold types support it (e.g. pistol, holditem).

Returns:WeaponHandedness

public string Sandbox.BaseCombatWeapon.HoldBone { get; set; }PUBLICGETSET

The bone on the holder's renderer to attach the world model to.

Returns:string

public string Sandbox.BaseCombatWeapon.HoldType { get; set; }PUBLICGETSET

How the holder poses their arms while this is deployed - an option name on the holder animgraph's "holdtype" enum parameter (e.g. "pistol", "rifle"). Set on the holder's renderer when equipped. Empty doesn't drive it.

Returns:string

public bool Sandbox.BaseCombatWeapon.IncrementalReloading { get; set; }PUBLICGETSET

Load one round at a time instead of the whole magazine (shotgun-style).

Returns:bool

public bool Sandbox.BaseCombatWeapon.IsHeld { get; set; }PUBLICGETSET

True while held by a player.

Returns:bool

public bool Sandbox.BaseCombatWeapon.IsReloading { get; set; }PUBLICGETSET

True while a reload is in progress. Host authoritative, synced so every peer can animate.

Returns:bool

public int Sandbox.BaseCombatWeapon.MaxReserveAmmo { get; set; }PUBLICGETSET

Most reserve ammo the holder can carry for primary fire (from the ammo type).

Returns:int

protected Sandbox.TimeUntil Sandbox.BaseCombatWeapon.NextPrimaryFire { get; set; }PROTECTEDGETSET

Time until primary fire is off cooldown. Not synced - the firing side gates itself (GMod's GetNext/SetNextPrimaryFire). The host doesn't enforce the rate; a hardened game rate-checks incoming shot claims instead (see `Sandbox.BaseCombatWeapon.OnValidateShotClaim(Sandbox.BaseCombatWeapon.ShotClaim@)`).

Returns:TimeUntil

public Sandbox.PlayerController Sandbox.BaseCombatWeapon.Owner { get; set; }PUBLICGETSET

The player controller holding this, or null if it isn't held by one (it's in the world, or held by something that isn't a `Sandbox.PlayerController`). Derived from the hierarchy.

Returns:PlayerController

public Sandbox.BaseAmmoResource Sandbox.BaseCombatWeapon.PrimaryAmmoType { get; set; }PUBLICGETSET

The reserve ammo type primary fire draws from. Null means a bottomless reserve - the magazine still forces the reload rhythm, it just never runs out. Assign a type for a finite reserve, shared with other weapons of the same type.

Returns:BaseAmmoResource

public bool Sandbox.BaseCombatWeapon.PrimaryAutomatic { get; set; }PUBLICGETSET

When true primary fire keeps firing while the button is held; when false it fires once per press (GMod's `Primary.Automatic`).

Returns:bool

public int Sandbox.BaseCombatWeapon.PrimaryClipSize { get; set; }PUBLICGETSET

Magazine size for primary fire, or -1 when it feeds straight from reserve (GMod's Primary.ClipSize). Derived from `Sandbox.BaseCombatWeapon.UsesAmmo` / `Sandbox.BaseCombatWeapon.UsesClips` / `Sandbox.BaseCombatWeapon.ClipMaxSize`.

Returns:int

public float Sandbox.BaseCombatWeapon.PrimaryDelay { get; set; }PUBLICGETSET

Seconds between primary shots - the fire rate (GMod's `Primary.Delay`).

Returns:float

protected virtual int Sandbox.BaseCombatWeapon.ReloadFillTarget { get; set; }PROTECTEDVIRTUALGETSET

How full a reload fills the primary magazine. Defaults to `Sandbox.BaseCombatWeapon.PrimaryClipSize` - override for +1-in-the-chamber style reloads (e.g. `ClipMaxSize + (Clip1 > 0 ? 1 : 0)`). Read once when the reload starts.

Returns:int

public float Sandbox.BaseCombatWeapon.ReloadStartTime { get; set; }PUBLICGETSET

Delay before the first round goes in. Zero uses `Sandbox.BaseCombatWeapon.ReloadTime`.

Returns:float

public float Sandbox.BaseCombatWeapon.ReloadTime { get; set; }PUBLICGETSET

How long a (full) reload takes, in seconds. For incremental reloads, the time per round.

Returns:float

public bool Sandbox.BaseCombatWeapon.SecondaryAutomatic { get; set; }PUBLICGETSET

When true secondary fire is full-auto while held.

Returns:bool

public int Sandbox.BaseCombatWeapon.SecondaryClipSize { get; set; }PUBLICGETSET

Magazine size for secondary fire, or -1 when it doesn't use one (GMod's Secondary.ClipSize). Set directly - unlike `Sandbox.BaseCombatWeapon.PrimaryClipSize`, it isn't derived from the clip settings.

Returns:int

public int Sandbox.BaseCombatWeapon.SecondaryDefaultClip { get; set; }PUBLICGETSET

Rounds loaded into the secondary magazine when first given. -1 fills it.

Returns:int

public float Sandbox.BaseCombatWeapon.SecondaryDelay { get; set; }PUBLICGETSET

Seconds between secondary shots.

Returns:float

public virtual bool Sandbox.BaseCombatWeapon.ShouldAvoid { get; set; }PUBLICVIRTUALGETSET

Avoid auto-switching to a gun with nothing left to fire or load (see `Sandbox.BaseInventoryItem.ShouldAvoid`).

Returns:bool

protected float Sandbox.BaseCombatWeapon.SpreadBloom { get; set; }PROTECTEDGETSET

How bloomed the spread is - 0 settled, 1 right after a shot.

Returns:float

public float Sandbox.BaseCombatWeapon.SpreadScale { get; set; }PUBLICGETSET

Runtime multiplier on the spread cone - 1 is the configured ballistics. NPCs set this to the weapon's `Sandbox.BaseCombatWeapon.Npc` spread scale times their own skill when they equip it.

Returns:float

public int Sandbox.BaseCombatWeapon.StartingAmmo { get; set; }PUBLICGETSET

Reserve ammo granted on first pickup, seeded into the holder's pool.

Returns:int

protected virtual Ray Sandbox.BaseCombatWeapon.UnheldAimRay { get; set; }PROTECTEDVIRTUALGETSET

The aim ray to use when this weapon isn't held by a player - placed in the world, mounted, or controlled from a seat. Base fires from the muzzle; override for camera-targeted aim.

Returns:Ray

public bool Sandbox.BaseCombatWeapon.UsableByNpcs { get; set; }PUBLICGETSET

Can NPCs fight with this weapon at all?

Returns:bool

public bool Sandbox.BaseCombatWeapon.UsesAmmo { get; set; }PUBLICGETSET

Does primary fire consume ammo at all? When false the weapon never runs dry - for melee, tools and the like. Switches the whole Ammo feature off.

Returns:bool

public bool Sandbox.BaseCombatWeapon.UsesClips { get; set; }PUBLICGETSET

Feed primary fire from a magazine (true) or straight from the reserve pool (false).

Returns:bool

public bool Sandbox.BaseCombatWeapon.UsesPrimaryClip { get; set; }PUBLICGETSET

True when primary fire feeds from a magazine rather than straight from reserve.

Returns:bool

public bool Sandbox.BaseCombatWeapon.UsesSecondaryClip { get; set; }PUBLICGETSET

True when secondary fire feeds from a magazine.

Returns:bool

public Sandbox.GameObject Sandbox.BaseCombatWeapon.ViewModel { get; set; }PUBLICGETSET

The spawned view model instance, or null. Owner-only and not networked - each client makes its own.

Returns:GameObject

public Sandbox.GameObject Sandbox.BaseCombatWeapon.ViewModelPrefab { get; set; }PUBLICGETSET

First-person view model prefab. Spawned only on the client holding this item.

Returns:GameObject

public Sandbox.BaseWeaponModel Sandbox.BaseCombatWeapon.WeaponModel { get; set; }PUBLICGETSET

The `Sandbox.BaseWeaponModel` on the currently-shown model - the view model when it's being drawn, otherwise the world model, otherwise the weapon's own hierarchy (standalone weapons). Null when none carries one.

Returns:BaseWeaponModel

public Sandbox.GameObject Sandbox.BaseCombatWeapon.WorldModel { get; set; }PUBLICGETSET

The spawned world model instance, or null. Not networked - each peer makes its own.

Returns:GameObject

public Sandbox.GameObject Sandbox.BaseCombatWeapon.WorldModelPrefab { get; set; }PUBLICGETSET

Third-person world model prefab, attached to the holder's hand bone. Seen by everyone.

Returns:GameObject

On this page

Constructorspublic BaseCombatWeapon()Methodsprotected virtual Sandbox.SceneTrace BulletTrace(Ray ray, System.Single distance, System.Single radius)public virtual System.Void CancelReload()public virtual System.Boolean CanPrimaryAttack()public virtual System.Boolean CanReload()public virtual System.Boolean CanSecondaryAttack()protected virtual System.Void CreateViewModel()protected virtual System.Void CreateWorldModel()protected virtual System.Void DestroyViewModel()protected virtual System.Void DestroyWorldModel()public virtual System.Void DrawCrosshair(Sandbox.Rendering.HudPainter hud, Vector2 center)public System.Void DrawHud(Sandbox.CameraComponent camera)public virtual System.Void DrawHud(Sandbox.Rendering.HudPainter painter, Vector2 crosshair)public virtual System.Void DryFire()public System.Boolean FirePrimary()public System.Boolean FireSecondary()public virtual Transform GetMuzzleTransform()protected virtual System.Int32 GetReserveAmmo(Sandbox.BaseAmmoResource ammoType)public virtual System.Boolean HasPrimaryAmmo()public virtual System.Boolean HasSecondaryAmmo()public static System.Void ImpactEffect(Sandbox.BaseCombatWeapon.ShotEffect shot)public static System.Void ImpactEffect(Sandbox.SceneTraceResult tr)public static System.Void ImpactPrefab(Sandbox.GameObject hitObject, Sandbox.Surface surface, Vector3 position, Vector3 normal)protected virtual System.Void ModifyCamera(Sandbox.CameraComponent camera, Sandbox.CameraView view)protected virtual System.Void OnAdded(Sandbox.BaseInventoryComponent inventory)protected virtual System.Boolean OnAdding(Sandbox.BaseInventoryComponent inventory)protected virtual System.Void OnControl()protected virtual System.Void OnEquipped()protected virtual System.Void OnHolstered()protected virtual System.Void OnReloadCancelled()protected virtual System.Void OnReloadFinished()protected virtual System.Void OnReloadInserted()protected virtual System.Void OnReloadStarted()protected virtual System.Void OnShootEffects(Sandbox.BaseCombatWeapon.ShotEffect shot)protected virtual System.Void OnShootImpact(Sandbox.BaseCombatWeapon.ShotEffect& modreq(System.Runtime.InteropServices.InAttribute) shot)protected virtual System.Void OnUpdate()protected virtual System.Boolean OnValidateShotClaim(Sandbox.BaseCombatWeapon.ShotClaim& modreq(System.Runtime.InteropServices.InAttribute) claim)protected virtual System.Void PlaceViewModel(Sandbox.CameraComponent camera, Sandbox.CameraView& modreq(System.Runtime.InteropServices.InAttribute) view)protected System.Void PlayAttackSound()public virtual System.Void PrimaryAttack()public virtual System.Void Reload()public virtual System.Void SecondaryAttack()public System.Void SetNextFire(System.Single delay)public System.Void SetNextPrimaryFire(System.Single delay)public System.Void SetNextSecondaryFire(System.Single delay)public static Sandbox.SceneTraceResult ShootBullet(Sandbox.Scene scene, Ray ray, System.Single distance, System.Single radius, System.Single damage, System.Single force, Sandbox.GameObject attacker, Sandbox.GameObject weapon, Sandbox.GameObject ignore = null, Sandbox.TagSet tags = null)public static Sandbox.SceneTraceResult ShootBullet(Sandbox.SceneTraceResult tr, System.Single damage, System.Single force, Sandbox.GameObject attacker, Sandbox.GameObject weapon, Sandbox.TagSet tags = null, System.Boolean hitboxTags = True)protected Sandbox.SceneTraceResult ShootBullet(Sandbox.SceneTraceResult tr, System.Single damage, System.Single force, Sandbox.TagSet tags = null, System.Boolean hitboxTags = True)protected Sandbox.SceneTraceResult ShootBullet(System.Single distance, System.Single radius, System.Single damage, System.Single force, Sandbox.TagSet tags = null)public static Sandbox.SceneTraceResult[] ShootBullets(Sandbox.Scene scene, Ray ray, System.Int32 count, Vector2 spread, System.Single distance, System.Single radius, System.Single damage, System.Single force, Sandbox.GameObject attacker, Sandbox.GameObject weapon, Sandbox.GameObject ignore = null, Sandbox.TagSet tags = null)protected Sandbox.SceneTraceResult[] ShootBullets(System.Int32 count, Vector2 spread, System.Single distance, System.Single radius, System.Single damage, System.Single force, Sandbox.TagSet tags = null)public System.Void ShootEffects()public System.Void ShootEffects(Sandbox.BaseCombatWeapon.ShotEffect shot)public System.Void ShootEffects(Sandbox.BaseCombatWeapon.ShotEffect[] volley)public System.Boolean TakePrimaryAmmo(System.Int32 amount = 1)protected virtual System.Int32 TakeReserveAmmo(Sandbox.BaseAmmoResource ammoType, System.Int32 amount)public System.Boolean TakeSecondaryAmmo(System.Int32 amount = 1)protected virtual System.Void Think()protected virtual System.Void UpdateBodyAnimations(Sandbox.SkinnedModelRenderer body)protected virtual System.Boolean WantsPrimaryAttack()protected virtual System.Boolean WantsReload()protected virtual System.Boolean WantsSecondaryAttack()Propertiespublic virtual Ray Sandbox.BaseCombatWeapon.AimRay { get; set; }public System.Int32 Sandbox.BaseCombatWeapon.Ammo1 { get; set; }public System.Int32 Sandbox.BaseCombatWeapon.Ammo2 { get; set; }protected virtual Sandbox.GameObject Sandbox.BaseCombatWeapon.Attacker { get; set; }public Sandbox.SoundEvent Sandbox.BaseCombatWeapon.AttackSound { get; set; }public System.Boolean Sandbox.BaseCombatWeapon.AutoReload { get; set; }public Sandbox.BaseCombatWeapon.BallisticConfig Sandbox.BaseCombatWeapon.Ballistics { get; set; }public System.Boolean Sandbox.BaseCombatWeapon.CanCancelReload { get; set; }public System.Int32 Sandbox.BaseCombatWeapon.Clip1 { get; set; }public System.Int32 Sandbox.BaseCombatWeapon.Clip2 { get; set; }public System.Int32 Sandbox.BaseCombatWeapon.ClipMaxSize { get; set; }protected Color Sandbox.BaseCombatWeapon.CrosshairCanShoot { get; set; }protected Color Sandbox.BaseCombatWeapon.CrosshairNoShoot { get; set; }public virtual Vector2 Sandbox.BaseCombatWeapon.CurrentSpread { get; set; }public System.Single Sandbox.BaseCombatWeapon.DeployTime { get; set; }public Sandbox.SoundEvent Sandbox.BaseCombatWeapon.DryFireSound { get; set; }public System.Single Sandbox.BaseCombatWeapon.FirstShellReloadTime { get; set; }public Sandbox.BaseCombatWeapon.WeaponHandedness Sandbox.BaseCombatWeapon.Handedness { get; set; }public System.String Sandbox.BaseCombatWeapon.HoldBone { get; set; }public Sandbox.SkinnedModelRenderer Sandbox.BaseCombatWeapon.HolderRenderer { get; set; }public System.String Sandbox.BaseCombatWeapon.HoldType { get; set; }public System.Boolean Sandbox.BaseCombatWeapon.IncrementalReloading { get; set; }public System.Boolean Sandbox.BaseCombatWeapon.IsHeld { get; set; }public System.Boolean Sandbox.BaseCombatWeapon.IsReloading { get; set; }public System.Int32 Sandbox.BaseCombatWeapon.MaxReserveAmmo { get; set; }protected Sandbox.TimeUntil Sandbox.BaseCombatWeapon.NextPrimaryFire { get; set; }protected Sandbox.TimeUntil Sandbox.BaseCombatWeapon.NextSecondaryFire { get; set; }public Sandbox.BaseCombatWeapon.NpcUsage Sandbox.BaseCombatWeapon.Npc { get; set; }public Sandbox.PlayerController Sandbox.BaseCombatWeapon.Owner { get; set; }public Sandbox.BaseAmmoResource Sandbox.BaseCombatWeapon.PrimaryAmmoType { get; set; }public System.Boolean Sandbox.BaseCombatWeapon.PrimaryAutomatic { get; set; }public System.Int32 Sandbox.BaseCombatWeapon.PrimaryClipSize { get; set; }public System.Single Sandbox.BaseCombatWeapon.PrimaryDelay { get; set; }protected virtual System.Int32 Sandbox.BaseCombatWeapon.ReloadFillTarget { get; set; }public System.Single Sandbox.BaseCombatWeapon.ReloadStartTime { get; set; }public System.Single Sandbox.BaseCombatWeapon.ReloadTime { get; set; }public Sandbox.BaseAmmoResource Sandbox.BaseCombatWeapon.SecondaryAmmoType { get; set; }public System.Boolean Sandbox.BaseCombatWeapon.SecondaryAutomatic { get; set; }public System.Int32 Sandbox.BaseCombatWeapon.SecondaryClipSize { get; set; }public System.Int32 Sandbox.BaseCombatWeapon.SecondaryDefaultClip { get; set; }public System.Single Sandbox.BaseCombatWeapon.SecondaryDelay { get; set; }public virtual System.Boolean Sandbox.BaseCombatWeapon.ShouldAvoid { get; set; }protected System.Single Sandbox.BaseCombatWeapon.SpreadBloom { get; set; }public System.Single Sandbox.BaseCombatWeapon.SpreadScale { get; set; }public System.Int32 Sandbox.BaseCombatWeapon.StartingAmmo { get; set; }protected Sandbox.TimeSince Sandbox.BaseCombatWeapon.TimeSinceShoot { get; set; }protected virtual Ray Sandbox.BaseCombatWeapon.UnheldAimRay { get; set; }public System.Boolean Sandbox.BaseCombatWeapon.UsableByNpcs { get; set; }public System.Boolean Sandbox.BaseCombatWeapon.UsesAmmo { get; set; }public System.Boolean Sandbox.BaseCombatWeapon.UsesClips { get; set; }public System.Boolean Sandbox.BaseCombatWeapon.UsesPrimaryClip { get; set; }public System.Boolean Sandbox.BaseCombatWeapon.UsesSecondaryClip { get; set; }public Sandbox.GameObject Sandbox.BaseCombatWeapon.ViewModel { get; set; }public Sandbox.GameObject Sandbox.BaseCombatWeapon.ViewModelPrefab { get; set; }public Sandbox.BaseWeaponModel Sandbox.BaseCombatWeapon.WeaponModel { get; set; }public Sandbox.GameObject Sandbox.BaseCombatWeapon.WorldModel { get; set; }public Sandbox.GameObject Sandbox.BaseCombatWeapon.WorldModelPrefab { get; set; }Metadata