This repository has been archived by the owner on Jul 17, 2023. It is now read-only.
forked from distritic/mdt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcl_mdt.lua
411 lines (360 loc) · 14.4 KB
/
cl_mdt.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
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
400
401
402
403
404
405
406
407
408
409
410
411
local isVisible = false
local tabletObject = nil
local callBip = nil
local zones = { ['AIRP'] = "Los Santos International Airport", ['ALAMO'] = "Alamo Sea", ['ALTA'] = "Alta", ['ARMYB'] = "Fort Zancudo", ['BANHAMC'] = "Banham Canyon Dr", ['BANNING'] = "Banning", ['BEACH'] = "Vespucci Beach", ['BHAMCA'] = "Banham Canyon", ['BRADP'] = "Braddock Pass", ['BRADT'] = "Braddock Tunnel", ['BURTON'] = "Burton", ['CALAFB'] = "Calafia Bridge", ['CANNY'] = "Raton Canyon", ['CCREAK'] = "Cassidy Creek", ['CHAMH'] = "Chamberlain Hills", ['CHIL'] = "Vinewood Hills", ['CHU'] = "Chumash", ['CMSW'] = "Chiliad Mountain State Wilderness", ['CYPRE'] = "Cypress Flats", ['DAVIS'] = "Davis", ['DELBE'] = "Del Perro Beach", ['DELPE'] = "Del Perro", ['DELSOL'] = "La Puerta", ['DESRT'] = "Grand Senora Desert", ['DOWNT'] = "Downtown", ['DTVINE'] = "Downtown Vinewood", ['EAST_V'] = "East Vinewood", ['EBURO'] = "El Burro Heights", ['ELGORL'] = "El Gordo Lighthouse", ['ELYSIAN'] = "Elysian Island", ['GALFISH'] = "Galilee", ['GOLF'] = "GWC and Golfing Society", ['GRAPES'] = "Grapeseed", ['GREATC'] = "Great Chaparral", ['HARMO'] = "Harmony", ['HAWICK'] = "Hawick", ['HORS'] = "Vinewood Racetrack", ['HUMLAB'] = "Humane Labs and Research", ['JAIL'] = "Bolingbroke Penitentiary", ['KOREAT'] = "Little Seoul", ['LACT'] = "Land Act Reservoir", ['LAGO'] = "Lago Zancudo", ['LDAM'] = "Land Act Dam", ['LEGSQU'] = "Legion Square", ['LMESA'] = "La Mesa", ['LOSPUER'] = "La Puerta", ['MIRR'] = "Mirror Park", ['MORN'] = "Morningwood", ['MOVIE'] = "Richards Majestic", ['MTCHIL'] = "Mount Chiliad", ['MTGORDO'] = "Mount Gordo", ['MTJOSE'] = "Mount Josiah", ['MURRI'] = "Murrieta Heights", ['NCHU'] = "North Chumash", ['NOOSE'] = "N.O.O.S.E", ['OCEANA'] = "Pacific Ocean", ['PALCOV'] = "Paleto Cove", ['PALETO'] = "Paleto Bay", ['PALFOR'] = "Paleto Forest", ['PALHIGH'] = "Palomino Highlands", ['PALMPOW'] = "Palmer-Taylor Power Station", ['PBLUFF'] = "Pacific Bluffs", ['PBOX'] = "Pillbox Hill", ['PROCOB'] = "Procopio Beach", ['RANCHO'] = "Rancho", ['RGLEN'] = "Richman Glen", ['RICHM'] = "Richman", ['ROCKF'] = "Rockford Hills", ['RTRAK'] = "Redwood Lights Track", ['SANAND'] = "San Andreas", ['SANCHIA'] = "San Chianski Mountain Range", ['SANDY'] = "Sandy Shores", ['SKID'] = "Mission Row", ['SLAB'] = "Stab City", ['STAD'] = "Maze Bank Arena", ['STRAW'] = "Strawberry", ['TATAMO'] = "Tataviam Mountains", ['TERMINA'] = "Terminal", ['TEXTI'] = "Textile City", ['TONGVAH'] = "Tongva Hills", ['TONGVAV'] = "Tongva Valley", ['VCANA'] = "Vespucci Canals", ['VESP'] = "Vespucci", ['VINE'] = "Vinewood", ['WINDF'] = "Ron Alternates Wind Farm", ['WVINE'] = "West Vinewood", ['ZANCUDO'] = "Zancudo River", ['ZP_ORT'] = "Port of South Los Santos", ['ZQ_UAR'] = "Davis Quartz" }
RegisterCommand('mdt', function()
local playerPed = PlayerPedId()
local playerVeh = GetVehiclePedIsIn(playerPed, false)
if not isVisible and IsPedInAnyPoliceVehicle(playerPed) and GetEntitySpeed(playerVeh) < 5.0 then
if GetVehicleNumberPlateText(getVehicleInFront()) then
TriggerServerEvent("mdt:performVehicleSearchInFront", GetVehicleNumberPlateText(getVehicleInFront()))
else
TriggerServerEvent("mdt:hotKeyOpen")
end
elseif not IsPedInAnyPoliceVehicle(playerPed) then
TriggerServerEvent("mdt:hotKeyOpen")
end
if DoesEntityExist(playerPed) and IsPedUsingActionMode(playerPed) then -- disable action mode/combat stance when engaged in combat (thing which makes you run around like an idiot when shooting)
SetPedUsingActionMode(playerPed, -1, -1, 1)
end
end, false)
RegisterKeyMapping('mdt', 'Display the mdt', 'keyboard', 'delete')
TriggerServerEvent("mdt:getOffensesAndOfficer")
RegisterNetEvent("mdt:toggleVisibilty")
AddEventHandler("mdt:toggleVisibilty", function(reports, warrants, officer, job, grade)
local playerPed = PlayerPedId()
if not isVisible then
local dict = "amb@world_human_seat_wall_tablet@female@base"
RequestAnimDict(dict)
if tabletObject == nil then
tabletObject = CreateObject(GetHashKey('prop_cs_tablet'), GetEntityCoords(playerPed), 1, 1, 1)
AttachEntityToEntity(tabletObject, playerPed, GetPedBoneIndex(playerPed, 28422), 0.0, 0.0, 0.03, 0.0, 0.0, 0.0, 1, 1, 0, 1, 0, 1)
end
while not HasAnimDictLoaded(dict) do Citizen.Wait(100) end
if not IsEntityPlayingAnim(playerPed, dict, 'base', 3) then
TaskPlayAnim(playerPed, dict, "base", 8.0, 1.0, -1, 49, 1.0, 0, 0, 0)
end
else
DeleteEntity(tabletObject)
ClearPedTasks(playerPed)
tabletObject = nil
end
if #warrants == 0 then warrants = false end
if #reports == 0 then reports = false end
SendNUIMessage({
type = "recentReportsAndWarrantsLoaded",
reports = reports,
warrants = warrants,
officer = officer,
department = job,
rank = grade
})
ToggleGUI()
end)
RegisterNUICallback("close", function(data, cb)
local playerPed = PlayerPedId()
DeleteEntity(tabletObject)
ClearPedTasks(playerPed)
tabletObject = nil
ToggleGUI(false)
cb('ok')
end)
RegisterNUICallback("performOffenderSearch", function(data, cb)
TriggerServerEvent("mdt:performOffenderSearch", data.query)
TriggerServerEvent("mdt:getOffensesAndOfficer")
cb('ok')
end)
RegisterNUICallback("viewOffender", function(data, cb)
TriggerServerEvent("mdt:getOffenderDetails", data.offender)
cb('ok')
end)
RegisterNUICallback("saveOffenderChanges", function(data, cb)
TriggerServerEvent("mdt:saveOffenderChanges", data.id, data.changes, data.identifier)
cb('ok')
end)
RegisterNUICallback("submitNewReport", function(data, cb)
TriggerServerEvent("mdt:submitNewReport", data)
cb('ok')
end)
RegisterNUICallback("performReportSearch", function(data, cb)
TriggerServerEvent("mdt:performReportSearch", data.query)
cb('ok')
end)
RegisterNUICallback("getOffender", function(data, cb)
TriggerServerEvent("mdt:getOffenderDetailsById", data.char_id)
cb('ok')
end)
RegisterNUICallback("deleteReport", function(data, cb)
TriggerServerEvent("mdt:deleteReport", data.id)
cb('ok')
end)
RegisterNUICallback("saveReportChanges", function(data, cb)
TriggerServerEvent("mdt:saveReportChanges", data)
cb('ok')
end)
RegisterNUICallback("vehicleSearch", function(data, cb)
TriggerServerEvent("mdt:performVehicleSearch", data.plate)
cb('ok')
end)
RegisterNUICallback("getVehicle", function(data, cb)
TriggerServerEvent("mdt:getVehicle", data.vehicle)
cb('ok')
end)
RegisterNUICallback("getWarrants", function(data, cb)
TriggerServerEvent("mdt:getWarrants")
end)
RegisterNUICallback("submitNewWarrant", function(data, cb)
TriggerServerEvent("mdt:submitNewWarrant", data)
cb('ok')
end)
RegisterNUICallback("deleteWarrant", function(data, cb)
TriggerServerEvent("mdt:deleteWarrant", data.id)
cb('ok')
end)
RegisterNUICallback("deleteWarrant", function(data, cb)
TriggerServerEvent("mdt:deleteWarrant", data.id)
cb('ok')
end)
RegisterNUICallback("getReport", function(data, cb)
TriggerServerEvent("mdt:getReportDetailsById", data.id)
cb('ok')
end)
RegisterNUICallback("getCalls", function(data, cb)
TriggerServerEvent("mdt:getCalls")
end)
RegisterNUICallback("attachToCall", function(data, cb)
TriggerServerEvent("mdt:attachToCall", data.index)
if not callBlip then
callBlip = AddBlipForCoord(data.coords[1], data.coords[2], data.coords[3])
SetBlipSprite(callBlip, 304)
SetBlipDisplay(callBlip, 2)
SetBlipScale(callBlip, 1.2)
SetBlipColour(callBlip, 29)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString("911 Call")
EndTextCommandSetBlipName(callBlip)
end
cb('ok')
end)
RegisterNUICallback("detachFromCall", function(data, cb)
TriggerServerEvent("mdt:detachFromCall", data.index)
if callBlip then
RemoveBlip(callBlip)
callBlip = nil
end
cb('ok')
end)
RegisterNUICallback("setCallWaypoint", function(data, cb)
SetNewWaypoint(data.coords[1], data.coords[2])
cb('ok')
end)
RegisterNUICallback("editCall", function(data, cb)
TriggerServerEvent("mdt:editCall", data.index, data.details)
cb('ok')
end)
RegisterNUICallback("deleteCall", function(data, cb)
TriggerServerEvent("mdt:deleteCall", data.index)
cb('ok')
end)
RegisterNUICallback("deleteCallBlip", function(data, cb)
if callBlip then
RemoveBlip(callBlip)
callBlip = nil
end
end)
RegisterNUICallback("saveVehicleChanges", function(data, cb)
TriggerServerEvent("mdt:saveVehicleChanges", data)
cb('ok')
end)
RegisterNetEvent("mdt:returnOffenderSearchResults")
AddEventHandler("mdt:returnOffenderSearchResults", function(results)
SendNUIMessage({
type = "returnedPersonMatches",
matches = results
})
end)
RegisterNetEvent("mdt:closeModal")
AddEventHandler("mdt:closeModal", function()
SendNUIMessage({
type = "closeModal"
})
end)
RegisterNetEvent("mdt:returnOffenderDetails")
AddEventHandler("mdt:returnOffenderDetails", function(data)
for i = 1, #data.vehicles do
data.vehicles[i].model = GetLabelText(GetDisplayNameFromVehicleModel(data.vehicles[i].model))
end
SendNUIMessage({
type = "returnedOffenderDetails",
details = data
})
end)
RegisterNetEvent("mdt:returnOffensesAndOfficer")
AddEventHandler("mdt:returnOffensesAndOfficer", function(data, name)
SendNUIMessage({
type = "offensesAndOfficerLoaded",
offenses = data,
name = name
})
end)
RegisterNetEvent("mdt:returnReportSearchResults")
AddEventHandler("mdt:returnReportSearchResults", function(results)
SendNUIMessage({
type = "returnedReportMatches",
matches = results
})
end)
RegisterNetEvent("mdt:returnVehicleSearchInFront")
AddEventHandler("mdt:returnVehicleSearchInFront", function(results, plate)
SendNUIMessage({
type = "returnedVehicleMatchesInFront",
matches = results,
plate = plate
})
end)
RegisterNetEvent("mdt:returnVehicleSearchResults")
AddEventHandler("mdt:returnVehicleSearchResults", function(results)
SendNUIMessage({
type = "returnedVehicleMatches",
matches = results
})
end)
RegisterNetEvent("mdt:returnVehicleDetails")
AddEventHandler("mdt:returnVehicleDetails", function(data)
if type(data.model) == 'number' then
data.model = GetLabelText(GetDisplayNameFromVehicleModel(data.model))
end
SendNUIMessage({
type = "returnedVehicleDetails",
details = data
})
end)
RegisterNetEvent("mdt:returnWarrants")
AddEventHandler("mdt:returnWarrants", function(data)
SendNUIMessage({
type = "returnedWarrants",
warrants = data
})
end)
RegisterNetEvent("mdt:completedWarrantAction")
AddEventHandler("mdt:completedWarrantAction", function(data)
SendNUIMessage({
type = "completedWarrantAction"
})
end)
RegisterNetEvent("mdt:returnReportDetails")
AddEventHandler("mdt:returnReportDetails", function(data)
SendNUIMessage({
type = "returnedReportDetails",
details = data
})
end)
RegisterNetEvent("mdt:sendNUIMessage")
AddEventHandler("mdt:sendNUIMessage", function(messageTable)
SendNUIMessage(messageTable)
end)
RegisterNetEvent("mdt:sendNotification")
AddEventHandler("mdt:sendNotification", function(message)
SendNUIMessage({
type = "sendNotification",
message = message
})
end)
RegisterNetEvent("mdt:getNewCallCoords")
AddEventHandler("mdt:getNewCallCoords", function(details, callid)
local coords = GetEntityCoords(PlayerPedId())
TriggerServerEvent("mdt:newCall", details, callid, coords)
end)
RegisterNetEvent("mdt:newCall")
AddEventHandler("mdt:newCall", function(details, callid, coords, index)
local x, y, z = table.unpack(coords)
local var1, var2 = GetStreetNameAtCoord(x, y, z, Citizen.ResultAsInteger(), Citizen.ResultAsInteger())
local location = GetStreetNameFromHashKey(var1)..', '..zones[GetNameOfZone(x, y, z)]
SendNUIMessage({
type = "newCall",
details = details,
source = callid,
coords = {x, y, z},
location = location,
id = index
})
end)
RegisterNetEvent("mdt:newCallAttach")
AddEventHandler("mdt:newCallAttach", function(index, charname)
SendNUIMessage({
type = "newCallAttach",
call = index,
charname = charname
})
end)
RegisterNetEvent("mdt:newCallDetach")
AddEventHandler("mdt:newCallDetach", function(index, charname)
SendNUIMessage({
type = "newCallDetach",
call = index,
charname = charname
})
end)
RegisterNetEvent("mdt:editCall")
AddEventHandler("mdt:editCall", function(index, details)
SendNUIMessage({
type = "editCall",
call = index,
details = details
})
end)
RegisterNetEvent("mdt:deleteCall")
AddEventHandler("mdt:deleteCall", function(index)
SendNUIMessage({
type = "deleteCall",
call = index
})
end)
function ToggleGUI(explicit_status)
if explicit_status ~= nil then
isVisible = explicit_status
else
isVisible = not isVisible
end
SetNuiFocus(isVisible, isVisible)
SendNUIMessage({
type = "enable",
isVisible = isVisible
})
end
function getVehicleInFront()
local playerPed = PlayerPedId()
local coordA = GetEntityCoords(playerPed, 1)
local coordB = GetOffsetFromEntityInWorldCoords(playerPed, 0.0, 10.0, 0.0)
local targetVehicle = getVehicleInDirection(coordA, coordB)
return targetVehicle
end
function getVehicleInDirection(coordFrom, coordTo)
local rayHandle = CastRayPointToPoint(coordFrom.x, coordFrom.y, coordFrom.z, coordTo.x, coordTo.y, coordTo.z, 10, GetPlayerPed(-1), 0)
local a, b, c, d, vehicle = GetRaycastResult(rayHandle)
return vehicle
end
function tprint (tbl, indent)
if not indent then indent = 0 end
local toprint = string.rep(" ", indent) .. "{\r\n"
indent = indent + 2
for k, v in pairs(tbl) do
toprint = toprint .. string.rep(" ", indent)
if (type(k) == "number") then
toprint = toprint .. "[" .. k .. "] = "
elseif (type(k) == "string") then
toprint = toprint .. k .. "= "
end
if (type(v) == "number") then
toprint = toprint .. v .. ",\r\n"
elseif (type(v) == "string") then
toprint = toprint .. "\"" .. v .. "\",\r\n"
elseif (type(v) == "table") then
toprint = toprint .. tprint(v, indent + 2) .. ",\r\n"
else
toprint = toprint .. "\"" .. tostring(v) .. "\",\r\n"
end
end
toprint = toprint .. string.rep(" ", indent-2) .. "}"
return toprint
end