Koja Scripts

Events and hooks

Server and client events fired by koja-inventory-v2 and the ox-style hooks (swapItems, openInventory, usingItem, createItem) with their payloads.

Events and hooks

Server events

EventArgumentsWhen
koja-inventory-v2:itemsReadynoneThe inventory finished starting. Register runtime items and slots here.
koja-inventory-v2:usedItemsource, name, itemId, metadataAn item was used.
koja-inventory-v2:slotChangedsource, key, item | nilAn equipment slot changed (built-in or custom).
koja-inventory-v2:statusAppliedsource, statusA usable item applied hunger/thirst status.
koja-inventory-v2:settingsChangedpathsAn admin saved settings in the panel.
ox_inventory:usedItemsource, name, itemId, metadataSame as usedItem, for ox scripts.
ox_inventory:openedInventorysource, inventoryNameA player opened a second inventory.
ox_inventory:closedInventorysource, inventoryNameA player closed it.
AddEventHandler('koja-inventory-v2:usedItem', function(source, name, itemId, metadata)
    if name == 'phone' then TriggerClientEvent('my_phone:open', source) end
end)

Client events

EventArgumentsWhen
koja-inventory-v2:client:slotChangedkey, item | nilOne of your equipment slots changed.
koja-inventory-v2:client:settingsChangedpathsSettings changed in the admin panel.
ox_inventory:currentWeaponweapon | nilA weapon was drawn or holstered.

Hooks

Hooks let your script inspect an action and block it by returning false. Register them with RegisterHook (or ox registerHook), remove them with RemoveHooks.

local hookId = exports['koja-inventory-v2']:RegisterHook('swapItems', function(payload)
    if payload.toType == 'player' and payload.fromSlot.name == 'evidence_bag' then
        return false
    end
end, {
    itemFilter = { evidence_bag = true },
    inventoryFilter = { '^police_' },
})
OptionDescription
itemFilter{ [itemName] = true }. The hook only runs for these items.
inventoryFilterPatterns (Lua string.match) or exact names. The hook only runs when one of the involved inventories matches.
HookPayloadNotes
swapItemssource, action, fromInventory, toInventory, fromType, toType, fromSlot, countRuns when an item moves between two different inventories. action is 'move', 'throw' and similar; fromSlot is the item in ox format.
openInventorysource, inventoryId, inventoryTypeRuns when a player opens a stash.
usingItemsource, item, inventoryId, slot, consumeRuns before an item is used.
createIteminventoryId, item, count, metadataRuns when an item is added through the ox AddItem. Return a table to replace the metadata.

Returning anything other than false lets the action continue. Errors in a hook are ignored.