-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathclient.lua
More file actions
399 lines (320 loc) · 11.4 KB
/
client.lua
File metadata and controls
399 lines (320 loc) · 11.4 KB
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
----------------------------------------------------------------------------------------------------
-- Variables
----------------------------------------------------------------------------------------------------
local _ESX = nil;
local _XPlayer = nil;
local _OwnPlayerData = nil;
local _DependenciesLoaded = false;
local _Impound = Config.Impound
local _GuiEnabled = false
local _VehicleAndOwner = nil;
local _ImpoundedVehicles = nil;
----------------------------------------------------------------------------------------------------
-- Setup & Initialization
----------------------------------------------------------------------------------------------------
Citizen.CreateThread(function ()
while _ESX == nil do
TriggerEvent("esx:getSharedObject", function(obj) _ESX = obj end)
Citizen.Wait(10)
end
while _ESX.GetPlayerData().job == nil do
Citizen.Wait(10)
end
_DependenciesLoaded = true;
_XPlayer = _ESX.GetPlayerData()
end)
function ActivateBlips()
local blip = AddBlipForCoord(_Impound.RetrieveLocation.X, _Impound.RetrieveLocation.Y, _Impound.RetrieveLocation.Z)
SetBlipScale(blip, 1.25)
SetBlipDisplay(blip, 4)
SetBlipSprite(blip, 430)
SetBlipColour(blip, 3)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString("Police Impound")
EndTextCommandSetBlipName(blip)
end
ActivateBlips()
----------------------------------------------------------------------------------------------------
-- Helper functions
----------------------------------------------------------------------------------------------------
function ShowHelpNotification(text)
ClearAllHelpMessages();
SetTextComponentFormat("STRING");
AddTextComponentString(text);
DisplayHelpTextFromStringLabel(0, false, true, 5000);
end
RegisterNetEvent('HRP:ESX:SetCharacter')
AddEventHandler('HRP:ESX:SetCharacter', function (playerData)
_OwnPlayerData = playerData
end)
RegisterNetEvent('HRP:ESX:SetVehicleAndOwner')
AddEventHandler('HRP:ESX:SetVehicleAndOwner', function (vehicleAndOwner)
_VehicleAndOwner = vehicleAndOwner;
end)
RegisterNetEvent('HRP:Impound:SetImpoundedVehicles')
AddEventHandler('HRP:Impound:SetImpoundedVehicles', function (impoundedVehicles)
_ImpoundedVehicles = impoundedVehicles;
end)
RegisterNetEvent('HRP:Impound:VehicleUnimpounded')
AddEventHandler('HRP:Impound:VehicleUnimpounded', function (data, index)
local spawnLocationIndex = index % 3 + 1
local localVehicle = json.decode(data.vehicle)
print(localVehicle.health);
_ESX.Game.SpawnVehicle(localVehicle.model, _Impound.SpawnLocations[spawnLocationIndex],
_Impound.SpawnLocations[spawnLocationIndex].h, function (spawnedVehicle)
_ESX.Game.SetVehicleProperties(spawnedVehicle, localVehicle)
SetVehicleEngineHealth(spawnedVehicle, localVehicle.engineHealth);
SetVehicleBodyHealth(spawnedVehicle, localVehicle.bodyHealth);
SetVehicleFuelLevel(spawnedVehicle, localVehicle.fuelLevel);
SetVehiclePetrolTankHealth(spawnedVehicle, localVehicle.petrolTankHealth);
SetVehicleOilLevel(spawnedVehicle, localVehicle.oilLevel);
SetVehicleDirtLevel(spawnedVehicle, localVehicle.dirtLevel);
for windowIndex = 1, 13, 1 do
Citizen.Trace("Smashing window! ")
if(localVehicle.windows[windowIndex] == false) then
SmashVehicleWindow(spawnedVehicle, windowIndex);
end
end
for tyreIndex = 1, 7, 1 do
Citizen.Trace("Pooppiiiin! ")
if(localVehicle.tyresburst[tyreIndex] ~= false) then
SetVehicleTyreBurst(spawnedVehicle, tyreIndex, true, 1000);
end
end
end)
_ESX.ShowNotification("Your vehicle with the plate: " .. data.plate .. " has been unimpounded!")
SetNewWaypoint(_Impound.SpawnLocations[spawnLocationIndex].x, _Impound.SpawnLocations[spawnLocationIndex].y)
end)
RegisterNetEvent('HRP:Impound:CannotUnimpound')
AddEventHandler('HRP:Impound:CannotUnimpound', function ()
_ESX.ShowNotification("Your vehicle cannot be unimpounded at this moment, do you have enough cash?");
end)
----------------------------------------------------------------------------------------------------
-- NUI bs
----------------------------------------------------------------------------------------------------
function ShowImpoundMenu (action)
local pos = GetEntityCoords(GetPlayerPed(PlayerId()))
local vehicle = GetClosestVehicle(pos.x, pos.y, pos.z, 5.0, 0, 71)
if (IsPedInAnyVehicle(GetPlayerPed(PlayerId()))) then
_ESX.ShowNotification("Leave the vehicle first")
return
end
if (vehicle ~= nil) then
local v = _ESX.Game.GetVehicleProperties(vehicle)
local data = {}
TriggerServerEvent('HRP:ESX:GetCharacter', _XPlayer.identifier)
TriggerServerEvent('HRP:ESX:GetVehicleAndOwner', v.plate)
Citizen.Wait(500);
if(Config.NoPlateColumn == true) then
Citizen.Wait(Config.WaitTime);
end
if(_VehicleAndOwner == nil) then
_ESX.ShowNotification('Unknown vehicle owner, cannot impound');
return
end
data.action = "open"
data.form = "impound"
data.rules = Config.Rules
data.vehicle = {
plate = _VehicleAndOwner.plate,
owner = _VehicleAndOwner.firstname .. ' ' .. _VehicleAndOwner.lastname
}
if (_XPlayer.job.name == 'police') then
data.officer = _OwnPlayerData.firstname .. ' ' .. _OwnPlayerData.lastname;
_GuiEnabled = true
SetNuiFocus(true, true)
SendNuiMessage(json.encode(data))
end
if (_XPlayer.job.name == 'mecano') then
data.mechanic = _OwnPlayerData.firstname .. ' ' .. _OwnPlayerData.lastname;
_GuiEnabled = true
SetNuiFocus(true, true)
SendNuiMessage(json.encode(data))
end
else
_ESX.ShowNotification('No vehicle nearby');
end
end
function ShowAdminTerminal ()
_XPlayer = _ESX.GetPlayerData()
_GuiEnabled = true
TriggerServerEvent('HRP:Impound:GetVehicles')
Citizen.Wait(500)
SetNuiFocus(true, true)
local data = {
action = "open",
form = "admin",
user = _OwnPlayerData,
job = _XPlayer.job,
vehicles = _ImpoundedVehicles
}
SendNuiMessage(json.encode(data))
end
function DisableImpoundMenu ()
_GuiEnabled = false
SetNuiFocus(false)
SendNuiMessage("{\"action\": \"close\", \"form\": \"none\"}")
_OwnPlayerData = nil;
_VehicleAndOwner = nil;
_ImpoundedVehicles = nil;
end
function ShowRetrievalMenu ()
_XPlayer = _ESX.GetPlayerData()
TriggerServerEvent('HRP:ESX:GetCharacter', _XPlayer.identifier)
TriggerServerEvent('HRP:Impound:GetImpoundedVehicles', _XPlayer.identifier)
Citizen.Wait(500)
_GuiEnabled = true
SetNuiFocus(true, true)
local data = {
action = "open",
form = "retrieve",
user = _OwnPlayerData,
job = _XPlayer.job,
vehicles = _ImpoundedVehicles
}
SendNuiMessage(json.encode(data))
end
RegisterNUICallback('escape', function(data, cb)
DisableImpoundMenu()
-- cb('ok')
end)
RegisterNUICallback('impound', function(data, cb)
local v = _ESX.Game.GetClosestVehicle();
local veh = _ESX.Game.GetVehicleProperties(v);
veh.engineHealth = GetVehicleEngineHealth(v);
veh.bodyHealth = GetVehicleBodyHealth(v);
veh.fuelLevel = GetVehicleFuelLevel(v);
veh.oilLevel = GetVehicleOilLevel(v);
veh.petrolTankHealth = GetVehiclePetrolTankHealth(v);
veh.tyresburst = {};
for i = 1, 7 do
res = IsVehicleTyreBurst(v, i, false);
if res ~= nil then
veh.tyresburst[#veh.tyresburst+1] = res;
if res == false then
res = IsVehicleTyreBurst(v, i, true);
veh.tyresburst[#veh.tyresburst] = res;
end
else
veh.tyresburst[#veh.tyresburst+1] = false;
end
end
veh.windows = {};
for i = 1, 13 do
res = IsVehicleWindowIntact(v, i);
if res ~= nil then
veh.windows[#veh.windows+1] = res;
else
veh.windows[#veh.windows+1] = true;
end
end
if (veh.plate:gsub("%s+", "") ~= data.plate:gsub("%s+", "")) then
_ESX.ShowNotification("The processed vehicle, and nearest vehicle do not match");
return
end
data.vehicle = json.encode(veh);
data.identifier = _VehicleAndOwner.identifier;
TriggerServerEvent('HRP:Impound:ImpoundVehicle', data)
_ESX.Game.DeleteVehicle(_ESX.Game.GetClosestVehicle());
DisableImpoundMenu()
-- cb('ok')
end)
RegisterNUICallback('unimpound', function(plate, cb)
Citizen.Trace("Unimpounding:" .. plate)
TriggerServerEvent('HRP:Impound:UnimpoundVehicle', plate);
DisableImpoundMenu();
-- cb('ok');
end)
RegisterNUICallback('unlock', function(plate, cb)
TriggerServerEvent('HRP:Impound:UnlockVehicle', plate)
end)
----------------------------------------------------------------------------------------------------
-- Background tasks
----------------------------------------------------------------------------------------------------
-- Decide what the player is currently doing and showing a help notification.
Citizen.CreateThread(function ()
while true do
inZone = false;
Citizen.Wait(500)
if(_DependenciesLoaded) then
local PlayerPed = GetPlayerPed(PlayerId())
local PlayerPedCoords = GetEntityCoords(PlayerPed)
if (GetDistanceBetweenCoords(_Impound.RetrieveLocation.X, _Impound.RetrieveLocation.Y, _Impound.RetrieveLocation.Z,
PlayerPedCoords.x, PlayerPedCoords.y, PlayerPedCoords.z, false) < 3) then
inZone = true;
if (_CurrentAction ~= "retrieve") then
_CurrentAction = "retrieve"
_ESX.ShowHelpNotification("Press ~INPUT_CONTEXT~ To unimpound a vehicle");
end
elseif (GetDistanceBetweenCoords(_Impound.StoreLocation.X, _Impound.StoreLocation.Y, _Impound.StoreLocation.Z,
PlayerPedCoords.x, PlayerPedCoords.y, PlayerPedCoords.z, false) < 3) then
inZone = true;
if (_CurrentAction ~= "store" and (_XPlayer.job.name == "police" or _XPlayer.job.name == "mecano")) then
_CurrentAction = "store"
_ESX.ShowHelpNotification("Press ~INPUT_CONTEXT~ To impound this vehicle");
end
else
for i, location in ipairs(_Impound.AdminTerminalLocations) do
if (GetDistanceBetweenCoords(location.x, location.y, location.z,
PlayerPedCoords.x, PlayerPedCoords.y, PlayerPedCoords.z, false) < 3) then
inZone = true;
if (_CurrentAction ~= "admin" and (_XPlayer.job.name == "police" or _XPlayer.job.name == "mecano")) then
_CurrentAction = "admin"
_ESX.ShowHelpNotification("Press ~INPUT_CONTEXT~ To open the admin terminal");
end
break;
end
end
end
end
if not inZone then
_CurrentAction = nil;
end
end
end)
Citizen.CreateThread(function ()
while true do
Citizen.Wait(0)
if (IsControlJustReleased(0, 38)) then
if (_CurrentAction == "retrieve") then
ShowRetrievalMenu()
elseif (_CurrentAction == "store") then
ShowImpoundMenu("store")
elseif (_CurrentAction == "admin") then
ShowAdminTerminal("admin")
end
end
end
end)
-- Disable background actions if the player is currently in a menu
Citizen.CreateThread(function()
while true do
if _GuiEnabled then
local ply = GetPlayerPed(-1)
local active = true
DisableControlAction(0, 1, active) -- LookLeftRight
DisableControlAction(0, 2, active) -- LookUpDown
DisableControlAction(0, 24, active) -- Attack
DisablePlayerFiring(ply, true) -- Disable weapon firing
DisableControlAction(0, 142, active) -- MeleeAttackAlternate
DisableControlAction(0, 106, active) -- VehicleMouseControlOverride
if IsDisabledControlJustReleased(0, 24) or IsDisabledControlJustReleased(0, 142) then -- MeleeAttackAlternate
SendNUIMessage({type = "click"})
end
end
Citizen.Wait(0)
end
end)
function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end