Frameworks

CLIENT & SERVER

The Framework Bridge abstracts framework-specific logic into a common, easy-to-use API, allowing seamless interaction with multiple frameworks such as boii_core, qb-core, es_extended, and ox_core.

By consolidating functionality into a single bridge, developers can write framework-independent code, improving maintainability and scalability.

Addtional default support will be added for other frameworks as time progresses. If your framework is not currently covered and you would like it to be, reach out through discord.

Handlers

Table of handlers for different frameworks. Covered by default: boii_core, ox_core, qb-core, es_extended

Client

local handlers = {
    boii_core = {
        init = function() return exports.boii_core:get() end,
        get_data = function(fw, key) return fw.get_data(key) end,
        get_identity = function(player)
            return {
                first_name = player.identity.first_name,
                last_name = player.identity.last_name,
                dob = player.identity.dob,
                sex = player.identity.sex,
                nationality = player.identity.nationality
            }
        end,
        get_player_id = function(player) return player.passport end
    },
    ['qb-core'] = {
        init = function() return exports['qb-core']:GetCoreObject() end,
        get_data = function(fw) return fw.Functions.GetPlayerData() end,
        get_identity = function(player)
            return {
                first_name = player.charinfo.firstname,
                last_name = player.charinfo.lastname,
                dob = player.charinfo.birthdate,
                sex = player.charinfo.gender,
                nationality = player.charinfo.nationality
            }
        end,
        get_player_id = function(player) return player.citizenid end
    },
    es_extended = {
        init = function() return exports['es_extended']:getSharedObject() end,
        get_data = function(fw) return fw.GetPlayerData() end,
        get_identity = function(player)
            return {
                first_name = player.firstName or 'firstName missing',
                last_name = player.lastName or 'lastName missing',
                dob = player.dateofbirth or 'dateofbirth missing',
                sex = player.sex or 'sex missing',
                nationality = 'LS, Los Santos'
            }
        end,
        get_player_id = function(player) return player.identifier end
    },
    ox_core = {
        init = function()
            local file = ('imports/%s.lua'):format(IsDuplicityVersion() and 'server' or 'client')
            local import = LoadResourceFile('ox_core', file)
            local chunk = assert(load(import, ('@@ox_core/%s'):format(file)))
            chunk()
            return Ox
        end,
        get_data = function(fw) return fw.GetPlayerData() end,
        get_identity = function(player)
            return {
                first_name = player.firstName,
                last_name = player.lastName,
                dob = player.dob,
                sex = player.gender,
                nationality = 'LS, Los Santos'
            }
        end,
        get_player_id = function(player) return player.stateId end
    }
    --- Add other frameworks here
}

Server

Client Functions

get_data

Retrieve the players data from the active framework.

Function

local function get_data(key)
    return call_function('get_data', key)
end

exports('get_data', get_data)
utils.fw.get_data = get_data

Example

--- Utils object
local data = utils.fw.get_data()

print('Data:', json.encode(data))

--- Direct export
exports.boii_utils:get_data()

get_identity

Retrieves players identity information.

Function

local function get_identity()
    local player = get_data()
    if not player then return false end
    return call_function('get_identity', player)
end

exports('get_identity', get_identity)
utils.fw.get_identity = get_identity

Example

--- Utils object
local identity = utils.fw.get_identity()

print('Identity:', json.encode(identity))

--- Direct export
exports.boii_utils:get_identity()

get_player_id

Retrieve players unique ID: citizenid, stateId, passport, identifier etc.

Function

local function get_player_id()
    local player = get_data()
    if not player then return false end
    return call_function('get_player_id', player)
end

exports('get_player_id', get_player_id)
utils.fw.get_player_id = get_player_id

Example

--- Utils object
local unique_id = utils.fw.get_player_id()

print('Unique ID:', json.encode(unique_id))

--- Direct export
exports.boii_utils:get_player_id()

player_has_job

Checks if player has a job by performing a server callback.

Function

local function player_has_job(jobs, on_duty, cb)
    utils.callback.cb('boii_utils:sv:player_has_job', { jobs = jobs, on_duty = on_duty }, cb)
end

exports('player_has_job', player_has_job)
utils.fw.player_has_job = player_has_job

Example

--- Job names to check
local jobs = { 'police', 'fib' }

--- If true will only return true if player is on duty.
--- If false will return true regardless of duty status
local on_duty = true 

--- Utils object
utils.fw.player_has_job(job, on_duty, function(has_job)
    if has_job then
        --- Do something
    else
        --- Do something else
    end
end)

--- Direct export
exports.boii_utils:player_has_job(...)

get_player_job_grade

Get the players grade in a specified job by performing a server callback.

Function

local function get_player_job_grade(job, cb)
    utils.callback.cb('boii_utils:sv:get_player_job_grade', { job = job }, cb)
end

exports('get_player_job_grade', get_player_job_grade)
utils.fw.get_player_job_grade = get_player_job_grade

Example

--- Define job name
local job = 'police'

--- Utils object
utils.fw.get_player_job_grade(job, function(grade)
    print('Players Grade:', grade)
end)

--- Direct export
exports.boii_utils:get_player_job_grade(...)

get_inventory

Retrieve the players inventory.

Function

local function get_inventory(cb)
    utils.callback.cb('boii_utils:sv:get_inventory', {}, cb)
end

exports('get_inventory', get_inventory)
utils.fw.get_inventory = get_inventory

Example

--- Utils object
utils.fw.get_inventory(function(inventory)
    if inventory then
        print('Inventory:', json.encode(inventory))
    else
        print('Failed to retrieve inventory.')
    end
end)


--- Direct export
exports.boii_utils:get_inventory(...)

get_item

Retrieve a specific item from players inventory.

Function

local function get_item(item, cb)
    utils.callback.cb('boii_utils:sv:get_item', { item_name = tostring(item) }, cb)
end

exports('get_item', get_item)
utils.fw.get_item = get_item

Example

--- Define item name
local item_name = 'weapon_pistol'

--- Utils object
utils.fw.get_item(item_name, function(item)
    if item then
        print('Player has the item:', json.encode(item))
    else
        print('Item not found in inventory.')
    end
end)

--- Direct export
exports.boii_utils:get_item(...)

has_item

Check if player has required item and quantity.

Function

local function has_item(item, amount, cb)
    utils.callback.cb('boii_utils:sv:has_item', { item_name = tostring(item), item_amount = tonumber(amount) or 1 }, cb)
end

exports('has_item', has_item)
utils.fw.has_item = has_item

Example

--- Define item name
local item_name = 'lockpick'
--- Define required quantity *(optional will default to 1)*
local quantity = 3

--- Utils object
utils.fw.has_item(item_name, quantity, function(has_item)
    if has_item then
        print('Player has the required item and quantity.')
    else
        print('Player does not have the required item or quantity.')
    end
end)

--- Direct export
exports.boii_utils:has_item(...)

Guides

Initial Setup

Framework detection is done automatically on load, however if you run a server with a dual core you may run into some issues. If you are using one of the pre-defined frameworks then you should not need to do anything for the bridge to work.

If your desired framework is not covered by default reach out through discord.

Adding Handlers

To add support for additional frameworks you need to add a handler into the handlers table inside .../bridges/frameworks.lua

Client

local handlers = {
    ['your framework core resource name'] = {
        init = function()
            --[[your frameworks function equivalent]]
        end,
        get_data = function(fw) return --[[your frameworks function equivalent]] end,
        get_identity = function(player)
            return {
                --[[your frameworks data equivalent]]
            }
        end,
        get_player_id = function(player) return --[[your frameworks uid]] end
        --- Any additional framework functions can be added below.
    }
}

Once you have added your handler, update the provided the ['your framework core resource name'] matches your core resource folder you should be good to go.

If for any reason you are unable to set this up yourself put a support post in discord.

Last updated