Kartik Scripts

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.lua for persistence.
  • The internal Config.Shared.Items table 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 handler
  • ak47_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.lua file.
  • 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.

On this page