The utils.fw module is designed to abstract framework-specific functionality across multiple popular frameworks, like QBCore, ESX, and others. This makes scripts compatible with different server setups out of the box. By centralizing the framework-specific logic in one place, it becomes easier to support multiple frameworks without scattering compatibility code throughout every script.
As more frameworks are supported, this module can be extended to include those as well, ensuring that no matter which framework a server runs, any scripts can integrate seamlessly
Initialization
Initializing the framework core is critical because it establishes a reliable reference (fw) that we can use throughout the scripts. Without initializing this core object, the scripts would be unable to access the framework's functions, player data, or other utilities.
Framework Detection: The script first checks which framework is active by querying the state of popular resources. Once the correct framework is identified, it sets a global variable (FRAMEWORK) to reference it.
Ensuring Correct Data Access: The rest of the bridge functions rely on this initial setup to determine which framework-specific methods to call. For example, getting player data in QBCore is different from doing so in ESX, so we need to know which framework we’re working with.
CreateThread(function()ifGetResourceState('boii_core') =='started' then FRAMEWORK ='boii_core'elseifGetResourceState('qb-core') =='started' then FRAMEWORK ='qb-core'elseifGetResourceState('es_extended') =='started' then FRAMEWORK ='es_extended'elseifGetResourceState('ox_core') =='started' then FRAMEWORK ='ox_core'endwhilenot FRAMEWORK doWait(500)endif FRAMEWORK =='boii_core' then fw = exports.boii_core:get_object()elseif FRAMEWORK =='qb-core' then fw = exports['qb-core']:GetCoreObject()elseif FRAMEWORK =='es_extended' then fw = exports['es_extended']:getSharedObject()elseif FRAMEWORK =='ox_core' thenlocal 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() fw = Oxelseif FRAMEWORK =='custom' then--- Custom framework initializationendreturnend)
Functions
ESX functionality is lacking, most of them could be improved. ESX is something that has not been used in house for quite some time, they will be improved on in due course.
OX Core functions were initially coded for the LUA base, these have not been tested with the new TS core, currently unsure if any of them still work, these will be updated in due course.
get_data()
Retrieves a players client side data based on active framework.
Function
localfunctionget_data(key)local player_dataif FRAMEWORK =='boii_core' then player_data = fw.get_data(key)elseif FRAMEWORK =='qb-core' then player_data = fw.Functions.GetPlayerData()elseif FRAMEWORK =='es_extended' then player_data = fw.GetPlayerData()elseif FRAMEWORK =='ox_core' then player_data = fw.GetPlayerData()elseif FRAMEWORK =='custom' then--- Custom framework logicendifnot player_data thenprint('No player data found in get_data()')endreturn player_dataendexports('fw_get_data', get_data)utils.fw.get_data = get_data
Example
--- Retreive the data.local data = utils.fw.get_data()--- Print data as json string.print('Data:', json.encode(data))
get_identity()
Retrieves players identity information.
Function
localfunctionget_identity()local player =get_data()ifnot player thenreturnfalseendlocal player_dataif FRAMEWORK =='boii_core' then player_data = { first_name = player.identity.first_name, last_name = player.identity.last_name, dob = player.identity.dob, sex = player.identity.sex, nationality = player.identity.nationality }elseif FRAMEWORK =='qb-core' then player_data = { first_name = player.charinfo.firstname, last_name = player.charinfo.lastname, dob = player.charinfo.birthdate, sex = player.charinfo.gender, nationality = player.charinfo.nationality }elseif FRAMEWORK =='es_extended' then player_data = { first_name = fw.GetPlayerData().firstName or'firstName missing', last_name = fw.GetPlayerData().lastName or'lastName missing', dob = fw.GetPlayerData().dateofbirth or'dateofbirth missing', sex = fw.GetPlayerData().sex or'sex missing', nationality ='LS, Los Santos' }elseif FRAMEWORK =='ox_core' then player_data = { first_name = player.firstName, last_name = player.lastName, dob = player.dob, sex = player.gender, nationality ='LS, Los Santos' }elseif FRAMEWORK =='custom' then--- Custom framework logicendreturn player_dataendexports('fw_get_identity', get_identity)utils.fw.get_identity = get_identity
--- Define jobs list.local job_list = { 'police', 'ems' }--- Toggle if on duty is required.local on_duty_only =true--- Check if player has one of the jobs and is on duty.utils.fw.player_has_job(job_list, on_duty_only, function(has_job)ifnot has_job thenprint('Player does not meet the job requirements.') returnendprint('Player has the required job and is on duty.')end)
--- Retreive and print inventory if found.utils.fw.get_inventory(function(inventory)ifnot inventory thenprint('Inventory not found.') returnendprint('Player inventory:', json.encode(inventory))end)
--- Define item.local item_id ='water'--- Check if player has item.utils.fw.get_item(item_id, function(item)ifnot item thenprint('Item not found.') returnendprint('Item found:', json.encode(item))end)
--- Define item.local item_id ='water'--- Define quantity.local required_quantity =5--- Check if player has required item and correct quantity.utils.fw.has_item(item_id, required_quantity, function(has_item)ifnot has_item thenprint('Player does not have enough of the required item.') returnendprint('Player has enough of the required item.')end)