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

Allows the weapon to be holstered.
Returns tooltip lines showing the ammo stored in the weapon's clips.
Adds an Ammo option listing the loaded clips to the item entity's menu when the weapon has ammo stored.
Returns the weapon class the item gives.
Returns whether the player holds this exact weapon item.
Returns whether the weapon has a primary clip.
Returns whether the weapon has a secondary clip.
Returns whether the item is a fake weapon.
Returns whether the item is a melee weapon.
Returns whether the item is a throwable weapon.
Called when a player drops the weapon item; does nothing, so dropping is allowed.
Shows a Holster/Drop menu on the client and calls Callback with nil or 'drop' for the choice.
Called when a player holsters the weapon; does nothing in the base.
Holsters the weapon back into the inventory, or drops it where the player looks when extraData is 'drop'.
OnSetup()shared
Lowercases weaponClass and, two seconds later, fills in the ammo classes and default ammo from the weapon.
Gives the player the weapon and calls OnEquip; the item leaves the inventory while the weapon is out.
Strips the weapon's default ammo and loads the clips stored in the item's ClipOne/ClipTwo data.

Methods

ITEM:CanHolsterWeapon(player, forceHolster, bNoMsg)

shared gamemodes/catwork/gamemode/core/items/sh_weapon_base.lua:93

Allows 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 false when both clips are empty

ITEM:GetEntityMenuOptions(entity, options)

shared gamemodes/catwork/gamemode/core/items/sh_weapon_base.lua:32

Adds 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:67

Returns 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 false when hasNoPrimaryClip is set

Returns whether the weapon has a secondary clip.

Returns

  • Boolean false when hasNoSecondaryClip is set

Returns whether the item is a fake weapon.

Returns

  • Boolean The isFakeWeapon field

Returns whether the item is a melee weapon.

Returns

  • Boolean The isMeleeWeapon field

Returns whether the item is a throwable weapon.

Returns

  • Boolean The isThrowableWeapon field

Called when a player drops the weapon item; does nothing, so dropping is allowed.

Parameters

  • player
  • position

ITEM:OnHandleUnequip(Callback)

shared gamemodes/catwork/gamemode/core/items/sh_weapon_base.lua:101

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: nil to holster, 'drop' to drop

ITEM:OnHolster(player, bForced)

shared gamemodes/catwork/gamemode/core/items/sh_weapon_base.lua:330

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:122

Holsters 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.

ITEM:OnUse(player, itemEntity)

shared gamemodes/catwork/gamemode/core/items/sh_weapon_base.lua:213

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:190

Strips the weapon's default ammo and loads the clips stored in the item's ClipOne/ClipTwo data.

Parameters

  • player
  • weapon

Defined in