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
enditemName- inventory item name to register as usablecaseType- the case ID fromCasesto 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
endgetPlayerIdentifier
Returns the player's unique identifier.
function getPlayerIdentifier(source)
local xPlayer = ESX.GetPlayerFromId(source)
if not xPlayer then return nil end
return xPlayer.getIdentifier()
endgetInventoryItemCount
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
endremoveInventoryItem
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
endaddInventoryItem
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
endgiveReward
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
endFor 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)
endmessage- notification texttype-"success","error","info", or any framework-supported stringtitle- optional title above the messageduration- display time in milliseconds
Localization
Translation files live in locales/. The resource ships with en.json and de.json.
To add a new language:
- Copy
locales/en.jsontolocales/{code}.json(e.g.fr.json) - Translate all string values
- Set
"Locale": "fr"instatic/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.