From b014e43e14dca890f6b57526cb56e8d3c555155c Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Wed, 2 Aug 2023 16:16:37 +1000 Subject: [PATCH] feat(init): importing modules with resource metadata Allow loading modules through fxmanifest (i.e. ox_lib 'locale' or ox_libs { 'locale' }). Useful in some cases where the module needs to be loaded (lib.locale()) first. --- init.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 7a48b25..d72efda 100644 --- a/init.lua +++ b/init.lua @@ -149,7 +149,7 @@ end lua language server doesn't support generics when using @overload see https://github.com/LuaLS/lua-language-server/issues/723 this function stub allows the following to work - + local key = cache('key', function() return 'abc' end) -- fff: 'abc' local game = cache.game -- game: string ]] @@ -218,3 +218,13 @@ else TriggerClientEvent(notifyEvent, playerId, data) end end + +for i = 1, GetNumResourceMetadata(cache.resource, 'ox_lib') do + local name = GetResourceMetadata(cache.resource, 'ox_lib', i - 1) + + if not rawget(lib, name) then + local module = loadModule(lib, name) + + if type(module) == 'function' then pcall(module) end + end +end