Licences

CLIENT & SERVER SIDE

A standalone utility for managing licenses, such as driving or firearm licenses, independent of any framework. It provides functionality to fetch, update, and check license statuses both client and server-side.

Client Functions

get_licences

Gets all licence data for the player and logs response.

Function

local function get_licences()
    utils.callback.cb('boii_utils:sv:get_licences', {}, function(licences_data)
        if licences_data then
            debug_log('info', 'Licenses data fetched: '.. json.encode(licences_data))
        else
            debug_log('err', 'Failed to fetch licences data.')
        end
    end)
end

exports('get_licences', get_licences)
utils.licences.get_licences = get_licences

Example

--- Utils object
local player_licences = utils.licences.get_licences()

if player_licences then
    print('Licences:', json.encode(player_licences))
else
    print('No licences found.')
end

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

update_licence

Updates a specific licences status.

Function

local function update_licence(licence_id, test_type, passed)
    utils.callback.cb('boii_utils:sv:update_licence', { licence_id = licence_id, test_type = test_type, passed = passed }, function(response)
        if response.success then
            debug_log('info', 'License status updated successfully.')
        else
            debug_log('err', 'Failed to update licence status.')
        end
    end)
end

exports('update_licence', update_licence)
utils.licences.update = update_licence

Example

--- Define licence id
local licence_id = 'driving'
--- Specify test type
local test_type = 'practical'
--- Specify status
local passed = true

--- Utils object
utils.licences.update(licence_id, test_type, passed)

--- Direct export
exports.boii_utils:update_licence(licence_id, test_type, passed)

check_licence

Checks if a player has the required licence status.

Function

local function check_licence(licence_id, test_type, cb)
    utils.callback.cb('boii_utils:sv:check_licence_passed', {licence_id = licence_id, test_type = test_type}, function(response)
        if response.passed then
            cb(true)
        else
            cb(false)
        end
    end)
end

exports('check_licence', check_licence)
utils.licences.check_licence = check_licence

Example

--- Define licence id
local licence_id = 'driving'
--- Define test type
local test_type = 'theory'

--- Utils object
utils.licences.check_licence(licence_id, test_type, function(has_passed)
    if has_passed then
        print("Player has passed the theory test.")
    else
        print("Player has not passed the theory test.")
    end
end)

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

Server Functions

Last updated