-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathclient.lua
320 lines (279 loc) · 8.84 KB
/
client.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
Citizen.CreateThread(function()
local JobName = ""
local GangName = ""
local loaded = false
local prompts = {}
local usagefuncs = {}
local defaultdata = {
name = "testprompt",
objecttext = "World",
actiontext = "Interact with something",
holdtime = 5000,
key = "E",
params = {},
usage = function(data)
print("Proximity prompt got used, the following params got passed: " .. json.encode(data))
end,
drawdist = 3,
usagedist = 1.5,
}
RegisterNUICallback("triggercallback", function(data, cb)
usagefuncs[data.name](prompts[data.name].params, GetSubFunctions(data.name))
cb("ok")
end)
RegisterNUICallback("loaded", function(_data, cb)
loaded = true
SendNUIMessage({ action = "loaded" })
cb("ok")
end)
function GetSubFunctions(name)
local subfuncs = {}
function subfuncs:Remove()
prompts[name] = nil
SendNUIMessage({ action = "removeprompt", name = name })
end
function subfuncs:Delete()
prompts[name] = nil
SendNUIMessage({ action = "removeprompt", name = name })
end
function subfuncs:Update(values)
for i, v in pairs(values) do
if i == "key" then
prompts[name][i] = string.upper(v)
elseif
i ~= "left"
and i ~= "top"
and i ~= "isbeingpressed"
and i ~= "holding"
and i ~= "visible"
and i ~= "timeheld"
then
prompts[name][i] = v
end
end
end
return subfuncs
end
function AddNewPrompt(data)
if data == nil then
data = defaultdata
end
for i, v in pairs(defaultdata) do
if data[i] == nil then
data[i] = v
end
end
data.timeheld = 0
data.visible = false
data.key = string.upper(data.key)
data.isbeingpressed = false
data.holding = false
data.left = 0
data.top = 0
if not data.offset or type(data.offset) ~= "vector3" then
data.offset = vector3(0.0, 0.0, 0.0)
end
if data.position then
data.position = vector3(data.position.x, data.position.y, data.position.z) + data.offset
end
if data.entity then
if DoesEntityExist(data.entity) == false then
print(
string.format(
'ZERIO-PROXIMITYPROMPT [WARN] - The entity with the value "%s" does not exist',
tostring(data.entity)
)
)
return
end
end
if Config.Keys[data.key] ~= nil then
if prompts[data.name] == nil then
prompts[data.name] = data
usagefuncs[data.name] = data.usage
local data2 = data
data2.usage = nil
if loaded then
SendNUIMessage({ action = "addnewprompt", data = data })
else
CreateThread(function()
while loaded == false do
Citizen.Wait(1000)
end
SendNUIMessage({ action = "addnewprompt", data = data })
end)
end
return GetSubFunctions(data.name)
else
usagefuncs[data.name] = data.usage
print(
string.format(
'ZERIO-PROXIMITYPROMPT [WARN] - There is already a proximity prompt with the id "%s"',
data.name
)
)
end
else
print(
string.format(
'ZERIO-PROXIMITYPROMPT [WARN] - The key "%s" doesn\'t exist. This warning is from the following prompt: "%s"',
data.key,
data.name
)
)
end
end
exports("AddNewPrompt", AddNewPrompt)
while loaded == false do
Citizen.Wait(100)
end
if GetResourceState("qb-core") ~= "missing" then
QBCore = exports["qb-core"]:GetCoreObject()
local PlayerData = QBCore.Functions.GetPlayerData()
if PlayerData and PlayerData.job then
JobName = PlayerData.job.name
SendNUIMessage({ action = "updatejob", job = PlayerData.job.name })
end
if PlayerData and PlayerData.gang then
GangName = PlayerData.gang.name
SendNUIMessage({ action = "updategang", gang = PlayerData.gang.name })
end
RegisterNetEvent("QBCore:Client:OnJobUpdate")
AddEventHandler("QBCore:Client:OnJobUpdate", function(JobInfo)
JobName = JobInfo.name
SendNUIMessage({ action = "updatejob", job = JobInfo.name })
end)
RegisterNetEvent("QBCore:Client:OnGangUpdate", function(GangInfo)
GangName = GangInfo.name
SendNUIMessage({ action = "updategang", gang = GangInfo.name })
end)
RegisterNetEvent("QBCore:Client:OnPlayerLoaded")
AddEventHandler("QBCore:Client:OnPlayerLoaded", function()
newData = QBCore.Functions.GetPlayerData()
JobName = newData.job.name
SendNUIMessage({ action = "updatejob", job = newData.job.name })
end)
end
if GetResourceState("es_extended") ~= "missing" then
if ESX == nil then
while ESX == nil do
TriggerEvent("esx:getSharedObject", function(obj)
ESX = obj
end)
Citizen.Wait(0)
end
end
local PlayerData = ESX.GetPlayerData()
if PlayerData and PlayerData.job then
JobName = PlayerData.job.name
SendNUIMessage({ action = "updatejob", job = PlayerData.job.name })
end
RegisterNetEvent("esx:setJob")
AddEventHandler("esx:setJob", function(Job)
JobName = Job.name
SendNUIMessage({ action = "updatejob", job = Job.name })
end)
RegisterNetEvent("esx:playerLoaded")
AddEventHandler("esx:playerLoaded", function(newData)
JobName = newData.job.name
SendNUIMessage({ action = "updatejob", job = newData.job.name })
end)
end
while true do
local ped = PlayerPedId()
if ped then
local plrpos = GetEntityCoords(ped)
local resx, resy = GetActiveScreenResolution()
local noneInRange, noneOnScreen, lowestdist = true, true, math.huge
for i, v in pairs(prompts) do
local v = prompts[i]
local position = v.position
if v.entity and not v.position then
position = GetOffsetFromEntityInWorldCoords(v.entity, v.offset.x, v.offset.y, v.offset.z)
end
local dist = #(plrpos - position)
if lowestdist > dist then
lowestdist = dist
end
prompts[i].visible = false
if dist < v.drawdist then
if v.canuse == nil or v.canuse() == true then
noneInRange = false
local onscreen, x, y = GetScreenCoordFromWorldCoord(position.x, position.y, position.z)
if onscreen and x and y then
noneOnScreen = false
if IsPauseMenuActive() == false then
prompts[i].left = (x * resx) * 0.75
prompts[i].top = y * resy
prompts[i].visible = true
prompts[i].scale = (1 / dist)
if prompts[i].scale > 1 then
prompts[i].scale = 1
end
if prompts[i].scale < 0.5 then
prompts[i].scale = 0.5
end
if
IsControlPressed(0, Config.Keys[v.key])
and prompts[i].isbeingpressed == false
and v.usagedist > dist
then
if
(prompts[i].job == nil or JobName == prompts[i].job)
and (prompts[i].gang == nil or GangName == prompts[i].gang)
then
if prompts[i] then
prompts[i].isbeingpressed = true
end
Citizen.CreateThread(function()
local key = Config.Keys[v.key]
SendNUIMessage({
action = "startholding",
idx = i,
})
while true do
if not IsControlPressed(0, key) then
if prompts[i] then
prompts[i].isbeingpressed = false
SendNUIMessage({
action = "stopholding",
idx = i,
})
end
return
end
Citizen.Wait(100)
end
end)
end
end
end
end
end
end
SendNUIMessage({
action = "updateprompt",
idx = i,
data = {
visible = prompts[i].visible,
top = prompts[i].top,
left = prompts[i].left,
scale = prompts[i].scale,
},
})
end
if noneOnScreen == false then
Citizen.Wait(Config.RefreshRate)
else
Citizen.Wait(100)
end
if noneInRange == true then
local time = lowestdist * 10
if time > 1000 then
time = 1000
end
Citizen.Wait(time)
end
end
end
end)