Weapon Base item
Item defined in core/items/sh_weapon_base.lua
Defines the weapon_base base item for weapons: using one gives the player its weaponClass, and unequipping
holsters it back into the inventory or drops it.
Instances keep their loaded clips in the networked ClipOne and ClipTwo data. OnSetup fills in the ammo classes
and default ammo from the SWEP table, or from a built-in list for the Half-Life 2 weapons, and the
PlayerCanHolsterWeapon and PlayerCanDropWeapon hooks gate unequipping.
Summary
Methods
Ammo option listing the loaded clips to the item entity's menu when the weapon has ammo stored.Callback with nil or 'drop' for the choice.extraData is 'drop'.weaponClass and, two seconds later, fills in the ammo classes and default ammo from the weapon.OnEquip; the item leaves the inventory while the weapon is out.ClipOne/ClipTwo data.Methods
ITEM:CanHolsterWeapon(player, forceHolster, bNoMsg)
shared gamemodes/catwork/gamemode/core/items/sh_weapon_base.lua:93Allows the weapon to be holstered.
Parameters
- player
- forceHolster
- bNoMsg
Returns
- Boolean Always
true
Returns tooltip lines showing the ammo stored in the weapon's clips.
Returns
- String Markup lines, or
falsewhen both clips are empty
ITEM:GetEntityMenuOptions(entity, options)
shared gamemodes/catwork/gamemode/core/items/sh_weapon_base.lua:32Adds an Ammo option listing the loaded clips to the item entity's menu when the weapon has ammo stored.
Parameters
- entity
- options
Returns the weapon class the item gives.
Returns
- String
weaponClass, or the item's unique ID when it has none
ITEM:HasPlayerEquipped(player, bIsValidWeapon)
shared gamemodes/catwork/gamemode/core/items/sh_weapon_base.lua:67Returns whether the player holds this exact weapon item.
On the client there is no way to check, so it returns bIsValidWeapon.
Parameters
- player
- bIsValidWeapon
Returns
- Boolean Whether the item is equipped
Returns whether the weapon has a primary clip.
Returns
- Boolean
falsewhenhasNoPrimaryClipis set
Returns whether the weapon has a secondary clip.
Returns
- Boolean
falsewhenhasNoSecondaryClipis set
Returns whether the item is a fake weapon.
Returns
- Boolean The
isFakeWeaponfield
Returns whether the item is a melee weapon.
Returns
- Boolean The
isMeleeWeaponfield
Returns whether the item is a throwable weapon.
Returns
- Boolean The
isThrowableWeaponfield
Called when a player drops the weapon item; does nothing, so dropping is allowed.
Parameters
- player
- position
Shows a Holster/Drop menu on the client and calls Callback with nil or 'drop' for the choice.
Calls Callback() straight away when the item has no OnDrop.
Parameters
- Callback Function Called with the unequip mode:
nilto holster,'drop'to drop
Called when a player holsters the weapon; does nothing in the base.
Parameters
- player
- bForced
ITEM:OnPlayerUnequipped(player, extraData)
shared gamemodes/catwork/gamemode/core/items/sh_weapon_base.lua:122Holsters the weapon back into the inventory, or drops it where the player looks when extraData is 'drop'.
Runs PlayerCanHolsterWeapon/PlayerHolsterWeapon or PlayerCanDropWeapon/PlayerDropWeapon.
Parameters
- player
- extraData
Lowercases weaponClass and, two seconds later, fills in the ammo classes and default ammo from the weapon.
Values come from the stored SWEP table, or from a built-in list for the HL2 weapons; fields already set on the item are kept.
Gives the player the weapon and calls OnEquip; the item leaves the inventory while the weapon is out.
If the player already has the weapon, it calls OnAlreadyHas instead.
Parameters
- player
- itemEntity
Returns
- Boolean
false(keeping the item) when the weapon could not be given or is already held
ITEM:OnWeaponGiven(player, weapon)
shared gamemodes/catwork/gamemode/core/items/sh_weapon_base.lua:190Strips the weapon's default ammo and loads the clips stored in the item's ClipOne/ClipTwo data.
Parameters
- player
- weapon