-
Notifications
You must be signed in to change notification settings - Fork 7
/
import.lua
189 lines (160 loc) · 5.26 KB
/
import.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
182
183
184
185
186
187
188
189
----------------------------------------------------------------
-- General Stuff
----------------------------------------------------------------
if not _VERSION:find('5.4') then
error("Enable Lua 5.4 in the fxmanifest.lua! (lua54 'yes')", 2)
end
local resourceName = GetCurrentResourceName()
local msk_core = 'msk_core'
if resourceName == msk_core then return end
if MSK and MSK.name == msk_core then
error(("Duplicate entires for '@%s/import.lua' detected! Please remove all duplicate entires in '%s/fxmanifest.lua'"):format(msk_core, resourceName))
end
if GetResourceState(msk_core) ~= 'started' then
error('^1msk_core must be started before this resource.^0', 0)
end
local context = IsDuplicityVersion() and 'server' or 'client'
----------------------------------------------------------------
-- Export for MSK Library
----------------------------------------------------------------
MSK = exports.msk_core:GetLib()
MSK.name = resourceName
----------------------------------------------------------------
-- Quick function access
----------------------------------------------------------------
-- MSK.Input(header, placeholder, field, cb)
setmetatable(MSK.Input, {
__call = function(self, ...)
self.Open(...)
end
})
-- MSK.Numpad(pin, showPin, cb)
setmetatable(MSK.Numpad, {
__call = function(self, ...)
self.Open(...)
end
})
-- MSK.Progress(data)
setmetatable(MSK.Progress, {
__call = function(self, ...)
self.Start(...)
end
})
-- MSK.Timeout(ms, cb, data)
setmetatable(MSK.Timeout, {
__call = function(self, ...)
return self.Set(...)
end
})
-- MSK.TextUI(key, text, color)
setmetatable(MSK.TextUI, {
__call = function(self, ...)
self.Show(...)
end
})
if context == 'client' then
-- MSK.Request(request, hasLoaded, assetType, asset, timeout, ...)
setmetatable(MSK.Request, {
__call = function(self, ...)
return self.Streaming(...)
end
})
end
if context == 'server' then
-- MSK.Check({auhtor = 'MSK-Scripts', name = 'msk_core', download? = 'url'})
setmetatable(MSK.Check, {
__call = function(self, ...)
self.Version(...)
end
})
end
----------------------------------------------------------------
-- MSK.Player
----------------------------------------------------------------
if context == 'client' then
setmetatable(MSK.Player, {
__index = function(self, key)
if key == 'coords' then
return GetEntityCoords(self.ped)
elseif key == 'heading' then
return GetEntityHeading(self.ped)
elseif key == 'state' then
return PlayerState(self.serverId).state
end
if tonumber(key) then
return MSK.Trigger('msk_core:player', key)
end
end,
__call = function(self, key, val, update)
local value = rawget(self, key)
if value == nil then
if type(val) == 'function' then
value = func()
else
value = val
end
rawset(self, key, value)
if update then
TriggerEvent('msk_core:invokingUpdate', key, value)
end
end
return value
end
})
AddEventHandler('msk_core:onPlayer', function(key, value, oldValue)
MSK.Player[key] = value
end)
elseif context == 'server' then
local metatable = {
__index = function(self, key)
if type(key) == "string" then
return rawget(self, tonumber(key))
end
end
}
setmetatable(MSK.Player, metatable)
local playerMeta = {
__index = function(self, key)
if key == 'coords' then
return GetEntityCoords(self.ped)
elseif key == 'heading' then
return GetEntityHeading(self.ped)
elseif key == 'state' then
return PlayerState(self.serverId).state
end
end
}
AddEventHandler('msk_core:OnPlayer', function(playerId, key, value, oldValue)
if not MSK.Player[playerId] then
MSK.Player[playerId] = {}
setmetatable(MSK.Player[playerId], playerMeta)
end
MSK.Player[playerId][key] = value
end)
for playerId, data in pairs(MSK.Player) do
if not getmetatable(MSK.Player[playerId]) then
setmetatable(MSK.Player[playerId], playerMeta)
end
end
end
----------------------------------------------------------------
-- Other stuff
----------------------------------------------------------------
if context == 'client' then
RegisterNetEvent('msk_core:playerLoaded', function()
MSK.Bridge.isPlayerLoaded = true
-- esx_multicharacter support
if MSK.Bridge.Framework.Type == 'ESX' and ESX then
ESX.PlayerLoaded = true
ESX.PlayerData = ESX.GetPlayerData()
end
end)
RegisterNetEvent('msk_core:playerLogout', function()
MSK.Bridge.isPlayerLoaded = false
-- esx_multicharacter support
if MSK.Bridge.Framework.Type == 'ESX' and ESX then
ESX.PlayerLoaded = false
ESX.PlayerData = {}
end
end)
end