JCKSDocs
JCKS BridgeV2Referencia

Default editable files

The complete default editable files of JCKS Bridge 2.0.0, to copy a function that is missing in your own file.

These are the editable files exactly as JCKS Bridge 2.0.0 ships them. Your own copies in editable/ are never replaced by an update. When the console says a function is missing, the default below runs instead of it. Copy the function into your file only if you want to change it.

The same files are in defaults/editable/ of the release. Files of other versions: changelog.

editable/client.lua

Function What it does
Editable.Custom.Notify Notification when the notify provider is Custom. The default shows a GTA feed message.
Editable.Custom.Progress Progress bar when the progress provider is Custom. Returns true when finished. The default only waits for the duration.
Editable.Custom.CancelProgress Cancels the running custom progress bar.
Editable.Custom.SkillCheck Skill check when the skill check provider is Custom. Returns true on success. The default always passes.
Editable.Custom.ShowTextUI Text prompt when the text UI provider is Custom. The default shows a GTA help text.
Editable.Custom.Status Receives a status name ('hunger', 'thirst', ...). Returns its value 0 - 100 when the bridge has none yet, or nil.
Editable.Custom.HideTextUI Hides the custom text prompt.
Editable.SetClipboard Copies text to the clipboard through jcks_lib.
Editable.OpenWardrobe Opens the wardrobe of the clothing system at job lockers. Returns false when there is none.
Editable.RestoreCivilian Puts the saved clothes back on after a uniform. Returns false when there is no clothing system.
Editable.SetFuel Sets the fuel level of a vehicle in the fuel system and in GTA.
Editable.GetFuel Returns the fuel level of a vehicle from the fuel system, or the GTA fuel level.
lua
Editable = Editable or {}

Editable.Custom = {}

function Editable.Custom.Notify(data)
    BeginTextCommandThefeedPost('STRING')
    AddTextComponentSubstringPlayerName(data.title and data.description and (data.title .. '~n~' .. data.description) or data.description or data.title or '')
    EndTextCommandThefeedPostTicker(false, true)
end

function Editable.Custom.Progress(opts)
    Wait(opts.duration or 3000)
    return true
end

function Editable.Custom.CancelProgress()
end

function Editable.Custom.SkillCheck()
    return true
end

function Editable.Custom.ShowTextUI(text)
    BeginTextCommandDisplayHelp('STRING')
    AddTextComponentSubstringPlayerName(text)
    EndTextCommandDisplayHelp(0, true, false, -1)
end

function Editable.Custom.Status(name)
    return nil
end

function Editable.Custom.HideTextUI()
    ClearAllHelpMessages()
end

function Editable.SetClipboard(text)
    if GetResourceState('jcks_lib') == 'started' then return exports.jcks_lib:SetClipboard(text) end
    return false
end

function Editable.OpenWardrobe()
    local system = Bridge.ClothingSystem
    if system == 'illenium-appearance' then
        TriggerEvent('illenium-appearance:client:openOutfitMenu')
    elseif system == 'fivem-appearance' then
        TriggerEvent('fivem-appearance:client:openWardrobe')
    elseif system == 'qb-clothing' then
        TriggerEvent('qb-clothing:client:openOutfitMenu')
    elseif system == 'esx_skin' then
        TriggerEvent('esx_skin:openSaveableMenu')
    else
        return false
    end
    return true
end

function Editable.RestoreCivilian()
    local system = Bridge.ClothingSystem
    if system == 'illenium-appearance' then
        ExecuteCommand('reloadskin')
    elseif system == 'qb-clothing' then
        TriggerServerEvent('qb-clothes:loadPlayerSkin')
    elseif system == 'esx_skin' and Bridge.Framework == 'esx' then
        local ESX = exports.es_extended:getSharedObject()
        ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin)
            TriggerEvent('skinchanger:loadSkin', skin)
        end)
    else
        return false
    end
    return true
end

function Editable.SetFuel(vehicle, fuel)
    local system = Bridge.FuelSystem
    fuel = fuel + 0.0
    if system == 'ox_fuel' then
        Entity(vehicle).state:set('fuel', fuel, true)
    elseif system ~= 'none' then
        pcall(function() exports[system]:SetFuel(vehicle, fuel) end)
    end
    SetVehicleFuelLevel(vehicle, fuel)
end

function Editable.GetFuel(vehicle)
    local system = Bridge.FuelSystem
    if system == 'ox_fuel' then
        local fuel = Entity(vehicle).state.fuel
        if fuel then return fuel + 0.0 end
    elseif system ~= 'none' then
        local ok, fuel = pcall(function() return exports[system]:GetFuel(vehicle) end)
        if ok and tonumber(fuel) then return tonumber(fuel) + 0.0 end
    end
    return GetVehicleFuelLevel(vehicle) + 0.0
end

editable/client_framework.lua

Function What it does
Editable.Framework.GetGender Returns 'male' or 'female' for the local character.
lua
--[[ CUSTOM FRAMEWORK ADAPTER (client)
    Client half of editable/server_framework.lua, used only when the framework is 'custom'.
    The job, grade and duty reach the client automatically: the server reads them through
    Editable.Framework.GetJob and publishes them in the player's state bag 'jcks:job'. JCKS scripts
    get jcks_bridge:client:playerLoaded, jcks_bridge:client:jobChanged and
    jcks_bridge:client:playerUnloaded from that, so nothing has to be wired here for jobs.
    Item counts come from the inventory adapter: ox_inventory or the other supported inventories,
    or editable/client_inventory.lua when the inventory is 'custom' or 'framework'.
    Set Resource to the same core resource name as on the server. ]]

Editable = Editable or {}

Editable.Framework = {}

Editable.Framework.Resource = 'openlife_core'  -- your core resource name

--[[ Returns 'male' or 'female' for the local character. Used for job outfits.
    The default reads it from your core and falls back to the ped model. ]]
function Editable.Framework.GetGender()
    local ok, data = pcall(function() return exports[Editable.Framework.Resource]:getPlayerData() end)
    local sex = ok and type(data) == 'table' and (data.sex or data.gender) or nil
    if sex == 'f' or sex == 'F' or sex == 'female' or sex == 1 then return 'female' end
    if sex == 'm' or sex == 'M' or sex == 'male' or sex == 0 then return 'male' end
    return GetEntityModel(PlayerPedId()) == joaat('mp_f_freemode_01') and 'female' or 'male'
end

editable/client_inventory.lua

Function What it does
Editable.Inventory.GetItemCount Receives an item name. Returns how many the local player has.
Editable.Inventory.OpenStash Called when the server side OpenStash sends 'stash' to this client (only if your server function does that).
Editable.Inventory.OpenPlayerInventory Called when the server side OpenPlayerInventory sends 'player' to this client (only if your server function does that).
lua
--[[ CUSTOM INVENTORY ADAPTER (client)
    Client half of editable/server_inventory.lua, used only when the inventory is 'custom'.
    Set Resource to the same inventory resource name as on the server. ]]

Editable = Editable or {}

Editable.Inventory = {}

Editable.Inventory.Resource = 'my_inventory'  -- your inventory resource name
Editable.Inventory.Images = ''                -- item image path with %s for the item name, e.g. 'nui://my_inventory/html/images/%s.png', empty for none

--[[ Receives an item name. Returns how many the local player has. Only used to show or hide prompts,
    the server checks the real count before anything happens. ]]
function Editable.Inventory.GetItemCount(item)
    return exports[Editable.Inventory.Resource]:getItemCount(item) or 0
end

--[[ Called when the server side OpenStash sends 'stash' to this client (only if your server
    function does that). Receives { id, label, slots, weight }. Opens the stash UI. ]]
function Editable.Inventory.OpenStash(data)
    exports[Editable.Inventory.Resource]:openStash(data.id, data.label, data.slots, data.weight)
end

--[[ Called when the server side OpenPlayerInventory sends 'player' to this client (only if your server
    function does that). Receives the target server id. Opens the search UI. ]]
function Editable.Inventory.OpenPlayerInventory(target)
    exports[Editable.Inventory.Resource]:openPlayerInventory(target)
end

editable/server.lua

Function What it does
Editable.GiveKeys Gives vehicle keys through the selected key system.
Editable.RemoveKeys Takes vehicle keys back through the selected key system.
Editable.Notify Sends a notification from the server to a player.
Editable.IsAdmin Receives the server id. Return true to give that player JCKS admin access on top of ACE and admin groups.
lua
Editable = Editable or {}

function Editable.GiveKeys(src, vehicle, plate, opts)
    return Veh.GiveKeys(src, vehicle, plate, opts)
end

function Editable.RemoveKeys(src, vehicle, plate, opts)
    return Veh.RemoveKeys(src, vehicle, plate, opts)
end

function Editable.Notify(src, data, resource)
    TriggerClientEvent('jcks_bridge:client:notify', src, data, resource)
end

function Editable.IsAdmin(src)
    return false
end

editable/server_framework.lua

Function What it does
Editable.Framework.GetIdentifier REQUIRED. Receives the server id. Returns a unique, never changing character id, or nil while no character is loaded.
Editable.Framework.GetName REQUIRED. Receives the server id. Returns the character name as one string.
Editable.Framework.GetJob REQUIRED. Receives the server id. Returns the current job as a table with name and grade, or nil while no character is loaded.
Editable.Framework.SetJob REQUIRED. Receives the server id, the job name, the grade number and onDuty (boolean or nil when the caller does not care).
Editable.Framework.SetDuty REQUIRED. Receives the server id and true (on duty) or false (off duty).
Editable.Framework.GetMoney REQUIRED. Receives the server id and a JCKS account name ('cash', 'bank', 'black').
Editable.Framework.AddMoney REQUIRED. Receives the server id, the account, a whole positive amount and a reason text.
Editable.Framework.RemoveMoney REQUIRED. Same arguments as AddMoney.
Editable.Framework.GetPlayers REQUIRED. Returns the server ids of every player with a loaded character, as a list { 1, 5, 12 }.
Editable.Framework.GetJobs OPTIONAL. Returns every job your core knows with its grades, so JCKS can import them and check SetJob targets.
Editable.Framework.SaveJob OPTIONAL. Receives a job created or changed in JCKS Jobs (def and grades) to write it to your core.
Editable.Framework.DeleteJob OPTIONAL. Receives a job name that was deleted in JCKS Jobs.
Editable.Framework.InGroup OPTIONAL. Receives the server id and a permission group name. Returns true when the player is in that group.
Editable.Framework.SetMetadata OPTIONAL. Receives the server id, a key and a value. Stores small character data.
Editable.Framework.SetStatus OPTIONAL. Receives the server id, a status name ('hunger', 'thirst', 'stress', 'drunk') and a value 0 - 100. Sets that need of the character.
Editable.Framework.RegisterUsableItem OPTIONAL. Receives an item name and a callback. Calls cb(source, item) when a player uses the item.
Editable.Framework.Listen OPTIONAL but strongly recommended. Hooks your core's events and calls signal.loaded, unloaded, job or duty.
Editable.Framework.GetOfflineJob Receives an identifier. Returns { name = 'police', grade = 2 } or nil.
Editable.Framework.SetJobOffline Receives an identifier, a job name and a grade. Saves it for an offline character. Returns true on success.
Editable.Framework.GetEmployees Receives a job name. Returns every character with that job as { { identifier, name, grade }, ... }.
Editable.Framework.SearchCharacters Receives a search text, a limit and an offset. Returns a list of { identifier, name, job, grade } and the total number of matches.
Editable.Framework.CharactersByLicense Receives a Rockstar license. Returns the characters of that player as { { identifier, name, job, grade }, ... }, at most 10.
Editable.Framework.GetCharacterName Receives an identifier. Returns the character name or nil.
Editable.Framework.MoveGrade Receives a job name and two grade numbers. Moves every offline character of that job from one grade to the other.
Editable.Framework.ResetOfflineJob Receives a job name. Sets every offline character of that job to the unemployed job (job deleted in JCKS Jobs).
Editable.Society.Ensure OPTIONAL. Receives a job name and label. Creates the account if it does not exist.
Editable.Society.GetMoney REQUIRED. Receives a job name. Returns the balance.
Editable.Society.AddMoney REQUIRED. Receives a job name, an amount and a reason. Returns true on success.
Editable.Society.RemoveMoney REQUIRED. Receives a job name, an amount and a reason. Returns true on success, false when refused.
lua
--[[ CUSTOM FRAMEWORK ADAPTER (server)
    Connects JCKS Bridge, and through it every JCKS script, to a framework that is not ESX, QBCore,
    Qbox, ox_core or jcks_core. Used only when the framework is set to 'custom' in /jcks (Environment)
    or Config.Framework = 'custom'. Auto detection never picks it.

    How it works
      JCKS calls the functions below. Each function talks to your core and returns plain values.
      The bridge validates everything that comes back, keeps its own security checks (money amounts,
      balance before removing money, item names and counts, job names and grades) and publishes the
      job to the player's client, so you never touch the client job cache yourself.

    What you change
      1. Editable.Framework.Resource: the name of your core resource.
      2. Editable.Framework.Style: 'exports' for a core with exports such as getPlayer, setJob, setDuty
         and money functions (the worked example below), 'object' for a core that hands out an
         ESX like shared object with GetPlayerFromId and xPlayer style methods.
      3. Every function marked REQUIRED. The example code shows the expected shape of your data,
         rename the exports to the ones your core documents.
      4. Editable.Framework.Listen: tell the bridge when a character loads, logs out, changes job or
         changes duty. Without it JCKS only notices changes it made itself.
      5. Editable.Framework.Database: table and column names for offline features (fire an offline
         employee, search characters). Set it to false if your core has no such table.

    Your core can also signal changes itself from any server script:
        exports.jcks_bridge:CustomPlayerLoaded(source)
        exports.jcks_bridge:CustomPlayerUnloaded(source)
        exports.jcks_bridge:CustomJobChanged(source)
        exports.jcks_bridge:CustomDutyChanged(source)
    or with server events (server side only, clients cannot trigger them):
        TriggerEvent('jcks_bridge:custom:playerLoaded', source)
        TriggerEvent('jcks_bridge:custom:playerUnloaded', source)
        TriggerEvent('jcks_bridge:custom:jobChanged', source)
        TriggerEvent('jcks_bridge:custom:dutyChanged', source)
    Each one makes the bridge read the job again through GetJob, so passing the new job is not needed.
    A player who leaves the server is unloaded automatically.

    At start the bridge prints which REQUIRED functions are missing and the first error of every
    function that fails. The same list is shown in /jcks Overview.

    The client side lives in editable/client_framework.lua. Set the same Resource there.
    Accounts used by JCKS: 'cash', 'bank', 'black' (dirty money). Map them in ACCOUNTS below.
    Society accounts (job money) are in Editable.Society at the end of this file and are used when
    the accounts system is set to 'custom' in /jcks (Integrations). ]]

Editable = Editable or {}

Editable.Framework = {}

Editable.Framework.Resource = 'openlife_core'   -- your core resource name, the bridge waits up to 30 s for it to start
Editable.Framework.Style = 'exports'            -- 'exports' (getPlayer, setJob, ...) or 'object' (ESX like shared object)
Editable.Framework.Vehicles = true              -- true stores owned vehicles in the JCKS table jcks_owned_vehicles, false turns owned vehicles off

--[[ Table and column names of the characters table, used by the offline functions further below.
    The bridge fills {table}, {identifier}, ... into the SQL and quotes them, so write plain names.
    Set the whole value to false when your core keeps no characters table. Offline features then
    only work for players who are online. ]]
Editable.Framework.Database = {
    table = 'players',          -- characters table
    identifier = 'identifier',  -- column with the same value GetIdentifier returns
    license = 'license',        -- column with the Rockstar license (license:xxxx or the bare hash), used to list a player's characters
    firstname = 'firstname',
    lastname = 'lastname',
    job = 'job',                -- column with the job name
    grade = 'job_grade',        -- column with the job grade number
}

local ACCOUNTS = { cash = 'cash', bank = 'bank', black = 'black_money', dirty = 'black_money' }

local function core()
    return exports[Editable.Framework.Resource]
end

local function shared()
    return core():getSharedObject()
end

local function getPlayer(src)
    if Editable.Framework.Style == 'object' then return shared().GetPlayerFromId(src) end
    return core():getPlayer(src)
end

--[[ REQUIRED. Receives the server id. Returns a string that is unique per character and never
    changes (citizen id, character id, state id). JCKS stores it for employees, vehicles and logs.
    Return nil while the player has no character loaded. ]]
function Editable.Framework.GetIdentifier(src)
    local p = getPlayer(src)
    if not p then return nil end
    return p.identifier or p.citizenid or p.charId
end

--[[ REQUIRED. Receives the server id. Returns the character name as one string, for example 'John Smith'. ]]
function Editable.Framework.GetName(src)
    local p = getPlayer(src)
    if not p then return nil end
    if Editable.Framework.Style == 'object' and p.getName then return p.getName() end
    if type(p.name) == 'string' then return p.name end
    return ((p.firstname or '') .. ' ' .. (p.lastname or '')):match('^%s*(.-)%s*$')
end

--[[ REQUIRED. Receives the server id. Returns the current job as a table:
        name        string, job name (required)
        label       string, shown in menus
        grade       number, 0 is the lowest grade (required)
        gradeName   string, optional
        gradeLabel  string, optional
        salary      number, optional
        onDuty      boolean, nil counts as on duty
        isBoss      boolean, optional
    Return nil while the player has no character loaded. ]]
function Editable.Framework.GetJob(src)
    local p = getPlayer(src)
    if not p or not p.job then return nil end
    local job = p.job
    return {
        name = job.name,
        label = job.label,
        grade = tonumber(type(job.grade) == 'table' and job.grade.level or job.grade) or 0,
        gradeName = job.grade_name or job.gradeName,
        gradeLabel = job.grade_label or job.gradeLabel,
        salary = tonumber(job.grade_salary or job.salary) or 0,
        onDuty = job.onDuty ~= false and job.onduty ~= false,
        isBoss = job.isBoss == true or job.isboss == true,
    }
end

--[[ REQUIRED. Receives the server id, the job name, the grade number and onDuty (boolean or nil
    when the caller does not care). Sets the job in your core. Returns true on success, false when
    the core refused. The bridge checks the job name and grade before calling this. ]]
function Editable.Framework.SetJob(src, jobName, grade, onDuty)
    if Editable.Framework.Style == 'object' then
        local p = getPlayer(src)
        if not p then return false end
        if type(onDuty) == 'boolean' then p.setJob(jobName, grade, onDuty) else p.setJob(jobName, grade) end
        return true
    end
    return core():setJob(src, jobName, grade, onDuty) ~= false
end

--[[ REQUIRED. Receives the server id and true (on duty) or false (off duty). Returns true on success.
    If your core has no duty, return true and JCKS keeps the duty state itself. ]]
function Editable.Framework.SetDuty(src, onDuty)
    if Editable.Framework.Style == 'object' then
        local p = getPlayer(src)
        if not p or not p.job then return false end
        p.setJob(p.job.name, p.job.grade, onDuty)
        return true
    end
    return core():setDuty(src, onDuty) ~= false
end

--[[ REQUIRED. Receives the server id and a JCKS account name ('cash', 'bank', 'black').
    Returns the balance as a number. ]]
function Editable.Framework.GetMoney(src, account)
    local name = ACCOUNTS[account] or account
    if Editable.Framework.Style == 'object' then
        local p = getPlayer(src)
        local acc = p and p.getAccount(name)
        return acc and acc.money or 0
    end
    return core():getMoney(src, name) or 0
end

--[[ REQUIRED. Receives the server id, the account, a whole positive amount and a reason text.
    Adds the money. Returns true on success. The bridge already checked the amount. ]]
function Editable.Framework.AddMoney(src, account, amount, reason)
    local name = ACCOUNTS[account] or account
    if Editable.Framework.Style == 'object' then
        local p = getPlayer(src)
        if not p then return false end
        p.addAccountMoney(name, amount, reason)
        return true
    end
    return core():addMoney(src, name, amount, reason) ~= false
end

--[[ REQUIRED. Same arguments as AddMoney. Removes the money and returns true, or returns false when
    the core refused. The bridge checks the balance with GetMoney before calling this. ]]
function Editable.Framework.RemoveMoney(src, account, amount, reason)
    local name = ACCOUNTS[account] or account
    if Editable.Framework.Style == 'object' then
        local p = getPlayer(src)
        if not p then return false end
        p.removeAccountMoney(name, amount, reason)
        return true
    end
    return core():removeMoney(src, name, amount, reason) ~= false
end

--[[ REQUIRED. Returns the server ids of every player with a loaded character, as a list { 1, 5, 12 }.
    A table keyed by server id { [1] = player, [5] = player } works too. ]]
function Editable.Framework.GetPlayers()
    if Editable.Framework.Style == 'object' then
        local list = {}
        for _, p in pairs(shared().GetExtendedPlayers()) do list[#list + 1] = p.source end
        return list
    end
    return core():getPlayers() or {}
end

--[[ OPTIONAL. Returns every job your core knows, so JCKS can import them and check SetJob targets:
        { { name = 'police', label = 'Police', whitelisted = true,
            grades = { { grade = 0, name = 'recruit', label = 'Recruit', salary = 50, isBoss = false }, ... } }, ... }
    A table keyed by job name and grades keyed by grade number also works. Return nil when your core
    has no job list; JCKS then lets the core decide in SetJob. Jobs created in JCKS Jobs are stored by the
    bridge in jcks_bridge_jobdefs either way. ]]
function Editable.Framework.GetJobs()
    if Editable.Framework.Style == 'object' then
        local jobs = shared().GetJobs and shared().GetJobs()
        if type(jobs) ~= 'table' then return nil end
        local list = {}
        for name, job in pairs(jobs) do
            local grades = {}
            for level, g in pairs(job.grades or {}) do
                grades[#grades + 1] = { grade = tonumber(g.grade or level) or 0, name = g.name, label = g.label, salary = tonumber(g.salary) or 0, isBoss = g.name == 'boss' }
            end
            list[#list + 1] = { name = name, label = job.label, whitelisted = job.whitelisted == true, grades = grades }
        end
        return list
    end
    local ok, jobs = pcall(function() return core():getJobs() end)
    return ok and jobs or nil
end

--[[ OPTIONAL. Receives a job created or changed in JCKS Jobs: def = { name, label, whitelisted } and
    grades = { { grade, name, label, salary, isBoss }, ... }. Write it to your core when it supports
    runtime jobs. Return true. When your core cannot add jobs, keep it as it is. ]]
function Editable.Framework.SaveJob(def, grades)
    return true
end

--[[ OPTIONAL. Receives a job name that was deleted in JCKS Jobs. Remove it from your core if it supports that. ]]
function Editable.Framework.DeleteJob(name)
    return true
end

--[[ OPTIONAL. Receives the server id and a permission group name ('admin', 'god', ...).
    Returns true when the player is in that group. /jcks admin access and permission rules use it.
    ACE groups (group.admin) are always checked as well. ]]
function Editable.Framework.InGroup(src, group)
    local p = getPlayer(src)
    if not p then return false end
    if Editable.Framework.Style == 'object' then return p.getGroup and p.getGroup() == group end
    return p.group == group
end

--[[ OPTIONAL. Receives the server id, a key and a value. Stores small character data JCKS asks for
    (for example a job uniform flag). The default keeps it in the player's state bag. ]]
function Editable.Framework.SetMetadata(src, key, value)
    if Player(src) then Player(src).state:set('jcks:meta:' .. key, value, true) end
end

--[[ OPTIONAL. Receives the server id, a status name ('hunger', 'thirst', 'stress', 'drunk') and a value 0 - 100.
    Sets that need of the character, for example when a medic heals or revives the player. Return false when your
    core has no such status. The default writes the player's state bag, which jcks_hud and most HUDs read. ]]
function Editable.Framework.SetStatus(src, name, value)
    if not Player(src) then return false end
    Player(src).state:set(name, value, true)
    return true
end

--[[ OPTIONAL. Receives an item name and a callback. When a player uses that item, call cb(source, item).
    With inventory 'custom' the bridge uses Editable.Inventory.RegisterUsableItem instead. ]]
function Editable.Framework.RegisterUsableItem(item, cb)
    if GetResourceState('ox_inventory') == 'started' then
        exports.ox_inventory:registerHook('usingItem', function(payload)
            cb(payload.source, item, type(payload.item) == 'table' and payload.item or nil)
            return false
        end, { itemFilter = { [item] = true } })
        return
    end
    if Editable.Framework.Style == 'object' then
        shared().RegisterUsableItem(item, function(source) cb(source, item) end)
        return
    end
    core():registerUsableItem(item, function(source) cb(source, item) end)
end

--[[ OPTIONAL but strongly recommended. Called once after your core started. Hook your core's own
    server events and call the matching signal with the server id:
        signal.loaded(src)     character loaded or switched
        signal.unloaded(src)   character logged out without leaving the server
        signal.job(src)        job or grade changed outside JCKS
        signal.duty(src)       duty changed outside JCKS
    The event names below are examples, use the ones your core triggers. ]]
function Editable.Framework.Listen(signal)
    if Editable.Framework.Style == 'object' then
        AddEventHandler('esx:playerLoaded', function(src) signal.loaded(src) end)
        AddEventHandler('esx:playerLogout', function(src) signal.unloaded(src) end)
        AddEventHandler('esx:setJob', function(src) signal.job(src) end)
        return
    end
    AddEventHandler('openlife:playerLoaded', function(src) signal.loaded(src) end)
    AddEventHandler('openlife:playerLogout', function(src) signal.unloaded(src) end)
    AddEventHandler('openlife:jobUpdated', function(src) signal.job(src) end)
    AddEventHandler('openlife:dutyUpdated', function(src) signal.duty(src) end)
end

--[[ OFFLINE FUNCTIONS. They run when the player is not online (boss menu fires an offline employee,
    admin searches a character). CustomCore.Sql(kind, sql, params) runs oxmysql with the names from
    Editable.Framework.Database filled in; kind is 'single', 'query', 'scalar' or 'update'.
    Write your own SQL here if your table looks different, always with ? placeholders. ]]

--[[ Receives an identifier. Returns { name = 'police', grade = 2 } or nil. ]]
function Editable.Framework.GetOfflineJob(identifier)
    local row = CustomCore.Sql('single', 'SELECT {job} AS job, {grade} AS grade FROM {table} WHERE {identifier} = ?', { identifier })
    return row and { name = row.job, grade = tonumber(row.grade) or 0 } or nil
end

--[[ Receives an identifier, a job name and a grade. Saves it for an offline character. Returns true on success. ]]
function Editable.Framework.SetJobOffline(identifier, jobName, grade)
    return (CustomCore.Sql('update', 'UPDATE {table} SET {job} = ?, {grade} = ? WHERE {identifier} = ?', { jobName, grade, identifier }) or 0) > 0
end

--[[ Receives a job name. Returns every character with that job, online or not:
    { { identifier = '...', name = 'John Smith', grade = 1 }, ... } ]]
function Editable.Framework.GetEmployees(jobName)
    local list = {}
    for _, r in ipairs(CustomCore.Sql('query', 'SELECT {identifier} AS id, {firstname} AS firstname, {lastname} AS lastname, {grade} AS grade FROM {table} WHERE {job} = ?', { jobName }) or {}) do
        list[#list + 1] = { identifier = r.id, name = ((r.firstname or '') .. ' ' .. (r.lastname or '')):match('^%s*(.-)%s*$'), grade = tonumber(r.grade) or 0 }
    end
    return list
end

--[[ Receives a search text, a limit and an offset. Returns two values: a list of
    { identifier, name, job, grade } and the total number of matches. ]]
function Editable.Framework.SearchCharacters(query, limit, offset)
    local like = Bridge.Like(query)
    local rows = CustomCore.Sql('query', [[SELECT {identifier} AS id, {firstname} AS firstname, {lastname} AS lastname, {job} AS job, {grade} AS grade FROM {table}
        WHERE CONCAT_WS(' ', {firstname}, {lastname}) LIKE ? OR {identifier} LIKE ? ORDER BY {lastname}, {firstname} LIMIT ? OFFSET ?]], { like, like, limit, offset }) or {}
    local total = CustomCore.Sql('scalar', 'SELECT COUNT(*) FROM {table} WHERE CONCAT_WS(\' \', {firstname}, {lastname}) LIKE ? OR {identifier} LIKE ?', { like, like }) or 0
    local list = {}
    for _, r in ipairs(rows) do
        list[#list + 1] = { identifier = r.id, name = ((r.firstname or '') .. ' ' .. (r.lastname or '')):match('^%s*(.-)%s*$'), job = r.job, grade = tonumber(r.grade) or 0 }
    end
    return list, total
end

--[[ Receives a Rockstar license ('license:abc...' or 'license2:abc...'). Returns the characters of
    that player as { { identifier, name, job, grade }, ... }, at most 10. ]]
function Editable.Framework.CharactersByLicense(license)
    local hash = type(license) == 'string' and license:match('^license2?:(%x+)$')
    if not hash then return {} end
    local rows = CustomCore.Sql('query', [[SELECT {identifier} AS id, {firstname} AS firstname, {lastname} AS lastname, {job} AS job, {grade} AS grade FROM {table}
        WHERE {license} = ? OR {license} = ? OR {license} = ? LIMIT 10]], { license, 'license:' .. hash, hash }) or {}
    local list = {}
    for _, r in ipairs(rows) do
        list[#list + 1] = { identifier = r.id, name = ((r.firstname or '') .. ' ' .. (r.lastname or '')):match('^%s*(.-)%s*$'), job = r.job, grade = tonumber(r.grade) or 0 }
    end
    return list
end

--[[ Receives an identifier. Returns the character name or nil. ]]
function Editable.Framework.GetCharacterName(identifier)
    local r = CustomCore.Sql('single', 'SELECT {firstname} AS firstname, {lastname} AS lastname FROM {table} WHERE {identifier} = ?', { identifier })
    return r and ((r.firstname or '') .. ' ' .. (r.lastname or '')):match('^%s*(.-)%s*$') or nil
end

--[[ Receives a job name and two grade numbers. Moves every offline character of that job from one grade
    to the other (used when a grade is deleted in JCKS Jobs). ]]
function Editable.Framework.MoveGrade(jobName, from, to)
    CustomCore.Sql('update', 'UPDATE {table} SET {grade} = ? WHERE {job} = ? AND {grade} = ?', { to, jobName, from })
end

--[[ Receives a job name. Sets every offline character of that job to the unemployed job (job deleted in JCKS Jobs). ]]
function Editable.Framework.ResetOfflineJob(jobName)
    CustomCore.Sql('update', 'UPDATE {table} SET {job} = ?, {grade} = 0 WHERE {job} = ?', { Config.Unemployed, jobName })
end

--[[ SOCIETY ACCOUNTS. Used only when the accounts system is 'custom' in /jcks (Integrations).
    job is the job name ('police'). Amounts are whole positive numbers already checked by the bridge,
    and the bridge checks the balance before RemoveMoney. ]]
Editable.Society = {}

--[[ OPTIONAL. Receives a job name and label. Creates the account if it does not exist. Returns true. ]]
function Editable.Society.Ensure(job, label)
    return true
end

--[[ REQUIRED. Receives a job name. Returns the balance as a number. ]]
function Editable.Society.GetMoney(job)
    return exports[Editable.Framework.Resource]:getSocietyMoney(job) or 0
end

--[[ REQUIRED. Receives a job name, an amount and a reason. Returns true on success. ]]
function Editable.Society.AddMoney(job, amount, reason)
    return exports[Editable.Framework.Resource]:addSocietyMoney(job, amount, reason) ~= false
end

--[[ REQUIRED. Receives a job name, an amount and a reason. Returns true on success, false when refused. ]]
function Editable.Society.RemoveMoney(job, amount, reason)
    return exports[Editable.Framework.Resource]:removeSocietyMoney(job, amount, reason) ~= false
end

editable/server_inventory.lua

Function What it does
Editable.Inventory.GetItemCount REQUIRED. Receives the server id and an item name. Returns how many the player has.
Editable.Inventory.CanCarry OPTIONAL. Receives the server id, an item name and a count. Returns true when the player has room.
Editable.Inventory.AddItem REQUIRED. Receives the server id, an item name, a count and a metadata table or nil. Returns true on success.
Editable.Inventory.RemoveItem REQUIRED. Same arguments as AddItem. Returns true on success.
Editable.Inventory.GetItemList REQUIRED. Returns every item your inventory knows: { water = { label = 'Water' }, ... }. Cached 5 minutes.
Editable.Inventory.GetItemsMetadata OPTIONAL. Receives the server id and an item name. Returns every slot of that item with its metadata.
Editable.Inventory.RemoveSlot OPTIONAL. Receives the server id, an item name and a slot number. Removes one item from that slot.
Editable.Inventory.RegisterStash OPTIONAL. Receives a stash id, label, slot count, max weight (grams), personal (true means one stash per character), allowed groups and coords.
Editable.Inventory.OpenStash OPTIONAL. Receives the server id, stash id, label, slots, weight and personal. Opens the stash for that player.
Editable.Inventory.OpenPlayerInventory OPTIONAL. Receives the server id of the officer and the server id of the target. Opens the target's inventory for searching.
Editable.Inventory.RegisterUsableItem OPTIONAL. Receives an item name and a callback. Calls cb(source, item) when a player uses the item.
lua
--[[ CUSTOM INVENTORY ADAPTER (server)
    Connects JCKS Bridge to an inventory the bridge does not support out of the box. Used only when the
    inventory is set to 'custom' in /jcks (Environment) or Config.Inventory = 'custom'. Auto detection
    never picks it. ox_inventory, qb-inventory, qs-inventory, tgiann, codem, ak47, core, ps and origen
    have built-in adapters, pick those instead.

    The bridge validates every call before it reaches these functions (item name, whole positive count,
    stash id) and keeps its own checks: RemoveItem is only called when GetItemCount shows enough items,
    AddItem only when CanCarry allows it, and every return value is checked for the right type.

    What you change
      1. Editable.Inventory.Resource: the name of your inventory resource.
      2. Every function marked REQUIRED. The example uses exports with obvious names, rename them to
         the ones your inventory documents.
      3. Editable.Inventory.Metadata: true when your inventory stores per item metadata (serial numbers,
         key plates). With false JCKS turns off features that need it, for example physical vehicle keys.

    At start the bridge prints which REQUIRED functions are missing and the first error of every
    function that fails. The same list is shown in /jcks Overview.
    The client side (item count for prompts, opening a stash from the client) is in
    editable/client_inventory.lua. ]]

Editable = Editable or {}

Editable.Inventory = {}

Editable.Inventory.Resource = 'my_inventory'  -- your inventory resource name
Editable.Inventory.Metadata = true            -- true if items carry metadata, false if not
Editable.Inventory.Images = ''                -- item image path with %s for the item name, e.g. 'nui://my_inventory/html/images/%s.png', empty for none

local function inv()
    return exports[Editable.Inventory.Resource]
end

--[[ REQUIRED. Receives the server id and an item name. Returns how many the player has, as a number. ]]
function Editable.Inventory.GetItemCount(src, item)
    return inv():getItemCount(src, item) or 0
end

--[[ OPTIONAL. Receives the server id, an item name and a count. Returns true when the player has room.
    Return true if your inventory has no weight or slot limit. ]]
function Editable.Inventory.CanCarry(src, item, count)
    return inv():canCarryItem(src, item, count) == true
end

--[[ REQUIRED. Receives the server id, an item name, a count and a metadata table or nil.
    Gives the items. Returns true on success. ]]
function Editable.Inventory.AddItem(src, item, count, metadata)
    return inv():addItem(src, item, count, metadata) == true
end

--[[ REQUIRED. Same arguments as AddItem. Takes the items. Returns true on success. When metadata is a
    table, take only items whose metadata matches it. ]]
function Editable.Inventory.RemoveItem(src, item, count, metadata)
    return inv():removeItem(src, item, count, metadata) == true
end

--[[ REQUIRED. Returns every item your inventory knows: { water = { label = 'Water' }, ... }.
    The bridge caches the result for 5 minutes. ]]
function Editable.Inventory.GetItemList()
    local list = {}
    for name, item in pairs(inv():getItems() or {}) do list[name] = { label = item.label or name } end
    return list
end

--[[ OPTIONAL. Receives the server id and an item name. Returns every stack or slot of that item with
    its metadata: { { slot = 3, metadata = { plate = 'ABC123' } }, ... }. Only used when Metadata is true. ]]
function Editable.Inventory.GetItemsMetadata(src, item)
    local list = {}
    for _, slot in pairs(inv():getSlotsWithItem(src, item) or {}) do
        list[#list + 1] = { slot = slot.slot, metadata = slot.metadata or slot.info or {} }
    end
    return list
end

--[[ OPTIONAL. Receives the server id, an item name and a slot number. Removes one item from exactly that
    slot. Returns true on success. The bridge checks first that the slot holds that item when
    GetItemsMetadata is available. ]]
function Editable.Inventory.RemoveSlot(src, item, slot)
    return inv():removeItem(src, item, 1, nil, slot) == true
end

--[[ OPTIONAL. Receives a stash id, label, slot count, max weight (grams), personal (true means one stash
    per character), allowed groups and coords. Registers the stash at start. Return true, or false when
    your inventory has no stashes (job lockers and storages then stay closed). ]]
function Editable.Inventory.RegisterStash(id, label, slots, weight, personal, groups, coords)
    inv():registerStash(id, label, slots, weight, personal, groups, coords)
    return true
end

--[[ OPTIONAL. Receives the server id, stash id, label, slots, weight and personal. Opens the stash for
    that player. Personal stashes should use a per character id, for example id .. '_' .. identifier;
    CustomInventory.Identifier(src) returns the character identifier.
    If your inventory only opens stashes from the client, call
        TriggerClientEvent('jcks_bridge:client:inventory', src, 'stash', { id = id, label = label, slots = slots, weight = weight })
    and handle it in Editable.Inventory.OpenStash in editable/client_inventory.lua. Return true. ]]
function Editable.Inventory.OpenStash(src, id, label, slots, weight, personal)
    local stashId = personal and (id .. '_' .. (CustomInventory.Identifier(src) or src)) or id
    inv():openStash(src, stashId, label, slots, weight)
    return true
end

--[[ OPTIONAL. Receives the server id of the officer and the server id of the target. Opens the target's
    inventory for searching. Return true, or false when not supported. ]]
function Editable.Inventory.OpenPlayerInventory(src, target)
    inv():openPlayerInventory(src, target)
    return true
end

--[[ OPTIONAL. Receives an item name and a callback. When a player uses the item, call cb(source, item). ]]
function Editable.Inventory.RegisterUsableItem(item, cb)
    inv():registerUsableItem(item, function(source) cb(source, item) end)
end