This repository has been archived by the owner on Jun 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
/
sv_mdt.lua
656 lines (586 loc) · 22.6 KB
/
sv_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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
ESX = nil
local call_index = 0
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
RegisterServerEvent("mdt:hotKeyOpen")
AddEventHandler("mdt:hotKeyOpen", function()
local usource = source
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.job.name == 'police' then
MySQL.Async.fetchAll("SELECT * FROM (SELECT * FROM `mdt_reports` ORDER BY `id` DESC LIMIT 3) sub ORDER BY `id` DESC", {}, function(reports)
for r = 1, #reports do
reports[r].charges = json.decode(reports[r].charges)
end
MySQL.Async.fetchAll("SELECT * FROM (SELECT * FROM `mdt_warrants` ORDER BY `id` DESC LIMIT 3) sub ORDER BY `id` DESC", {}, function(warrants)
for w = 1, #warrants do
warrants[w].charges = json.decode(warrants[w].charges)
end
local officer = GetCharacterName(usource)
TriggerClientEvent('mdt:toggleVisibilty', usource, reports, warrants, officer, xPlayer.job.name)
end)
end)
end
end)
RegisterServerEvent("mdt:getOffensesAndOfficer")
AddEventHandler("mdt:getOffensesAndOfficer", function()
local usource = source
local charges = {}
MySQL.Async.fetchAll('SELECT * FROM fine_types', {
}, function(fines)
for j = 1, #fines do
if fines[j].category == 0 or fines[j].category == 1 or fines[j].category == 2 or fines[j].category == 3 then
table.insert(charges, fines[j])
end
end
local officer = GetCharacterName(usource)
TriggerClientEvent("mdt:returnOffensesAndOfficer", usource, charges, officer)
end)
end)
RegisterServerEvent("mdt:performOffenderSearch")
AddEventHandler("mdt:performOffenderSearch", function(query)
local usource = source
local matches = {}
MySQL.Async.fetchAll("SELECT * FROM `characters` WHERE LOWER(`firstname`) LIKE @query OR LOWER(`lastname`) LIKE @query OR CONCAT(LOWER(`firstname`), ' ', LOWER(`lastname`)) LIKE @query", {
['@query'] = string.lower('%'..query..'%') -- % wildcard, needed to search for all alike results
}, function(result)
for index, data in ipairs(result) do
table.insert(matches, data)
end
TriggerClientEvent("mdt:returnOffenderSearchResults", usource, matches)
end)
end)
RegisterServerEvent("mdt:getOffenderDetails")
AddEventHandler("mdt:getOffenderDetails", function(offender)
local usource = source
GetLicenses(offender.identifier, function(licenses) offender.licenses = licenses end)
while offender.licenses == nil do Citizen.Wait(0) end
local result = MySQL.Sync.fetchAll('SELECT * FROM `user_mdt` WHERE `char_id` = @id', {
['@id'] = offender.id
})
offender.notes = ""
offender.mugshot_url = ""
offender.bail = false
if result[1] then
offender.notes = result[1].notes
offender.mugshot_url = result[1].mugshot_url
offender.bail = result[1].bail
end
local convictions = MySQL.Sync.fetchAll('SELECT * FROM `user_convictions` WHERE `char_id` = @id', {
['@id'] = offender.id
})
if convictions[1] then
offender.convictions = {}
for i = 1, #convictions do
local conviction = convictions[i]
offender.convictions[conviction.offense] = conviction.count
end
end
local warrants = MySQL.Sync.fetchAll('SELECT * FROM `mdt_warrants` WHERE `char_id` = @id', {
['@id'] = offender.id
})
if warrants[1] then
offender.haswarrant = true
end
local phone_number = MySQL.Sync.fetchAll('SELECT `phone_number` FROM `users` WHERE `identifier` = @identifier', {
['@identifier'] = offender.identifier
})
offender.phone_number = phone_number[1].phone_number
local vehicles = MySQL.Sync.fetchAll('SELECT * FROM `owned_vehicles` WHERE `owner` = @identifier', {
['@identifier'] = offender.identifier
})
for i = 1, #vehicles do
vehicles[i].state, vehicles[i].stored, vehicles[i].job, vehicles[i].fourrieremecano, vehicles[i].vehiclename, vehicles[i].ownerName = nil
vehicles[i].vehicle = json.decode(vehicles[i].vehicle)
vehicles[i].model = vehicles[i].vehicle.model
if vehicles[i].vehicle.color1 then
if colors[tostring(vehicles[i].vehicle.color2)] and colors[tostring(vehicles[i].vehicle.color1)] then
vehicles[i].color = colors[tostring(vehicles[i].vehicle.color2)] .. " on " .. colors[tostring(vehicles[i].vehicle.color1)]
elseif colors[tostring(vehicles[i].vehicle.color1)] then
vehicles[i].color = colors[tostring(vehicles[i].vehicle.color1)]
elseif colors[tostring(vehicles[i].vehicle.color2)] then
vehicles[i].color = colors[tostring(vehicles[i].vehicle.color2)]
else
vehicles[i].color = "Unknown"
end
end
vehicles[i].vehicle = nil
end
offender.vehicles = vehicles
TriggerClientEvent("mdt:returnOffenderDetails", usource, offender)
end)
RegisterServerEvent("mdt:getOffenderDetailsById")
AddEventHandler("mdt:getOffenderDetailsById", function(char_id)
local usource = source
local result = MySQL.Sync.fetchAll('SELECT * FROM `characters` WHERE `id` = @id', {
['@id'] = char_id
})
local offender = result[1]
if not offender then
TriggerClientEvent("mdt:closeModal", usource)
TriggerClientEvent("mdt:sendNotification", usource, "This person no longer exists.")
return
end
GetLicenses(offender.identifier, function(licenses) offender.licenses = licenses end)
while offender.licenses == nil do Citizen.Wait(0) end
local result = MySQL.Sync.fetchAll('SELECT * FROM `user_mdt` WHERE `char_id` = @id', {
['@id'] = offender.id
})
offender.notes = ""
offender.mugshot_url = ""
offender.bail = false
if result[1] then
offender.notes = result[1].notes
offender.mugshot_url = result[1].mugshot_url
offender.bail = result[1].bail
end
local convictions = MySQL.Sync.fetchAll('SELECT * FROM `user_convictions` WHERE `char_id` = @id', {
['@id'] = offender.id
})
if convictions[1] then
offender.convictions = {}
for i = 1, #convictions do
local conviction = convictions[i]
offender.convictions[conviction.offense] = conviction.count
end
end
local warrants = MySQL.Sync.fetchAll('SELECT * FROM `mdt_warrants` WHERE `char_id` = @id', {
['@id'] = offender.id
})
if warrants[1] then
offender.haswarrant = true
end
local phone_number = MySQL.Sync.fetchAll('SELECT `phone_number` FROM `users` WHERE `identifier` = @identifier', {
['@identifier'] = offender.identifier
})
offender.phone_number = phone_number[1].phone_number
local vehicles = MySQL.Sync.fetchAll('SELECT * FROM `owned_vehicles` WHERE `owner` = @identifier', {
['@identifier'] = offender.identifier
})
for i = 1, #vehicles do
vehicles[i].state, vehicles[i].stored, vehicles[i].job, vehicles[i].fourrieremecano, vehicles[i].vehiclename, vehicles[i].ownerName = nil
vehicles[i].vehicle = json.decode(vehicles[i].vehicle)
vehicles[i].model = vehicles[i].vehicle.model
if vehicles[i].vehicle.color1 then
if colors[tostring(vehicles[i].vehicle.color2)] and colors[tostring(vehicles[i].vehicle.color1)] then
vehicles[i].color = colors[tostring(vehicles[i].vehicle.color2)] .. " on " .. colors[tostring(vehicles[i].vehicle.color1)]
elseif colors[tostring(vehicles[i].vehicle.color1)] then
vehicles[i].color = colors[tostring(vehicles[i].vehicle.color1)]
elseif colors[tostring(vehicles[i].vehicle.color2)] then
vehicles[i].color = colors[tostring(vehicles[i].vehicle.color2)]
else
vehicles[i].color = "Unknown"
end
end
vehicles[i].vehicle = nil
end
offender.vehicles = vehicles
TriggerClientEvent("mdt:returnOffenderDetails", usource, offender)
end)
RegisterServerEvent("mdt:saveOffenderChanges")
AddEventHandler("mdt:saveOffenderChanges", function(id, changes, identifier)
local usource = source
MySQL.Async.fetchAll('SELECT * FROM `user_mdt` WHERE `char_id` = @id', {
['@id'] = id
}, function(result)
if result[1] then
MySQL.Async.execute('UPDATE `user_mdt` SET `notes` = @notes, `mugshot_url` = @mugshot_url, `bail` = @bail WHERE `char_id` = @id', {
['@id'] = id,
['@notes'] = changes.notes,
['@mugshot_url'] = changes.mugshot_url,
['@bail'] = changes.bail
})
else
MySQL.Async.insert('INSERT INTO `user_mdt` (`char_id`, `notes`, `mugshot_url`, `bail`) VALUES (@id, @notes, @mugshot_url, @bail)', {
['@id'] = id,
['@notes'] = changes.notes,
['@mugshot_url'] = changes.mugshot_url,
['@bail'] = changes.bail
})
end
for i = 1, #changes.licenses_removed do
local license = changes.licenses_removed[i]
MySQL.Async.execute('DELETE FROM `user_licenses` WHERE `type` = @type AND `owner` = @identifier', {
['@type'] = license.type,
['@identifier'] = identifier
})
end
if changes.convictions ~= nil then
for conviction, amount in pairs(changes.convictions) do
MySQL.Async.execute('UPDATE `user_convictions` SET `count` = @count WHERE `char_id` = @id AND `offense` = @offense', {
['@id'] = id,
['@count'] = amount,
['@offense'] = conviction
})
end
end
for i = 1, #changes.convictions_removed do
MySQL.Async.execute('DELETE FROM `user_convictions` WHERE `char_id` = @id AND `offense` = @offense', {
['@id'] = id,
['offense'] = changes.convictions_removed[i]
})
end
TriggerClientEvent("mdt:sendNotification", usource, "Offender changes have been saved.")
end)
end)
RegisterServerEvent("mdt:saveReportChanges")
AddEventHandler("mdt:saveReportChanges", function(data)
MySQL.Async.execute('UPDATE `mdt_reports` SET `title` = @title, `incident` = @incident WHERE `id` = @id', {
['@id'] = data.id,
['@title'] = data.title,
['@incident'] = data.incident
})
TriggerClientEvent("mdt:sendNotification", source, "Report changes have been saved.")
end)
RegisterServerEvent("mdt:deleteReport")
AddEventHandler("mdt:deleteReport", function(id)
MySQL.Async.execute('DELETE FROM `mdt_reports` WHERE `id` = @id', {
['@id'] = id
})
TriggerClientEvent("mdt:sendNotification", source, "Report has been successfully deleted.")
end)
RegisterServerEvent("mdt:submitNewReport")
AddEventHandler("mdt:submitNewReport", function(data)
local usource = source
local author = GetCharacterName(source)
charges = json.encode(data.charges)
data.date = os.date('%m-%d-%Y %H:%M:%S', os.time())
MySQL.Async.insert('INSERT INTO `mdt_reports` (`char_id`, `title`, `incident`, `charges`, `author`, `name`, `date`) VALUES (@id, @title, @incident, @charges, @author, @name, @date)', {
['@id'] = data.char_id,
['@title'] = data.title,
['@incident'] = data.incident,
['@charges'] = charges,
['@author'] = author,
['@name'] = data.name,
['@date'] = data.date,
}, function(id)
TriggerEvent("mdt:getReportDetailsById", id, usource)
TriggerClientEvent("mdt:sendNotification", usource, "A new report has been submitted.")
end)
for offense, count in pairs(data.charges) do
MySQL.Async.fetchAll('SELECT * FROM `user_convictions` WHERE `offense` = @offense AND `char_id` = @id', {
['@offense'] = offense,
['@id'] = data.char_id
}, function(result)
if result[1] then
MySQL.Async.execute('UPDATE `user_convictions` SET `count` = @count WHERE `offense` = @offense AND `char_id` = @id', {
['@id'] = data.char_id,
['@offense'] = offense,
['@count'] = count + 1
})
else
MySQL.Async.insert('INSERT INTO `user_convictions` (`char_id`, `offense`, `count`) VALUES (@id, @offense, @count)', {
['@id'] = data.char_id,
['@offense'] = offense,
['@count'] = count
})
end
end)
end
end)
RegisterServerEvent("mdt:performReportSearch")
AddEventHandler("mdt:performReportSearch", function(query)
local usource = source
local matches = {}
MySQL.Async.fetchAll("SELECT * FROM `mdt_reports` WHERE `id` LIKE @query OR LOWER(`title`) LIKE @query OR LOWER(`name`) LIKE @query OR LOWER(`author`) LIKE @query or LOWER(`charges`) LIKE @query", {
['@query'] = string.lower('%'..query..'%') -- % wildcard, needed to search for all alike results
}, function(result)
for index, data in ipairs(result) do
data.charges = json.decode(data.charges)
table.insert(matches, data)
end
TriggerClientEvent("mdt:returnReportSearchResults", usource, matches)
end)
end)
RegisterServerEvent("mdt:performVehicleSearch")
AddEventHandler("mdt:performVehicleSearch", function(query)
local usource = source
local matches = {}
MySQL.Async.fetchAll("SELECT * FROM `owned_vehicles` WHERE LOWER(`plate`) LIKE @query", {
['@query'] = string.lower('%'..query..'%') -- % wildcard, needed to search for all alike results
}, function(result)
for index, data in ipairs(result) do
local data_decoded = json.decode(data.vehicle)
data.model = data_decoded.model
if data_decoded.color1 then
data.color = colors[tostring(data_decoded.color1)]
if colors[tostring(data_decoded.color2)] then
data.color = colors[tostring(data_decoded.color2)] .. " on " .. colors[tostring(data_decoded.color1)]
end
end
table.insert(matches, data)
end
TriggerClientEvent("mdt:returnVehicleSearchResults", usource, matches)
end)
end)
RegisterServerEvent("mdt:performVehicleSearchInFront")
AddEventHandler("mdt:performVehicleSearchInFront", function(query)
local usource = source
local xPlayer = ESX.GetPlayerFromId(usource)
if xPlayer.job.name == 'police' then
MySQL.Async.fetchAll("SELECT * FROM (SELECT * FROM `mdt_reports` ORDER BY `id` DESC LIMIT 3) sub ORDER BY `id` DESC", {}, function(reports)
for r = 1, #reports do
reports[r].charges = json.decode(reports[r].charges)
end
MySQL.Async.fetchAll("SELECT * FROM (SELECT * FROM `mdt_warrants` ORDER BY `id` DESC LIMIT 3) sub ORDER BY `id` DESC", {}, function(warrants)
for w = 1, #warrants do
warrants[w].charges = json.decode(warrants[w].charges)
end
MySQL.Async.fetchAll("SELECT * FROM `owned_vehicles` WHERE `plate` = @query", {
['@query'] = query
}, function(result)
local officer = GetCharacterName(usource)
TriggerClientEvent('mdt:toggleVisibilty', usource, reports, warrants, officer, xPlayer.job.name)
TriggerClientEvent("mdt:returnVehicleSearchInFront", usource, result, query)
end)
end)
end)
end
end)
RegisterServerEvent("mdt:getVehicle")
AddEventHandler("mdt:getVehicle", function(vehicle)
local usource = source
local result = MySQL.Sync.fetchAll("SELECT * FROM `characters` WHERE `identifier` = @query", {
['@query'] = vehicle.owner
})
if result[1] then
vehicle.owner = result[1].firstname .. ' ' .. result[1].lastname
vehicle.owner_id = result[1].id
end
local data = MySQL.Sync.fetchAll('SELECT * FROM `vehicle_mdt` WHERE `plate` = @plate', {
['@plate'] = vehicle.plate
})
if data[1] then
if data[1].stolen == 1 then vehicle.stolen = true else vehicle.stolen = false end
if data[1].notes ~= null then vehicle.notes = data[1].notes else vehicle.notes = '' end
else
vehicle.stolen = false
vehicle.notes = ''
end
local warrants = MySQL.Sync.fetchAll('SELECT * FROM `mdt_warrants` WHERE `char_id` = @id', {
['@id'] = vehicle.owner_id
})
if warrants[1] then
vehicle.haswarrant = true
end
local bail = MySQL.Sync.fetchAll('SELECT `bail` FROM user_mdt WHERE `char_id` = @id', {
['@id'] = vehicle.owner_id
})
if bail and bail[1] and bail[1].bail == 1 then vehicle.bail = true else vehicle.bail = false end
vehicle.type = types[vehicle.type]
TriggerClientEvent("mdt:returnVehicleDetails", usource, vehicle)
end)
RegisterServerEvent("mdt:getWarrants")
AddEventHandler("mdt:getWarrants", function()
local usource = source
MySQL.Async.fetchAll("SELECT * FROM `mdt_warrants`", {}, function(warrants)
for i = 1, #warrants do
warrants[i].expire_time = ""
warrants[i].charges = json.decode(warrants[i].charges)
end
TriggerClientEvent("mdt:returnWarrants", usource, warrants)
end)
end)
RegisterServerEvent("mdt:submitNewWarrant")
AddEventHandler("mdt:submitNewWarrant", function(data)
local usource = source
data.charges = json.encode(data.charges)
data.author = GetCharacterName(source)
data.date = os.date('%m-%d-%Y %H:%M:%S', os.time())
MySQL.Async.insert('INSERT INTO `mdt_warrants` (`name`, `char_id`, `report_id`, `report_title`, `charges`, `date`, `expire`, `notes`, `author`) VALUES (@name, @char_id, @report_id, @report_title, @charges, @date, @expire, @notes, @author)', {
['@name'] = data.name,
['@char_id'] = data.char_id,
['@report_id'] = data.report_id,
['@report_title'] = data.report_title,
['@charges'] = data.charges,
['@date'] = data.date,
['@expire'] = data.expire,
['@notes'] = data.notes,
['@author'] = data.author
}, function()
TriggerClientEvent("mdt:completedWarrantAction", usource)
TriggerClientEvent("mdt:sendNotification", usource, "A new warrant has been created.")
end)
end)
RegisterServerEvent("mdt:deleteWarrant")
AddEventHandler("mdt:deleteWarrant", function(id)
local usource = source
MySQL.Async.execute('DELETE FROM `mdt_warrants` WHERE `id` = @id', {
['@id'] = id
}, function()
TriggerClientEvent("mdt:completedWarrantAction", usource)
end)
TriggerClientEvent("mdt:sendNotification", usource, "Warrant has been successfully deleted.")
end)
RegisterServerEvent("mdt:getReportDetailsById")
AddEventHandler("mdt:getReportDetailsById", function(query, _source)
if _source then source = _source end
local usource = source
MySQL.Async.fetchAll("SELECT * FROM `mdt_reports` WHERE `id` = @query", {
['@query'] = query
}, function(result)
if result and result[1] then
result[1].charges = json.decode(result[1].charges)
TriggerClientEvent("mdt:returnReportDetails", usource, result[1])
else
TriggerClientEvent("mdt:closeModal", usource)
TriggerClientEvent("mdt:sendNotification", usource, "This report cannot be found.")
end
end)
end)
RegisterServerEvent("mdt:newCall")
AddEventHandler("mdt:newCall", function(details, caller, coords)
call_index = call_index + 1
local xPlayers = ESX.GetPlayers()
for i= 1, #xPlayers do
local source = xPlayers[i]
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.job.name == 'police' then
TriggerClientEvent("mdt:newCall", source, details, caller, coords, call_index)
TriggerClientEvent("InteractSound_CL:PlayOnOne", source, 'demo', 1.0)
TriggerClientEvent("mythic_notify:client:SendAlert", source, {type="infom", text="You have received a new call.", length=5000, style = { ['background-color'] = '#ffffff', ['color'] = '#000000' }})
end
end
end)
RegisterServerEvent("mdt:attachToCall")
AddEventHandler("mdt:attachToCall", function(index)
local usource = source
local charname = GetCharacterName(usource)
local xPlayers = ESX.GetPlayers()
for i= 1, #xPlayers do
local source = xPlayers[i]
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.job.name == 'police' then
TriggerClientEvent("mdt:newCallAttach", source, index, charname)
end
end
TriggerClientEvent("mdt:sendNotification", usource, "You have attached to this call.")
end)
RegisterServerEvent("mdt:detachFromCall")
AddEventHandler("mdt:detachFromCall", function(index)
local usource = source
local charname = GetCharacterName(usource)
local xPlayers = ESX.GetPlayers()
for i= 1, #xPlayers do
local source = xPlayers[i]
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.job.name == 'police' then
TriggerClientEvent("mdt:newCallDetach", source, index, charname)
end
end
TriggerClientEvent("mdt:sendNotification", usource, "You have detached from this call.")
end)
RegisterServerEvent("mdt:editCall")
AddEventHandler("mdt:editCall", function(index, details)
local usource = source
local xPlayers = ESX.GetPlayers()
for i= 1, #xPlayers do
local source = xPlayers[i]
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.job.name == 'police' then
TriggerClientEvent("mdt:editCall", source, index, details)
end
end
TriggerClientEvent("mdt:sendNotification", usource, "You have edited this call.")
end)
RegisterServerEvent("mdt:deleteCall")
AddEventHandler("mdt:deleteCall", function(index)
local usource = source
local xPlayers = ESX.GetPlayers()
for i= 1, #xPlayers do
local source = xPlayers[i]
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.job.name == 'police' then
TriggerClientEvent("mdt:deleteCall", source, index)
end
end
TriggerClientEvent("mdt:sendNotification", usource, "You have deleted this call.")
end)
RegisterServerEvent("mdt:saveVehicleChanges")
AddEventHandler("mdt:saveVehicleChanges", function(data)
if data.stolen then data.stolen = 1 else data.stolen = 0 end
local usource = source
MySQL.Async.fetchAll('SELECT * FROM `vehicle_mdt` WHERE `plate` = @plate', {
['@plate'] = data.plate
}, function(result)
if result[1] then
MySQL.Async.execute('UPDATE `vehicle_mdt` SET `stolen` = @stolen, `notes` = @notes WHERE `plate` = @plate', {
['@plate'] = data.plate,
['@stolen'] = data.stolen,
['@notes'] = data.notes
})
else
MySQL.Async.insert('INSERT INTO `vehicle_mdt` (`plate`, `stolen`, `notes`) VALUES (@plate, @stolen, @notes)', {
['@plate'] = data.plate,
['@stolen'] = data.stolen,
['@notes'] = data.notes
})
end
TriggerClientEvent("mdt:sendNotification", usource, "Vehicle changes have been saved.")
end)
end)
function GetLicenses(identifier, cb)
MySQL.Async.fetchAll('SELECT * FROM user_licenses WHERE owner = @owner', {
['@owner'] = identifier
}, function(result)
local licenses = {}
local asyncTasks = {}
for i=1, #result, 1 do
local scope = function(type)
table.insert(asyncTasks, function(cb)
MySQL.Async.fetchAll('SELECT * FROM licenses WHERE type = @type', {
['@type'] = type
}, function(result2)
table.insert(licenses, {
type = type,
label = result2[1].label
})
cb()
end)
end)
end
scope(result[i].type)
end
Async.parallel(asyncTasks, function(results)
if #licenses == 0 then licenses = false end
cb(licenses)
end)
end)
end
function GetCharacterName(source)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer then
return xPlayer.getName()
--[[ -- If the wrong name displays, remove `return xPlayer.getName()` and uncomment this code block
local identifier = xPlayer.getIdentifier()
local result = MySQL.Sync.fetchAll('SELECT firstname, lastname FROM `users` WHERE identifier = @identifier', {
['@identifier'] = identifier
})
if result[1] and result[1].firstname and result[1].lastname then
return ('%s %s'):format(result[1].firstname, result[1].lastname)
end
]]
end
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