This repository has been archived by the owner on Oct 20, 2024. It is now read-only.
generated from supv-cfx/sublime_core-fivem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobj.lua
181 lines (153 loc) · 5.12 KB
/
obj.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
local sl_core <const> = 'sublime_core'
local IsDuplicityVersion <const> = IsDuplicityVersion
local LoadResourceFile <const> = LoadResourceFile
local GetResourceState <const> = GetResourceState
local GetGameName <const> = GetGameName
local GetCurrentResourceName <const>, AddEventHandler <const> = GetCurrentResourceName, AddEventHandler
local export = exports[sl_core]
local service <const>, joaat <const> = (IsDuplicityVersion() and 'server') or 'client', joaat
local function FormatEvent(self, name, from)
return ("__sl__:%s:%s"):format(from or service, joaat(name))
end
if not _VERSION:find('5.4') then
error("^1 Vous devez activer Lua 5.4 dans la resources où vous utilisez l'import, (lua54 'yes') dans votre fxmanifest!^0", 2)
end
if not GetResourceState(sl_core):find('start') then
error('^1sublime_core doit être lancé avant cette ressource!^0', 2)
end
local function load_module(self, index)
local func, err
local dir <const> = ('imports/%s'):format(index)
local chunk <const> = LoadResourceFile(sl_core, ('%s/%s.lua'):format(dir, service))
local shared <const> = LoadResourceFile(sl_core, ('%s/shared.lua'):format(dir))
if chunk or shared then
if shared then
func, err = load(shared, ('@@%s/%s/%s'):format(sl_core, index, 'shared'))
else
func, err = load(chunk, ('@@%s/%s/%s'):format(sl_core, index, service))
end
if err then error(("Erreur pendant le chargement du module\n- Provenant de : %s\n- Modules : %s\n- Service : %s\n - Erreur : %s"):format(dir, index, service, err), 3) end
local result = func()
rawset(self, index, result)
return self[index]
end
end
local function call_module(self, index, ...)
local module = rawget(self, index)
if not module then
module = load_module(self, index)
if not module then
local function method(...)
return export[index](nil, ...)
end
if not ... then
self[index] = method
end
return method
end
end
return module
end
sl = setmetatable({
name = sl_core,
service = service,
game = GetGameName(),
env = GetCurrentResourceName(),
lang = GetConvar('sl:locale', 'fr'),
cache = service == 'client' and {},
await = Citizen.Await,
hashEvent = FormatEvent,
onCache = service == 'client' and function(key, cb)
AddEventHandler(FormatEvent(nil, ('cache:%s'):format(key)), cb)
end
},
{
__index = call_module,
__call = call_module
})
if sl.service == 'client' then
setmetatable(sl.cache, {
__index = function(self, key)
AddEventHandler(FormatEvent(('cache:%s'):format(key)), function(value)
self[key] = value
return self[key]
end)
rawset(self, key, export:getCache(key) or false)
return self[key]
end
})
--setmetatable(sl.config, {
-- __index = function(self, key)
-- local value = rawget(self, key)
-- if not value then
-- value = export:getConfig(key)
-- rawset(self, key, value)
-- end
-- return value
-- end
--})
elseif sl.service == 'server' then
--setmetatable(sl.config, {
-- __index = function(self, key)
-- local value = rawget(self, key)
-- if not value then
-- value = export:getConfig(key)
-- rawset(self, key, value)
-- end
-- return value
-- end
--})
MySQL = setmetatable({}, {
__index = function(self, key)
local value = rawget(self, key)
if not value then
sl.mysql.init()
value = MySQL[key]
end
return value
end
})
end
if lib then return end
-- credit: ox_lib <https://github.com/overextended/ox_lib/blob/master/init.lua>
local intervals = {}
---@param callback function | number
---@param interval? number
---@param ... any
function SetInterval(callback, interval, ...)
interval = interval or 0
if type(interval) ~= 'number' then
return error(('Interval must be a number. Received %s'):format(json.encode(interval --[[@as unknown]])))
end
local cbType = type(callback)
if cbType == 'number' and intervals[callback] then
intervals[callback] = interval or 0
return
end
if cbType ~= 'function' then
return error(('Callback must be a function. Received %s'):format(cbType))
end
local args, id = { ... }
Citizen.CreateThreadNow(function(ref)
id = ref
intervals[id] = interval or 0
repeat
interval = intervals[id]
Wait(interval)
callback(table.unpack(args))
until interval < 0
intervals[id] = nil
end)
return id
end
---@param id number
function ClearInterval(id)
if type(id) ~= 'number' then
return error(('Interval id must be a number. Received %s'):format(json.encode(id --[[@as unknown]])))
end
if not intervals[id] then
return error(('No interval exists with id %s'):format(id))
end
intervals[id] = -1
end
require = sl.require.load