Attachments, tints, ammo, durability and serials
Components swap a weapon’s parts: suppressors, scopes, flashlights, magazines, grips and camos. A tint recolours the whole weapon. Ammo, wear and registration live in ox_inventory item metadata.
local ped, weapon = PlayerPedId(), `WEAPON_CARBINERIFLE`
if DoesWeaponTakeWeaponComponent(weapon, `COMPONENT_AT_AR_SUPP`) then
GiveWeaponComponentToPed(ped, weapon, `COMPONENT_AT_AR_SUPP`)
end
SetPedWeaponTintIndex(ped, weapon, 2) -- 2 = gold on normal weapons| Tint index (normal weapons) | Colour |
|---|---|
| 0 | Default (black) |
| 1 | Green |
| 2 | Gold |
| 3 | Pink |
| 4 | Army |
| 5 | LSPD |
| 6 | Orange |
| 7 | Platinum |
MK II weapons use a larger palette, 0–31. GetWeaponTintCount(hash) returns how many tints a weapon has.
In ox_inventory an attachment is an item listed under Components in data/weapons.lua, at_suppressor_light for example. Each one has a type and a client.component list of component hashes. Using the item on a weapon attaches the first component in that list that fits and records it in metadata.components.
MK II camos are components named COMPONENT_<WEAPON>_MK2_CAMO, _CAMO_02 … _CAMO_10 and _CAMO_IND_01, and SetPedWeaponLiveryColor(ped, weapon, component, tint) colours them. A component that floats away from the weapon has its bone (WAPSupp, WAPScop, WAPFlshLasr, WAPClip, WAPGrip) in the wrong place on the model.
Every stock COMPONENT_ name, its hash and the weapon it fits is listed in the weapon components reference.
Ammo, wear and registration are what make weapons part of a server’s economy, and ox_inventory handles all three through item metadata.
| ox_inventory ammo item | Calibre | Used by |
|---|---|---|
ammo-9 | 9 mm | Most pistols and SMGs |
ammo-rifle | 5.56×45 | Carbine-type rifles |
ammo-rifle2 | 7.62×39 | AK-type rifles |
ammo-shotgun | 12 gauge | Shotguns |
ammo-sniper | Sniper rounds | Sniper rifles |
The ammoname of each weapon in data/weapons.lua names the item that reloads it.
- Durability: a new weapon has
metadata.durability = 100, and every shot subtracts the weapon’sdurabilityvalue (0.1 for pistols, for example). At 0 it is broken until someone repairs it. - Serials: a weapon that uses ammo gets
registered(the owner’s name) and a serial of six digits, three letters and six digits. Pass a three-character prefix such asserial = 'POL'and it takes the middle position. metadata = { registered = false }creates an unregistered weapon with no serial, which is the black-market version.- The infinite ammo natives (
SetPedInfiniteAmmo,SetPedInfiniteAmmoClip) suit arenas and events, not a server that runs an inventory.
exports.ox_inventory:AddItem(source, 'WEAPON_COMBATPISTOL', 1, { serial = 'POL', ammo = 12 })
exports.ox_inventory:AddItem(source, 'ammo-9', 48)