-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
init.lua
157 lines (146 loc) · 4.58 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
if not lib then return end
local DEFAULT_FRAMEWORK = 'qb'
Framework = setmetatable({}, {
__newindex = function(self, name, fn)
exports(name, function() return fn end)
rawset(self, name, fn)
end
})
local function format(str)
if not string.find(str, "'") then return str end
return str:gsub("'", "")
end
Config = {
frameworks = {
ox = true,
esx = true,
qb = true,
nd = true,
ps = true,
qs = true
},
convars = {
core = format(GetConvar('bl:framework', DEFAULT_FRAMEWORK)),
inventory = format(GetConvar('bl:inventory', DEFAULT_FRAMEWORK)),
context = format(GetConvar('bl:context', DEFAULT_FRAMEWORK)),
target = format(GetConvar('bl:target', DEFAULT_FRAMEWORK)),
progressbar = format(GetConvar('bl:progressbar', DEFAULT_FRAMEWORK)),
radial = format(GetConvar('bl:radial', DEFAULT_FRAMEWORK)),
notify = format(GetConvar('bl:notify', DEFAULT_FRAMEWORK)),
textui = format(GetConvar('bl:textui', DEFAULT_FRAMEWORK)),
},
resources = {
inventory = {
ox = 'ox_inventory',
qb = 'qb-inventory',
ps = 'ps-inventory',
qs = 'qs-inventory'
},
core = {
nd = 'ND_Core',
qb = 'qb-core',
esx = 'es_extended'
},
context = {
qb = 'qb-menu',
ox = 'none'
},
progressbar = {
qb = 'progressbar',
ox = 'none'
},
radial = {
qb = 'qb-radialmenu',
ox = 'none'
},
target = {
qb = 'qb-target',
ox = 'ox_target',
},
notify = {
qb = 'none',
ox = 'none',
esx = 'none',
},
textui = {
ox = 'none',
qb = 'none',
}
},
client = {
dir = 'client',
moduleNames = {
"core",
"context",
"target",
"radial",
"notify",
"inventory",
"progressbar",
'textui',
},
all = {
inventory = true
},
},
server = {
dir = 'server',
moduleNames = {
"inventory",
"core",
"notify",
},
alternative = {
inventory = {
ps = 'qb'
}
},
}
}
exports('getFramework', function(module)
local moduleConfig = Config.resources[module]
if not moduleConfig then return end
return moduleConfig[Config.convars[module]]
end)
local function loadModule(dir, moduleName, framework)
local fomartedModule = ("%s.%s.%s"):format(dir, moduleName, framework)
local success, module = pcall(require, fomartedModule)
if type(module) ~= "string" or not string.find(module, 'not found') then
if success then
Framework[moduleName] = module
print(("[%s] Loaded module %s"):format(framework, moduleName))
else
error(("Error loading module %s: %s"):format(moduleName, module))
end
end
end
local modulesConfig = Config[lib.context]
if lib.context == 'server' then
local UUID = require'utils'.UUID
lib.callback.register('UUID', function(_, num)
return UUID(num)
end)
end
for _, moduleName in ipairs(modulesConfig.moduleNames) do
local framework = Config.convars[moduleName]
if Config.frameworks[framework] then
local hasAlternative = modulesConfig.alternative and modulesConfig.alternative[moduleName]
local moduleForAll = modulesConfig.all and modulesConfig.all[moduleName] and 'all' or framework
local alternative = hasAlternative and hasAlternative[moduleForAll] or moduleForAll
local resourceName = Config.resources[moduleName] and Config.resources[moduleName][framework]
if not resourceName then
return error('there is no '..framework.. ' on module '..moduleName.. '!, please make sure you configured your convars on cfg!')
elseif resourceName == 'none' or GetResourceState(resourceName) == 'started' then
loadModule(modulesConfig.dir, moduleName, alternative)
else
ExecuteCommand('ensure '..resourceName)
if lib.waitFor(function()
if GetResourceState(resourceName) == 'started' then
return true
end
end, ('resource %s is not starting'):format(resourceName), 2000) then
loadModule(modulesConfig.dir, moduleName, alternative)
end
end
end
end