-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathinit.lua
85 lines (67 loc) · 2.4 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
LGF = {}
LGF.Player = {}
function LGF:GetContext()
local SERVER_SIDE = IsDuplicityVersion()
local CLIENT_SIDE = not SERVER_SIDE
if SERVER_SIDE then
return "server"
elseif CLIENT_SIDE then
return "client"
else
error("Unable to determine path: Not running on either server or client side")
end
end
function LGF:LuaLoader(module_name, resource)
local resource_name = resource or GetInvokingResource()
local file_name = module_name .. ".lua"
local file_content = LoadResourceFile(resource_name, file_name)
if not file_content then
error(string.format("Error loading file '%s' from resource '%s': File does not exist or cannot be read.",
file_name, resource_name))
end
local func, compile_err = load(file_content, "@" .. file_name)
if not func then error(string.format("Error compiling module '%s': %s", module_name, compile_err), 2) end
local success, result = pcall(func)
if not success then error(string.format("Error executing module '%s': %s", module_name, result), 2) end
return result
end
-- require = function(module_name)
-- return LGF:LuaLoader(module_name)
-- end
local Framework = {
{ ResourceName = "LEGACYCORE", Object = "GetCoreData" },
{ ResourceName = "es_extended", Object = "getSharedObject" },
{ ResourceName = "qb-core", Object = "GetCoreObject" },
}
function LGF:GetFramework()
for I = 1, #Framework do
local DATA = Framework[I]
if GetResourceState(DATA.ResourceName):find("started") then
local success, frame = pcall(function()
return exports[DATA.ResourceName][DATA.Object]()
end)
if success then
return frame, DATA.ResourceName
else
LGF:logError("Failed to Get Object from %s, Result %s", DATA.ResourceName, frame)
end
end
end
end
if LGF:GetContext() == "client" then
function LGF.Player:Ped()
return PlayerPedId()
end
function LGF.Player:Index()
return GetPlayerServerId(NetworkGetPlayerIndexFromPed(self:Ped()))
end
function LGF.Player:PlayerId()
return PlayerId()
end
function LGF.Player:Coords()
return GetEntityCoords(self:Ped())
end
end
exports('UtilityData', function()
return _G.LGF
end)