Type / to search schemas

BaseCombatWeapon

HideSource
Also in
S&BoxdiffersIgnisSDKdiffersChaos Theory

Properties (31)

NameType
Owner
Who has this weapon? We use the funny WeaponOwner struct which has the casts built in, so you don't have to if (Owner is BasePlayer) every time
ReadOnly
WeaponData
ReadOnly
PrimaryAmmoLoaded
int
Primary amount WITH chambered bullet
Header
PrimaryAmmoInChamber
int
Primary amount of chambered bullets
SecondaryAmmoLoaded
int
Secondary amount WITH chambered bullet
ReadOnlyHeader
ReadyToFire
bool
Is the weapon ready to fire? (most likely in idle animation)
ReadOnlyHeader
FirstEquip
bool
ReadOnly
MagOut
bool
ReadOnly
_reloadsSingly
bool
Reload one by one, instead of by mag (shotguns, rifles)
protected · virtual
ReadOnly
DoFirstSetup
bool
This should've been OnStart
ReadOnly
WasOnTheGround
bool
ReadOnly
_shotsFired
int
How many shots were fired in quick succession (consequitive shots)
protected
ReadOnly
LastAttackTime
float
When was the last time we did any kind of attack
ReadOnly
_nextPrimaryAttack
float
When is the next primary shot
protected
ReadOnly
_nextSecondaryAttack
float
When is the next secondary shot
protected
ReadOnly
_nextEmptyAttack
float
When is the next dry fire click
protected
ReadOnly
IsHolstered
bool
Is the gun currently SPECIFICALLY holstered (and not just unavailable to shoot) PS: this is used for the "full holster" when weapon switching
ReadOnly
_disallowAttack
bool
Is attack blocked (mid reload, mid draw)
protected
ReadOnly
_inStagedReload
bool
Used to track whether we are storing a staged reloading state
protected
ReadOnly
IsReloading
bool
Is this weapon currently reloading (stage agnostic, some don't care)
ReadOnly
_currentReloadStage
int
What stage of reloading I'm on
protected
ReadOnly
DebugReloadStage
bool
DebugNoRecoil
bool
_amountPerShot
int
protected · virtual
_isProjectile
bool
protected · virtual
_muzzleSpotLight
protected · virtual
_delete
protected
DebugMuzzle
bool
_debugAnimEvents
bool
IsPrimaryAttackDown
bool
Fake NPC left mouse input to know when it wants to attack
IsSecondaryAttackDown
bool
Fake NPC right mouse input to know when it wants to attack

Fields & Events (1)

NameType
_shootHandle
protected

Constructors (1)

NameType
BaseCombatWeapon()

Methods (65)

NameType
GetEditorVis()
string
protected · override
HolsterAction()
void
What happens when the holster finishes, per each kind of holster reason there can be
protected · virtual
ChangeReloadStage()
void
protected · virtual
ChangePrimaryAmmo()
void
protected · virtual
ChangeEmpty()
void
protected · virtual
OnEnabled()
void
protected · override
OnStart()
void
protected · override
SetupCustomData()
void
Use this to setup your custom data instead of overriding OnStart and having to do base.OnStart() etc etc
protected · virtual
FirstSetup()
void
protected · virtual
ForceFirstSetup()
void
Use this to pre-warm a newly given weapon that's not enabled by default. This also makes sure that if you picked up multiple weapons, first equip doesn't play on all of them when switched for the first time.
OnUpdate()
void
protected · override
OnFixedUpdate()
void
protected · override
HandleWeaponInput()
void
Handle what all the buttons do for weapons, kinda equivalent to BaseCombatWeapon::ItemPostFrame()
protected · virtual
HandleWeaponStates()
void
Handle the animgraph params, reload stuff, anything that isn't input but has to be per frame
protected · virtual
Draw(BasePlayer.HolsterType type = BasePlayer.HolsterType.Weapon, bool force = false)
void
Draw the weapon. Needs to be public because other stuff can force us to draw
virtual
Holster(BasePlayer.HolsterType type = BasePlayer.HolsterType.Weapon, bool force = false)
void
Holster the weapon. Needs to be public because other stuff can force us to put down the weapon
virtual
AttackConditions(bool primary = true)
bool
Can I shoot? | Yes/No
protected · virtual
PrimaryAttack()
void
The main weapon shot, usually left mouse click.
protected · virtual
FireBullet(bool isPlayer = true, bool isPrimary = true)
void
Actually fire the AttackResult bullets
virtual
HandleFireOnEmpty(float delay = 0.5f)
void
Empty version (no ammo) of PrimaryAttack(), but can be used for SecondaryAttack().
protected · virtual
SecondaryAttack()
void
Second type of attack, usually right mouse click.
protected · virtual
StartReload(bool reloadPrimary = true)
void
Reload the weapon.
protected · virtual
FinishReload(bool reloadPrimary = true)
void
protected · virtual
ReprojectToViewmodel(Vector3 worldPos, Vector3 cameraPos, Vector3 cameraForward, float viewmodelFov, float cameraFov, float flatten = 0f)
GetMuzzleAttachObject(BaseEntity owner, string name, out GameObject muzzleObject)
Easy way to get world transform of the attachment as an attachment object, if there is one | FOV scaled transform of the muzzle, if the player is local
CreateMuzzleFlash(bool player = true)
void
Create the muzzle effect (particle and light) with all settings from the weapon resource
protected · virtual
Broadcast
ClearEffects(GameObject go)
void
Force clear all effects
virtual
AttackSound(bool firstperson = true, bool primary = true)
void
protected · virtual
Broadcast
EjectShells()
void
Spawn a shell effect on a shell_eject attachment. Need Bone Objects!
protected · virtual
EventDisallowFiring(bool disallow)
void
Cannot shoot
virtual
EventDrawFinished()
void
Putting the gun back on the screen has finished
virtual
EventHolsterFinished()
void
Putting the gun away was finished
virtual
EventPrimaryFire()
void
Gun has been fired
virtual
EventMagOut()
void
The first reload event, starting from here the
virtual
EventMagIn()
void
Usually the second in order event, magazine is back in
virtual
EventBoltRelease()
void
Usually the third and last (for full/empty reloads) in order event, bolt is released and you now can shoot
virtual
EventReloadFinished()
void
Reload has been finished, hooray!
virtual
GetPrimaryCapacity()
int
Clip/Magazine size of primary ammo for this weapon (not currently loaded, but the actual mag size) | The amount
GetSecondaryCapacity()
int
Clip/Magazine size of secondary ammo for this weapon (not currently loaded, but the actual mag size)
GetPrimaryDefault()
int
Default primary quantity (when given for the first time) | The amount
GetSecondaryDefault()
int
Default secondary quantity (when given for the first time) | The amount
GetPrimaryAmmoType()
string
The primary ammo type of this weapon as a string | The name of the ammo resource
GetSecondaryAmmoType()
string
The secondary ammo type of this weapon as a string | The name of the ammo resource
HasLoadedAmmo()
bool
Return true if this weapon has some ammo
HasUsableAmmo()
bool
Any ammo at all loaded or not
UsesPrimary()
bool
Does this weapon use primary attack? | Yes/No
UsesSecondary()
bool
Does this weapon use secondary attack? | Yes/No
IsMeleeWeapon()
bool
Is this weapon a melee? | Yes/No
virtual
GetPrimaryFireRate()
float
Get the fire rate for primary attack | The it
virtual
GetSecondaryFireRate()
float
Get the fire rate for secondary attack | The it
virtual
GetWeaponType()
string
Get weapon type as string | Weapon type
GetWeaponCrosshairType()
string
Get weapon type as string | Weapon type
AmmoResourceHasAnythingPrimary()
bool
Does Primary Ammo property contain anything? | Yes/No
AmmoResourceHasAnythingSecondary()
bool
Does Secondary Ammo property contain anything? | Yes/No
GetCustomDataFloat(string key)
float
A quick way to get a value out of custom data | Associated float (or int)
protected
GetCustomDataString(string key)
string
protected
GetDamageInfo(bool isPrimary, bool isPlayer)
Process the correct DamageInfo for the type of attack we are having | DamageInfo with correct values applied
GetSpreadForBullet(bool isPrimary, int shotsFired, int bulletIndex = 0, int bulletCount = 1)
float
Get the spread for a single bullet based on WeaponData and SpreadType | Spread in degrees
protected · virtual
OnUpdateNPC()
void
OnUpdate but for NPC
protected · virtual
OnFixedUpdateNPC()
void
OnFixedUpdate but for NPC
protected · virtual
HandleNPCInput()
void
Handle fake NPC inputs
protected · virtual
PrimaryAttackNPC()
void
NPC version of PrimaryAttack()
protected · virtual
SecondaryAttackNPC()
void
NPC version of SecondaryAttack()
protected · virtual
AttackConditionsNPC(bool primary = true)
bool
protected · virtual
ForceReload(bool primary = true)
void
Public function to be able to reload the weapon from elsewhere