diff --git a/init.lua b/init.lua index 30cbbc5dd0..6e4f2b039e 100644 --- a/init.lua +++ b/init.lua @@ -137,23 +137,6 @@ local function spamError(err) error(err, 0) end -CreateThread(function() - if shared.framework == 'ox' then - local file = ('imports/%s.lua'):format(lib.context) - local import = LoadResourceFile('ox_core', file) - local func, err = load(import, ('@@ox_core/%s'):format(file)) - - if not func or err then - shared.ready = false - return spamError(err) - end - - func() - - Ox = Ox or {} - end -end) - ---@param name string ---@return table ---@deprecated diff --git a/modules/bridge/client.lua b/modules/bridge/client.lua index 15b9bd5f6c..5ddae91454 100644 --- a/modules/bridge/client.lua +++ b/modules/bridge/client.lua @@ -58,19 +58,16 @@ function client.onLogout() Weapon.Disarm() end -local scriptPath = ('modules/bridge/%s/client.lua'):format(shared.framework) -local resourceFile = LoadResourceFile(cache.resource, scriptPath) - -if not resourceFile then - lib = nil - return error(("Unable to find framework bridge for '%s'"):format(shared.framework)) +if shared.framework == 'ox' then + CreateThread(function() + lib.load(('@ox_core.imports.%s'):format(lib.context)) + end) end -local func, err = load(resourceFile, ('@@%s/%s'):format(cache.resource, scriptPath)) +local success, result = pcall(lib.load, ('modules.bridge.%s.client'):format(shared.framework)) -if not func or err then - lib = nil - return error(err) +if not success then + lib.print.error(result) + lib = nil + return end - -func(client.onLogout) diff --git a/modules/bridge/esx/client.lua b/modules/bridge/esx/client.lua index f430c47d77..3417d343fc 100644 --- a/modules/bridge/esx/client.lua +++ b/modules/bridge/esx/client.lua @@ -1,5 +1,3 @@ -local onLogout = ... - local ESX = setmetatable({}, { __index = function(self, index) local obj = exports.es_extended:getSharedObject() @@ -22,7 +20,7 @@ function client.setPlayerStatus(values) end end -RegisterNetEvent('esx:onPlayerLogout', onLogout) +RegisterNetEvent('esx:onPlayerLogout', client.onLogout) AddEventHandler('esx:setPlayerData', function(key, value) if not PlayerData.loaded or GetInvokingResource() ~= 'es_extended' then return end diff --git a/modules/bridge/esx/server.lua b/modules/bridge/esx/server.lua index 10749a7a58..16fc142bb4 100644 --- a/modules/bridge/esx/server.lua +++ b/modules/bridge/esx/server.lua @@ -1,8 +1,7 @@ -local playerDropped = ... local Inventory = require 'modules.inventory.server' local Items = require 'modules.items.server' -AddEventHandler('esx:playerDropped', playerDropped) +AddEventHandler('esx:playerDropped', server.playerDropped) AddEventHandler('esx:setJob', function(source, job, lastJob) local inventory = Inventory(source) diff --git a/modules/bridge/nd/client.lua b/modules/bridge/nd/client.lua index 3577f64ccf..79c17f779a 100644 --- a/modules/bridge/nd/client.lua +++ b/modules/bridge/nd/client.lua @@ -1,8 +1,8 @@ -local onLogout = ... -local file = LoadResourceFile("ND_Core", "init.lua") -load(file, "@ND_Core/init.lua")() +local NDCore = lib.load('@ND_Core.init') -RegisterNetEvent("ND:characterUnloaded", onLogout) +if lib.checkDependency('ND_Core', '2.0.0', true) then return end + +RegisterNetEvent("ND:characterUnloaded", client.onLogout) local function reorderGroups(groups) groups = groups or {} diff --git a/modules/bridge/nd/server.lua b/modules/bridge/nd/server.lua index 53758ba9ed..530fa4218a 100644 --- a/modules/bridge/nd/server.lua +++ b/modules/bridge/nd/server.lua @@ -1,12 +1,11 @@ -local playerDropped = ... -local Inventory = require 'modules.inventory.server' -local file = LoadResourceFile("ND_Core", "init.lua") -load(file, "@ND_Core/init.lua")() - -AddEventHandler("ND:characterUnloaded", playerDropped) +local NDCore = lib.load('@ND_Core.init') if lib.checkDependency('ND_Core', '2.0.0', true) then return end +AddEventHandler("ND:characterUnloaded", server.playerDropped) + +local Inventory = require 'modules.inventory.server' + local function reorderGroups(groups) groups = groups or {} for group, info in pairs(groups) do diff --git a/modules/bridge/ox/client.lua b/modules/bridge/ox/client.lua index 80251984c4..5934478cd2 100644 --- a/modules/bridge/ox/client.lua +++ b/modules/bridge/ox/client.lua @@ -1,6 +1,4 @@ -local onLogout = ... - -RegisterNetEvent('ox:playerLogout', onLogout) +RegisterNetEvent('ox:playerLogout', client.onLogout) RegisterNetEvent('ox:setGroup', function(name, grade) PlayerData.groups[name] = grade diff --git a/modules/bridge/ox/server.lua b/modules/bridge/ox/server.lua index 78a17eae10..4ece4dfc8f 100644 --- a/modules/bridge/ox/server.lua +++ b/modules/bridge/ox/server.lua @@ -1,7 +1,6 @@ -local playerDropped = ... local Inventory = require 'modules.inventory.server' -AddEventHandler('ox:playerLogout', playerDropped) +AddEventHandler('ox:playerLogout', server.playerDropped) AddEventHandler('ox:setGroup', function(source, name, grade) local inventory = Inventory(source) diff --git a/modules/bridge/qb/client.lua b/modules/bridge/qb/client.lua index c7b2d3a7a8..1571543bc0 100644 --- a/modules/bridge/qb/client.lua +++ b/modules/bridge/qb/client.lua @@ -1,9 +1,8 @@ -local onLogout, Weapon = ... local QBCore = exports['qb-core']:GetCoreObject() local Inventory = require 'modules.inventory.client' local Weapon = require 'modules.weapon.client' -RegisterNetEvent('QBCore:Client:OnPlayerUnload', onLogout) +RegisterNetEvent('QBCore:Client:OnPlayerUnload', client.onLogout) RegisterNetEvent('QBCore:Player:SetPlayerData', function(data) if source == '' or not PlayerData.loaded then return end diff --git a/modules/bridge/qb/server.lua b/modules/bridge/qb/server.lua index f977b385b1..fb7f6a2ee6 100644 --- a/modules/bridge/qb/server.lua +++ b/modules/bridge/qb/server.lua @@ -1,10 +1,9 @@ -local playerDropped = ... local Inventory = require 'modules.inventory.server' local Items = require 'modules.items.server' local QBCore -AddEventHandler('QBCore:Server:OnPlayerUnload', playerDropped) +AddEventHandler('QBCore:Server:OnPlayerUnload', server.playerDropped) AddEventHandler('QBCore:Server:OnJobUpdate', function(source, job) local inventory = Inventory(source) diff --git a/modules/bridge/server.lua b/modules/bridge/server.lua index be90eadf14..2c68e84eef 100644 --- a/modules/bridge/server.lua +++ b/modules/bridge/server.lua @@ -39,7 +39,7 @@ end local Inventory = require 'modules.inventory.server' -local function playerDropped(source) +function server.playerDropped(source) local inv = Inventory(source) --[[@as OxInventory]] if inv?.player then @@ -48,25 +48,12 @@ local function playerDropped(source) end end -AddEventHandler('playerDropped', function() - playerDropped(source) -end) +local success, result = pcall(lib.load, ('modules.bridge.%s.server'):format(shared.framework)) -local scriptPath = ('modules/bridge/%s/server.lua'):format(shared.framework) -local resourceFile = LoadResourceFile(cache.resource, scriptPath) - -if not resourceFile then - lib = nil - return error(("Unable to find framework bridge for '%s'"):format(shared.framework)) +if not success then + lib.print.error(result) + lib = nil + return end -local func, err = load(resourceFile, ('@@%s/%s'):format(cache.resource, scriptPath)) - -if not func or err then - lib = nil - return error(err) -end - -func(playerDropped) - if server.convertInventory then exports('ConvertItems', server.convertInventory) end diff --git a/modules/inventory/server.lua b/modules/inventory/server.lua index af5ae3d96d..53e33259cf 100644 --- a/modules/inventory/server.lua +++ b/modules/inventory/server.lua @@ -2309,6 +2309,8 @@ function Inventory.SaveInventories(lock, clearInventories) end AddEventHandler('playerDropped', function() + server.playerDropped(source) + if GetNumPlayerIndices() == 0 then Inventory.SaveInventories(false, true) end