From 6b8698353b4d42b2cddb6617afc660242b4463cf Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Wed, 7 May 2025 13:55:12 +0100 Subject: [PATCH] Expand on the core file loading system This is still not in use for now, but it WILL be used in the future I'm getting too many support tickets about the "Failed to load" warning in console about files they don't have/need (if you don't run `ox_core` don't worry about `ox_core` not loading) This system is intended to load it through the script instead of `fxmanifest.lua` It is intended to check if the user has the required script and also warn them if it's not started (load order issue), or just load it as if it were told to in the fxmanifest --- shared/_loaders.lua | 2 +- starter.lua | 68 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/shared/_loaders.lua b/shared/_loaders.lua index 04c6987..d206396 100644 --- a/shared/_loaders.lua +++ b/shared/_loaders.lua @@ -99,7 +99,7 @@ end --- end, true) --- ``` function onResourceStart(func, thisScript) - debugPrint("^6Bridge^7: Registering ^3onResourceStart^7()") + debugPrint("^6Bridge^7: ^2Registering ^3onResourceStart^7()") AddEventHandler('onResourceStart', function(resourceName) if getScript() == resourceName and (thisScript or true) then func() diff --git a/starter.lua b/starter.lua index 351be73..b0b2af9 100644 --- a/starter.lua +++ b/starter.lua @@ -58,23 +58,73 @@ if Config and Config.System then end -- Testing loading the core files here instead of in fxmanifests --- Forcefully loads the files and quietly, compared to fxmanifest complaining if they don't exist --- This may be better button would require more refinement maybe +-- Forcefully loads the files and quietly, compared to fxmanifest complaining if they don't exist when you don't need them all + --[[ +-- Shared framework file loader for k, v in pairs({ -- This is a specific load order [Exports.OXLibExport] = "init.lua", [Exports.OXCoreExport] = "lib/init.lua", [Exports.ESXExport] = "imports.lua", [Exports.QBXExport] = "modules/playerdata.lua", }) do - if GetResourceState(k) == "started" then - print("^5Loading^7: '"..k.."/"..v.."' ^2into ^7'"..GetCurrentResourceName().."' ...") - local fileLoader = assert(load(LoadResourceFile(k, (v)), ('@@'..k..'/'..v))) - fileLoader() - print("^2Success^7: ^2loaded ^1Core ^2file^7: ^3"..k.."^7/^3"..(v):gsub("/", "^7/^3"):gsub("%.lua", "^7.lua").."^7") - else + local state = GetResourceState(k) + -- if the resource is started, load the file + if state == "started" then + if type(v) == "string" then + v = { v } + end + for _, file in pairs(v) do + --print("^5CoreLoader^7: '"..k.."/"..file.."' ^2into ^7'"..GetCurrentResourceName().."' ...") + local fileLoader = assert(load(LoadResourceFile(k, (file)), ('@@'..k..'/'..file))) + fileLoader() + print("^5CoreLoader^7: ^2loaded ^1Core ^2file^7: ^3"..k.."^7/^3"..(file):gsub("/", "^7/^3"):gsub("%.lua", "^7.lua").."^7") + end + end + + -- if script is in server, but not started warn the user + if state == "uninitialized" or state == "stopped" then + print("^5CoreLoader^7: ^3"..k.." ^1 found but it wasn't started^7. ^1Check your ^3server^7.^3cfg ^1load order^7") + end + + -- debugging only, if the script is missing, warn the user + if state == "missing" then if debugMode then - print("^3Warning^7: ^3"..k.." ^2not found^7, ^2skipping") + print("^5CoreLoader^7: ^3"..k.." ^2not found^7, ^2skipping") + end + end +end + +-- Client only file loader +if not IsDuplicityVersion() then + for k, v in pairs({ -- This is a specific load order + ["PolyZone"] = { "client.lua", "BoxZone.lua", "EntityZone.lua", "CircleZone.lua", "ComboZone.lua" }, + ["warmenu"] = { "warmenu.lua", }, + }) do + local state = GetResourceState(k) + -- if the resource is started, load the file + if state == "started" then + if type(v) == "string" then + v = { v } + end + for _, file in pairs(v) do + --print("^5CoreLoader^7: '"..k.."/"..file.."' ^2into ^7'"..GetCurrentResourceName().."' ...") + local fileLoader = assert(load(LoadResourceFile(k, (file)), ('@@'..k..'/'..file))) + fileLoader() + print("^5CoreLoader^7: ^2loaded ^1Core ^2file^7: ^3"..k.."^7/^3"..(file):gsub("/", "^7/^3"):gsub("%.lua", "^7.lua").."^7") + end + end + + -- if script is in server, but not started warn the user + if state == "uninitialized" or state == "stopped" then + print("^5CoreLoader^7: ^3"..k.." ^1 found but it wasn't started^7. ^1Check your ^3server^7.^3cfg ^1load order^7") + end + + -- debugging only, if the script is missing, warn the user + if state == "missing" then + if debugMode then + print("^3Warning^7: ^3"..k.." ^2not found^7, ^2skipping") + end end end end