Koja Scripts

Items

How to define items in shared/items.lua: size, stacking, equipment, backpacks, weapons, usables, held props, durability and salvage.

Items

Items are defined in shared/items.lua. Items from ox_inventory's data/items.lua and data/weapons.lua are imported automatically; define an item here to override the imported version (for example to give it a better grid size). Items can also be created at runtime from other resources. See Runtime items.

shared/items.lua
WEAPON_CARBINERIFLE = {
    label = 'Carbine rifle',
    size = { 4, 2 },
    weight = 3800,
    stack = 1,
    category = 'weapon',
    rarity = 'epic',
    equip = 'weapon_primary',
    weapon = { ammo = 'ammo_rifle', clip = 30 },
    description = '5.56 mm assault carbine.',
    salvage = { duration = 8000, results = { { name = 'scrap_metal', count = { 4, 8 } } } },
},

Basic fields

FieldDescription
labelName shown in the UI.
descriptionText in the item popup.
size{ width, height } in cells.
weightGrams per unit.
stackMax units in one stack. 1 means it never stacks.
categoryFree text used for filters, repair rules and slot rules, e.g. weapon, tools, food.
raritycommon, uncommon, rare, epic or legendary. Colours the tile.
imageFile name in Config.ImagePath without .png. Defaults to the item name.
propModel used when the item lies on the ground or is held.
closefalse keeps the inventory open after using the item.

Equipment and containers

FieldDescription
equipSlot type it fits: backpack, vest, weapon_primary, weapon_secondary, or clothing_<key>.
container{ width, height, maxWeight, allow } gives the item its own grid, like a backpack. allow limits it to categories. A backpack cannot go inside another backpack.
armorArmour points of a vest. Wear is saved back into the item.
pedLook on the character when equipped: { male = { drawable, texture }, female = { drawable, texture } }. Used for backpacks (component 5) and vests (component 9) when Config.Gear.enabled is on. Set it to drawables that exist on your server.

Weapons

FieldDescription
weapon.ammoAmmo item used to reload.
weapon.clipMagazine size.
weapon.meleetrue for melee weapons (no ammo, no wear).
attachmentOn an attachment item: list of component names, or a table per weapon.
attachSlotMount point in the workshop: sight, muzzle, barrel, flashlight, grip, magazine or skin.

Weapons keep their ammo, serial number, attachments and durability in metadata.

Usable items

shared/items.lua
burger = {
    label = 'Burger',
    size = { 1, 1 },
    weight = 350,
    stack = 3,
    category = 'food',
    rarity = 'common',
    description = 'A double cheeseburger. Four big bites.',
    degrade = 2880,
    prop = `prop_cs_burger_01`,
    consume = 1,
    uses = 4,
    use = {
        duration = 2200,
        anim = { dict = 'mp_player_inteat@burger', clip = 'mp_player_int_eat_burger_fp' },
        prop = { model = `prop_cs_burger_01`, bone = 18905, pos = vec3(0.13, 0.05, 0.02), rot = vec3(-50.0, 16.0, 60.0) },
        status = { hunger = 12 },
    },
},
FieldDescription
use{ duration, anim, prop, status, heal }: a progress bar with animation and prop. status adds hunger/thirst (ESX status or QB metadata), heal adds health.
consumeUnits removed per use.
usesBites or sips per unit (2 to 100). Each use applies use.status once; the item is gone after the last one.
degradeMinutes until it spoils. Shows a freshness bar; spoiled items cannot be used.
usabletrue marks an item usable that has no use block (for example handled by RegisterUsableItem).

Usable items also work through RegisterUsableItem, ox client.export / server.export, ESX.RegisterUsableItem and QBCore CreateUseableItem.

Held items

hold controls how the item sits in the hand:

hold = { model = `prop_ld_flow_bottle`, bone = 28422, pos = vec3(0.0, 0.0, -0.02), rot = vec3(0.0, 0.0, 0.0), anim = false, carry = false },

hold = true uses the default prop, hold = false makes the item impossible to hold. carry = true uses the two-handed box carry. Without hold, the prop comes from Config.Hands.props, then use.prop, then prop, then a bag or box by item size.

Durability

Weapons and tools listed in Config.Durability wear out automatically. Override it per item:

durability = { shot = 0.2, use = 10, craft = 5 },

shot is percent per shot, use per use, craft per craft when the item is a recipe tool. See Features.

Salvage

salvage = { duration = 6000, results = { { name = 'scrap_metal', count = { 1, 4 } }, { name = 'cable', count = 1, chance = 50 } } },

Right click → Salvage takes the item apart. count can be a number or { min, max }; chance is a percent.