ItemWeapon is the base class for items that give the player a weapon while equipped. A derived item sets weapon_class, the class of the weapon ('weapon_pistol' by default), and usually equip_slot, which is 'item.slot.primary' by default. Equipping the item gives the weapon to the player and selects it; unequipping strips it. The rounds in both clips of the weapon are stored in the ammo data of the item when it is unequipped and when the character is saved, and loaded back when it is equipped. The unload button of the menu moves the loaded rounds to the ammo reserve of the player.

Summary

Methods

Called on the server before the character of the player that has the item is saved.
Called on the server when a player presses the unload button in the item's menu.
Called when the item gets equipped.
Called when the item gets unequipped.

Methods

Called on the server before the character of the player that has the item is saved. Stores the contents of the weapon's clips in the item's data if the item is equipped.

Parameters

  • owner Player

ItemWeapon:on_unload(owner)

shared plugins/items/plugin/items/bases/sh_item_weapon.lua:77

Called on the server when a player presses the unload button in the item's menu. Empties the clips of the weapon and gives the ammo back to the player. Does nothing if the item is not equipped or the player does not have its weapon.

Parameters

  • owner Player

ItemWeapon:post_equipped(owner)

shared plugins/items/plugin/items/bases/sh_item_weapon.lua:43

Called when the item gets equipped. Gives the player the weapon, selects it and loads its clips with the ammo that is stored in the item's data.

Parameters

  • owner Player

ItemWeapon:post_unequipped(owner)

shared plugins/items/plugin/items/bases/sh_item_weapon.lua:60

Called when the item gets unequipped. Strips the weapon from the player and stores the contents of its clips in the item's data.

Parameters

  • owner Player

Defined in