ItemAmmo is the base class for boxes of ammunition. A derived item sets ammo_class, the name of the ammo type as Player:GiveAmmo takes it ('Pistol' by default), and ammo_count, the amount of ammo that one use gives (16 by default). Using the item gives that ammo to the player. With max_uses above 1, inherited from ItemUsable, a box can be used several times before it is gone. With the ammo_requires_weapon config on, the ammo can only be loaded by a player who carries a weapon that uses it.

Summary

Methods

Called by ItemUsable:on_use before the item is used.
Checks whether the player carries a weapon that takes the ammo of the item as its primary or secondary ammo.
Called by ItemUsable:on_use when the item is used.

Methods

Called by ItemUsable:on_use before the item is used. With the 'ammo_requires_weapon' config on, refuses to load the ammo and notifies the player if they carry no weapon that uses it.

Parameters

  • actor Player

Returns

  • Boolean false to prevent the use, nil otherwise

ItemAmmo:has_weapon_for(actor)

shared plugins/items/plugin/items/bases/sh_item_ammunition.lua:30

Checks whether the player carries a weapon that takes the ammo of the item as its primary or secondary ammo. Only the weapons the player has on them count, so the weapon items that are not equipped do not.

Parameters

  • actor Player

Returns

  • Boolean false also if the ammo type of the item does not exist

Called by ItemUsable:on_use when the item is used. Gives the player the ammo of the item.

Parameters

  • actor Player

Defined in