ktoxktox docs

Customization

Framework hooks, icons, and localization for ktx_cases.

Customization

ktx_cases ships with ESX support out of the box. Adapt it to any framework by editing the files in custom/.

Server Hooks

custom/server.lua contains the framework integration functions.

registerUsableItem

Registers a case item with the framework. When the item is used in-game, the resource fires the case selector for caseType on the client.

function registerUsableItem(itemName, caseType)
    ESX.RegisterUsableItem(itemName, function(playerId)
        TriggerClientEvent('ktx_cases:openCaseSelector', playerId, caseType)
    end)
    return true
end
  • itemName - inventory item name to register as usable
  • caseType - the case ID from Cases to open when the item is used

playerExists

Checks if a player source is valid.

function playerExists(source)
    local xPlayer = ESX.GetPlayerFromId(source)
    return xPlayer ~= nil
end

getPlayerIdentifier

Returns the player's unique identifier.

function getPlayerIdentifier(source)
    local xPlayer = ESX.GetPlayerFromId(source)
    if not xPlayer then return nil end
    return xPlayer.getIdentifier()
end

getInventoryItemCount

Returns how many of a specific item the player has.

function getInventoryItemCount(source, itemName)
    local xPlayer = ESX.GetPlayerFromId(source)
    if not xPlayer then return 0 end
    local item = xPlayer.getInventoryItem(itemName)
    return item and item.count or 0
end

removeInventoryItem

Removes an item from the player's inventory.

function removeInventoryItem(source, itemName, amount)
    local xPlayer = ESX.GetPlayerFromId(source)
    if not xPlayer then return false end
    xPlayer.removeInventoryItem(itemName, amount)
    return true
end

addInventoryItem

Adds an item to the player's inventory.

function addInventoryItem(source, itemName, amount)
    local xPlayer = ESX.GetPlayerFromId(source)
    if not xPlayer then return false end
    xPlayer.addInventoryItem(itemName, amount)
    return true
end

giveReward

Handles giving each reward type. This is the main function to customize for your framework. The server passes the player's expected identifier alongside the source so the hook can validate that the player on the wire is still the original opener.

function giveReward(source, playerIdentifier, reward)
    local xPlayer = ESX.GetPlayerFromId(source)
    if not xPlayer then return false end
    if playerIdentifier and xPlayer.getIdentifier() ~= playerIdentifier then
        return false
    end

    if reward.type == "money" then
        xPlayer.addMoney(reward.amount)
    elseif reward.type == "item" then
        xPlayer.addInventoryItem(reward.item, reward.amount)
    elseif reward.type == "weapon" then
        xPlayer.addWeapon(reward.weapon, reward.ammo)
    elseif reward.type == "vehicle" then
        giveVehicle(xPlayer, reward.model)
    elseif reward.type == "coins" then
        -- requires sky_coinsystem
        exports['sky_coinsystem']:GiveCoins(source, reward.amount)
    end

    return true
end

For QBx/QB-Core, replace ESX player methods with their equivalents (Player.Functions.AddMoney, Player.Functions.AddItem, etc.).

Client Hooks

custom/client.lua exports a single notify function used for every case-related UI message.

function notify(message, type, title, duration)
    ESX.ShowNotification(message, type, duration, title)
end
  • message - notification text
  • type - "success", "error", "info", or any framework-supported string
  • title - optional title above the message
  • duration - display time in milliseconds

Localization

Translation files live in locales/. The resource ships with en.json and de.json.

To add a new language:

  1. Copy locales/en.json to locales/{code}.json (e.g. fr.json)
  2. Translate all string values
  3. Set "Locale": "fr" in static/config.json

Keys must stay the same. Only translate the values.

Icons

Case Icons

Place case icon images in custom/icons/cases/. Set the filename in the case's icon field in config. Falls back to default.png if missing.

Reward Icons

Place reward icon images in custom/icons/rewards/. Filenames are taken from each reward's icon field. If the field is empty or the file is missing, the resource falls back to the reward type icon: money.png, item.png, weapon.png, vehicle.png, or coins.png.