---Loads a resource file provided the file path ---@param filePath string ---@param resourceName string|nil The resource to load the file from, uses CURRENT_RESOURCE if not spesified ---@return table local function loadFile(filePath, resourceName) local file = LoadResourceFile(resourceName or CURRENT_RESOURCE, filePath) local path = string.format('%s/%s', resourceName or CURRENT_RESOURCE, filePath) if not file then warn(string.format('No file was found with path %s', path)) return {} end local func, err = load(file, path) if not func or err then error(err, 0) end return func() end ---Checks if a export exist in the spesified resouce ---@param resource string ---@param export string ---@return boolean local function doesExportExist(resource, export) return pcall(function() return exports[resource][export] end) end ---Force loads init.lua from ox_lib local function forceIncludeOxLib() loadFile('init.lua', 'ox_lib') warn("ox_lib was force included by the script, please add it to the fxmanifest if you intend to use ox_lib with this script, otherwise configure the config file differently.") end local environment = IsDuplicityVersion() and 'server' or 'client' local EXPORTS = { QB = doesExportExist('qb-core', 'GetCoreObject'), ESX = doesExportExist('es_extended', 'getSharedObject') } local framework = Config.Framework if framework == 'auto' then if GetResourceState('ox_core') == 'started' then framework = 'ox' elseif EXPORTS.QB then framework = 'qb' elseif EXPORTS.ESX then framework = 'esx' elseif doesExportExist('ND_Core', 'GetCoreObject') then framework = 'nd' else framework = 'standalone' end end -- People are stupid and don't read instructions, so let's force include ox_lib if needed. if (framework == 'ox' or framework == 'nd') and not lib then forceIncludeOxLib() end loadFile(string.format('bridge/framework/%s/%s.lua', framework, environment)) ---@type string|boolean local dispatch = Config.Dispatch if dispatch then if dispatch == 'auto' or dispatch == true then if GetResourceState('ps-dispatch') == 'started' then dispatch = 'ps' elseif GetResourceState('ND_MDT') == 'started' then dispatch = 'nd' elseif GetResourceState('ox_mdt') == 'started' then dispatch = 'ox' elseif doesExportExist('core_dispatch', 'addCall') then dispatch = 'core' elseif GetResourceState('rcore_dispatch') == 'started' then dispatch = 'rcore' elseif doesExportExist('qs-dispatch', 'GetPlayerInfo') then dispatch = 'quasar' else dispatch = false -- Force disable to prevent server attempting to call on function Config.Dispatch = false end end if dispatch then loadFile(string.format('bridge/dispatch/%s/%s.lua', dispatch, environment)) end end local inventory = Config.Inventory if inventory == 'auto' then if doesExportExist('ox_inventory', 'Items') then inventory = 'ox' elseif EXPORTS.QB then inventory = 'qb' elseif EXPORTS.ESX then inventory = 'esx' else inventory = 'standalone' end end loadFile(string.format('bridge/inventory/%s/%s.lua', inventory, environment)) if environment == 'client' then local notification = Config.Notification ---@type string|boolean local helptext = Config.HelpText ---@type string|boolean local target = Config.Target if notification then if notification == 'auto' then if doesExportExist('ox_lib', 'notify') then notification = 'ox' elseif EXPORTS.QB then notification = 'qb' elseif EXPORTS.ESX then notification = 'esx' else notification = 'standalone' end end loadFile(string.format('bridge/notification/%s.lua', notification)) end if helptext then if helptext == 'auto' then if doesExportExist('ox_lib', 'showTextUI') then helptext = 'ox' elseif doesExportExist('qb-core', 'DrawText') then helptext = 'qb' elseif EXPORTS.ESX then helptext = 'esx' else helptext = 'standalone' end end -- People are stupid and don't read instructions, so let's force include ox_lib if needed. if helptext == 'ox' and not lib then forceIncludeOxLib() end loadFile(string.format('bridge/helptext/%s.lua', helptext)) end if target then if target == 'auto' or target == true then if doesExportExist('ox_target', 'addGlobalVehicle') then target = 'ox_target' elseif doesExportExist('qb-target', 'AddTargetBone') then target = 'qb-target' elseif doesExportExist('qtarget', 'AddTargetBone') then target = 'qtarget' elseif doesExportExist('bt-target', 'AddTargetModel') then target = 'bt-target' else target = false end end if target then loadFile(string.format('bridge/target/%s.lua', target)) end end end