AK47 QB Inventory
Kartik-Business integrates seamlessly with ak47_qb_inventory, allowing business items (food, ingredients, products, etc.) to be dynamically registered at runtime.
This custom QB inventory script has built-in support for Kartik-Business item registration, ensuring items are automatically added to the shared items table without additional modifications.
๐ฆ Requirements
Before proceeding, ensure the following dependencies are installed and running:
- ak47_qb_inventory
- qb-core
- oxmysql
- Kartik-Business
- kartik-laptop
๐ How the Integration Works
When Kartik-Business needs to register a new item:
- It triggers the server event handled by ak47_qb_inventory.
- The item is appended to
ak47_qb_inventory/shared/items.luafor persistence. - The internal
Config.Shared.Itemstable is updated for instant availability. - If an image URL is provided, it is downloaded and saved to
ak47_qb_inventory/web/images/.
This process ensures that items created through the business system are recognized immediately.
๐ Server Event: Insert Item
Kartik-Business uses the following event to register items:
TriggerServerEvent("kartik-business:inventory:insertItem", itemData)Item Data Format
{
name = "dirty_burger",
label = "Dirty Burger",
weight = 500,
consume = false,
degrade = 0,
stack = true,
close = true,
description = "A burger that looks a bit suspicious.",
image = "https://example.com/images/dirty_burger.png" -- Optional image URL
}๐ ๏ธ Built-in Integration
ak47_qb_inventory comes with pre-built support for Kartik-Business. The integration logic is already included in the script.
๐ Files Involved
ak47_qb_inventory/bridge/qb/server.lua- Contains the event handlerak47_qb_inventory/shared/items.lua- Where items are stored
๐ Implementation
The event handler is already present in bridge/qb/server.lua:
RegisterNetEvent("kartik-business:inventory:insertItem", function(item)
if not item or not item.name or not item.label then return end
local formatName = item.name:gsub("'", "\\'"):lower()
if Config.Shared.Items[formatName] then return end
local stack = true
local resource = GetCurrentResourceName()
local path = GetResourcePath(resource)
item.close = true
item.stack = stack
item.consume = false
item.degrade = 0
item.weight = item.weight or 1000
item.name = formatName
-- Load shared/items.lua
local file = { string.strtrim(LoadResourceFile(resource, 'shared/items.lua')) }
file[1] = file[1]:gsub('}$', '')
local itemFormat = [[
['%s'] = {
name = '%s',
label = '%s',
weight = %s,
consume = %s,
degrade = %s,
stack = %s,
close = %s,
description = %s
},
]]
local fileSize = #file
file[fileSize + 1] = itemFormat:format(
formatName,
formatName,
item.label:gsub("'", "\\'"),
item.weight,
item.consume,
item.degrade,
item.stack,
item.close,
item.description and ('"%s"'):format(item.description:gsub('"', '\\"')) or 'nil'
)
file[fileSize + 2] = '}'
SaveResourceFile(resource, 'shared/items.lua', table.concat(file), -1)
Config.Shared.Items[formatName] = item
if item.image then
PerformHttpRequest(item.image, function(code, data)
if code >= 200 and code < 300 then
local image = io.open(path .. '/web/images/' .. formatName .. '.png', "wb")
if image then
image:write(data)
image:flush()
image:close()
end
end
end)
end
end)โ ๏ธ Important Notes
- Persistence: Items are written to the physical
shared/items.luafile. - Instant Use: No server restart or resource restart is required.
- Image Location: Images are saved automatically to:
ak47_qb_inventory/web/images/ - Uniqueness: If an item with the same name already exists in
Config.Shared.Items, the insertion is skipped.
โ Integration Complete
With ak47_qb_inventory, Kartik-Business integration is ready out-of-the-box. New items created via the business app will be immediately available in the inventory and across the entire server.