Remarks

Hold-type animation stays animation agnostic: BaseWeapon.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.

build Constructors 1

data_object Properties 57

AimRay
Ray
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.BaseWeapon.UnheldAimRay.
Ammo1
int
Reserve ammo available to primary fire - the holder's pool of Sandbox.BaseWeapon.PrimaryAmmoType (GMod's Ammo1).
Ammo2
int
Reserve ammo available to secondary fire (GMod's Ammo2).
Attacker
GameObject
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).
AttackSound
SoundEvent
Sound played when the weapon attacks - the gunshot, swing, launch. Played by the base Sandbox.BaseWeapon.OnShootEffects(Sandbox.BaseWeapon.ShotEffect), so it reaches every peer that sees the shot.
AutoReload
bool
Start a reload automatically when the trigger is pulled on an empty magazine.
Ballistics
BallisticConfig
How the default Sandbox.BaseWeapon.PrimaryAttack shoots - damage, pellets, spread and reach.
CanCancelReload
bool
Can the reload be cancelled (e.g. by firing) part-way through?
Clip1
int
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.BaseWeapon.TakePrimaryAmmo(System.Int32)), whose count is the truth.
Clip2
int
Rounds currently in the secondary magazine, or -1 when unused (GMod's Clip2). Host authoritative.
ClipMaxSize
int
Primary magazine size.
CrosshairCanShoot
Color
Crosshair colour for a weapon that's ready to fire.
CrosshairNoShoot
Color
Crosshair colour for a weapon that can't fire - empty, reloading, cooling down.
CurrentSpread
Vector2
The current spread cone in degrees - the base cone widened by recent firing. Override to modify it (e.g. narrow while aiming down sights).
DeployTime
float
Seconds after deploying (switching to) this weapon before it can fire.
DryFireSound
SoundEvent
Sound played when the trigger is pulled with no ammo.
FirstShellReloadTime
float
Extra delay after the first round before the rest (e.g. a longer first insert). Incremental only.
Handedness
WeaponHandedness
Which hand(s) the holder carries this in - drives the holder animgraph's "holdtype_handedness" parameter alongside Sandbox.BaseWeapon.HoldType. Only some hold types support it (e.g. pistol, holditem).
HoldBone
string
The bone on the holder's renderer to attach the world model to.
HolderRenderer
SkinnedModelRenderer
The body renderer the world model attaches to - the holder's renderer.
HoldType
string
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.
IncrementalReloading
bool
Load one round at a time instead of the whole magazine (shotgun-style).
IsHeld
bool
True while held by a player.
IsReloading
bool
True while a reload is in progress. Host authoritative, synced so every peer can animate.
MaxReserveAmmo
int
Most reserve ammo the holder can carry for primary fire (from the ammo type).
NextPrimaryFire
TimeUntil
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.BaseWeapon.OnValidateShotClaim(Sandbox.BaseWeapon.ShotClaim@)).
NextSecondaryFire
TimeUntil
Time until secondary fire is off cooldown.
Npc
NpcUsage
How an NPC fights with this weapon.
Owner
PlayerController
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.
PrimaryAmmoType
AmmoResource
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.
PrimaryAutomatic
bool
When true primary fire keeps firing while the button is held; when false it fires once per press (GMod's Primary.Automatic).
PrimaryClipSize
int
Magazine size for primary fire, or -1 when it feeds straight from reserve (GMod's Primary.ClipSize). Derived from Sandbox.BaseWeapon.UsesAmmo / Sandbox.BaseWeapon.UsesClips / Sandbox.BaseWeapon.ClipMaxSize.
PrimaryDelay
float
Seconds between primary shots - the fire rate (GMod's Primary.Delay).
ReloadFillTarget
int
How full a reload fills the primary magazine. Defaults to Sandbox.BaseWeapon.PrimaryClipSize - override for +1-in-the-chamber style reloads (e.g. ClipMaxSize + (Clip1 > 0 ? 1 : 0)). Read once when the reload starts.
ReloadStartTime
float
Delay before the first round goes in. Zero uses Sandbox.BaseWeapon.ReloadTime.
ReloadTime
float
How long a (full) reload takes, in seconds. For incremental reloads, the time per round.
SecondaryAmmoType
AmmoResource
SecondaryAutomatic
bool
When true secondary fire is full-auto while held.
SecondaryClipSize
int
Magazine size for secondary fire, or -1 when it doesn't use one (GMod's Secondary.ClipSize). Set directly - unlike Sandbox.BaseWeapon.PrimaryClipSize, it isn't derived from the clip settings.
SecondaryDefaultClip
int
Rounds loaded into the secondary magazine when first given. -1 fills it.
SecondaryDelay
float
Seconds between secondary shots.
ShouldAvoid
bool
Avoid auto-switching to a gun with nothing left to fire or load (see Sandbox.BaseInventoryItem.ShouldAvoid).
SpreadBloom
float
How bloomed the spread is - 0 settled, 1 right after a shot.
SpreadScale
float
Runtime multiplier on the spread cone - 1 is the configured ballistics. NPCs set this to the weapon's Sandbox.BaseWeapon.Npc spread scale times their own skill when they equip it.
StartingAmmo
int
Reserve ammo granted on first pickup, seeded into the holder's pool.
TimeSinceShoot
TimeSince
Time since the last shot - drives spread bloom.
UnheldAimRay
Ray
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.
UsableByNpcs
bool
Can NPCs fight with this weapon at all?
UsesAmmo
bool
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.
UsesClips
bool
Feed primary fire from a magazine (true) or straight from the reserve pool (false).
UsesPrimaryClip
bool
True when primary fire feeds from a magazine rather than straight from reserve.
UsesSecondaryClip
bool
True when secondary fire feeds from a magazine.
ViewModel
GameObject
The spawned view model instance, or null. Owner-only and not networked - each client makes its own.
ViewModelPrefab
GameObject
First-person view model prefab. Spawned only on the client holding this item.
WeaponModel
BaseWeaponModel
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.
WorldModel
GameObject
The spawned world model instance, or null. Not networked - each peer makes its own.
WorldModelPrefab
GameObject
Third-person world model prefab, attached to the holder's hand bone. Seen by everyone.

functions Methods 49

BulletTrace (ray, distance, radius)
SceneTrace
The trace used for this weapon's bullets. Base traces against hitboxes and ignores the Sandbox.BaseWeapon.Attacker's hierarchy. Override to add collision rules or filters.
CancelReload ()
Abort a reload before it finishes, loading nothing further.
CanPrimaryAttack ()
bool
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.
CanReload ()
bool
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.
CanSecondaryAttack ()
bool
CreateViewModel ()
Spawns the view model from Sandbox.BaseWeapon.ViewModelPrefab and plays its deploy presentation. Owner only, idempotent - safe to call when one already exists.
CreateWorldModel ()
Spawns the world model from Sandbox.BaseWeapon.WorldModelPrefab onto the holder's Sandbox.BaseWeapon.HoldBone, replacing any previous one.
DestroyViewModel ()
Destroys the spawned view model, if any.
DestroyWorldModel ()
Destroys the spawned world model, if any.
DrawCrosshair (hud, center)
Draw this weapon's crosshair at the aim position. Base draws a simple four-line cross.
DrawHud (camera)
Draw this weapon's HUD on the given camera - the crosshair goes at screen centre when the camera sits on the aim ray, otherwise (third person, mounted weapons) at the projected aim point. Games call this for weapons they draw manually, e.g. seat-controlled ones.
DryFire ()
The player pulled the trigger with no ammo. Base plays Sandbox.BaseWeapon.DryFireSound, throttles both triggers so it doesn't spam, and starts a reload when Sandbox.BaseWeapon.AutoReload allows. Override to extend.
FirePrimary ()
bool
Pull the primary trigger - fires if Sandbox.BaseWeapon.CanPrimaryAttack allows, putting it on cooldown. Returns whether it fired. The way to shoot from code (AI, turrets) - calling Sandbox.BaseWeapon.PrimaryAttack directly skips the fire rate. Runs on whoever controls the weapon; the attack doesn't re-run on the host.
FireSecondary ()
bool
GetMuzzleTransform ()
Transform
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.
GetReserveAmmo (ammoType)
int
Reserve ammo of the given type available to this weapon. Reads the owning inventory's shared pool (Sandbox.InventoryComponent.GetAmmo(Sandbox.AmmoResource)) - 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.
HasPrimaryAmmo ()
bool
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).
HasSecondaryAmmo ()
bool
ModifyCamera (camera, view)
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.
OnAdded (inventory)
Seed the magazines with their default contents, and the inventory's reserve pool with Sandbox.BaseWeapon.StartingAmmo. Host only, runs once when the weapon enters an inventory.
OnAdding (inventory)
bool
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.
OnControl ()
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.
OnEquipped ()
OnHolstered ()
OnReloadCancelled ()
The reload was cancelled part-way (fired, holstered). Fires on every peer, alongside Sandbox.BaseWeapon.OnReloadFinished - use it to stop timed reload sounds and the like.
OnReloadFinished ()
Reload ended (finished or cancelled). Drives the active weapon model.
OnReloadInserted ()
A round was loaded (incremental). Drives the active weapon model's per-shell insert.
OnReloadStarted ()
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.
OnShootEffects (shot)
Define the presentation for a resolved shot. Base spawns the surface impact and flies the tracer for every pellet, then plays Sandbox.BaseWeapon.AttackSound, fires the holder's "b_attack" gesture and runs Sandbox.BaseWeaponModel.OnAttack(System.Nullable{Vector3},System.Nullable{Vector3}) on the shown model (muzzle flash, brass) - those are skipped for Sandbox.BaseWeapon.ShotEffect.NoEvents pellets, which share the lead pellet's. Call it when you override. Runs on every peer that should see the shot.
OnShootImpact (shot)
OnUpdate ()
OnValidateShotClaim (claim)
bool
PlaceViewModel (camera, view)
PlayAttackSound ()
Play Sandbox.BaseWeapon.AttackSound from the weapon - non-spatialized when the local player is the shooter, so your own gun doesn't pan around your head.
PrimaryAttack ()
Fire the primary attack. The default fires Sandbox.BaseWeapon.Ballistics - spends a round, shoots the volley from Sandbox.BaseWeapon.AimRay with Sandbox.BaseWeapon.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.BaseWeapon.ShootBullet(Sandbox.SceneTraceResult,System.Single,System.Single,Sandbox.TagSet,System.Boolean)), or the host for seat/NPC/world weapons (damage applies directly).
Reload ()
Begin reloading. Routed to the host, which runs it authoritatively. Override Sandbox.BaseWeapon.OnReloadStarted and friends for presentation rather than this.
SecondaryAttack ()
Fire the secondary attack. Base does nothing - override it. Same contract as Sandbox.BaseWeapon.PrimaryAttack: runs once, on whoever controls the weapon.
SetNextFire (delay)
Put both triggers on cooldown for seconds - for weapons where a shot blocks primary and secondary alike.
SetNextPrimaryFire (delay)
Put primary fire on cooldown for seconds.
SetNextSecondaryFire (delay)
Put secondary fire on cooldown for seconds.
ShootEffects ()
Play the shot's muzzle/fire presentation with no ranged hit - muzzle flash, fire sound, shell eject. For melee swings and projectile launches. See Sandbox.BaseWeapon.ShootEffects(Sandbox.BaseWeapon.ShotEffect[]).
TakePrimaryAmmo (amount)
bool
Spend 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).
TakeReserveAmmo (ammoType, amount)
int
Take up to reserve ammo of the given type from the owning inventory's pool, returning how much was actually taken. Pairs with Sandbox.BaseWeapon.GetReserveAmmo(Sandbox.AmmoResource).
TakeSecondaryAmmo (amount)
bool
Think ()
Runs every frame before attack handling - continuous logic (spin-up, charge, ...). Base does nothing.
UpdateBodyAnimations (body)
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.
WantsPrimaryAttack ()
bool
Is the player asking to fire primary this frame? Held when automatic, pressed otherwise.
WantsReload ()
bool
Is the player asking to reload this frame?
WantsSecondaryAttack ()
bool
Is the player asking to fire secondary this frame?

functions Static Methods 4

ImpactEffect (tr)
Spawn a bullet impact at a trace hit - the hit surface's impact sound and decal/particle, oriented to the surface and parented to what was hit (its nearest bone for skinned models, so decals stick to moving things). A hit object that's already gone - killed by this very shot - still gets its impact, left where it landed in the world. A pure presentation utility like Sandbox.BaseWeapon.ShootBullet(Sandbox.Scene,Ray,System.Single,System.Single,System.Single,System.Single,Sandbox.GameObject,Sandbox.GameObject,Sandbox.GameObject,Sandbox.TagSet); call it wherever you resolve a hit. Does nothing on a dedicated server or for a trace that missed.
ImpactPrefab (hitObject, surface, position, normal)
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).
ShootBullet (scene, ray, distance, radius, damage, force, attacker, weapon, ignore, tags)
SceneTraceResult
Traces a bullet through the world and, on the host, damages and pushes whatever it hits. This is a pure utility - it holds no state, so you can call it from anywhere (a weapon, a trap, an NPC, an explosion). Returns the trace result so the caller can spawn tracers, decals and play sounds.
ShootBullets (scene, ray, count, spread, distance, radius, damage, force, attacker, weapon, ignore, tags)
SceneTraceResult[]
Fires a volley of bullets - one trace per pellet, each randomly deflected within , resolved through Sandbox.BaseWeapon.ShootBullet(Sandbox.SceneTraceResult,System.Single,System.Single,Sandbox.GameObject,Sandbox.GameObject,Sandbox.TagSet,System.Boolean) (GMod's FireBullets). A pure utility like ShootBullet - damage and impulse apply on the host only. Returns every pellet's trace so the caller can drive tracers and impacts.

Inheritance

people
Log in to reply
You can't reply if you're not logged in. That would be crazy.