-
Notifications
You must be signed in to change notification settings - Fork 290
/
Copy pathmain.lua
1923 lines (1715 loc) · 75 KB
/
main.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
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local QBCore = exports['qb-core']:GetCoreObject()
local incidents = {}
local convictions = {}
local bolos = {}
local MugShots = {}
local activeUnits = {}
local impound = {}
local dispatchMessages = {}
local isDispatchRunning = false
local antiSpam = false
--------------------------------
-- SET YOUR WEHBOOKS IN HERE
-- Images for mug shots will be uploaded here. Add a Discord webhook.
local MugShotWebhook = ''
-- Clock-in notifications for duty. Add a Discord webhook.
-- Command /mdtleaderboard, will display top players per clock-in hours.
local ClockinWebhook = ''
--------------------------------
QBCore.Functions.CreateCallback('ps-mdt:server:MugShotWebhook', function(source, cb)
if MugShotWebhook == '' then
print("\27[31mA webhook is missing in: MugShotWebhook (server > main.lua > line 16)\27[0m")
else
cb(MugShotWebhook)
end
end)
local function GetActiveData(cid)
local player = type(cid) == "string" and cid or tostring(cid)
if player then
return activeUnits[player] and true or false
end
return false
end
local function IsPoliceOrEms(job)
for k, v in pairs(Config.PoliceJobs) do
if job == k then
return true
end
end
for k, v in pairs(Config.AmbulanceJobs) do
if job == k then
return true
end
end
return false
end
RegisterServerEvent("ps-mdt:dispatchStatus", function(bool)
isDispatchRunning = bool
end)
if Config.UseWolfknightRadar == true then
RegisterNetEvent("wk:onPlateScanned")
AddEventHandler("wk:onPlateScanned", function(cam, plate, index)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local PlayerData = GetPlayerData(src)
local vehicleOwner = GetVehicleOwner(plate)
local bolo, title, boloId = GetBoloStatus(plate)
local warrant, owner, incidentId = GetWarrantStatus(plate)
local driversLicense = PlayerData.metadata['licences'].driver
if bolo == true then
TriggerClientEvent('QBCore:Notify', src, 'BOLO ID: '..boloId..' | Title: '..title..' | Registered Owner: '..vehicleOwner..' | Plate: '..plate, 'error', Config.WolfknightNotifyTime)
end
if warrant == true then
TriggerClientEvent('QBCore:Notify', src, 'WANTED - INCIDENT ID: '..incidentId..' | Registered Owner: '..owner..' | Plate: '..plate, 'error', Config.WolfknightNotifyTime)
end
if Config.PlateScanForDriversLicense and driversLicense == false and vehicleOwner then
TriggerClientEvent('QBCore:Notify', src, 'NO DRIVERS LICENCE | Registered Owner: '..vehicleOwner..' | Plate: '..plate, 'error', Config.WolfknightNotifyTime)
end
if bolo or warrant or (Config.PlateScanForDriversLicense and not driversLicense) then
TriggerClientEvent("wk:togglePlateLock", src, cam, true, 1)
end
end)
end
AddEventHandler('onResourceStart', function(resourceName)
if GetCurrentResourceName() ~= resourceName then return end
Wait(3000)
if MugShotWebhook == '' then
print("\27[31mA webhook is missing in: MugShotWebhook (server > main.lua > line 16)\27[0m")
end
if ClockinWebhook == '' then
print("\27[31mA webhook is missing in: ClockinWebhook (server > main.lua > line 20)\27[0m")
end
end)
RegisterNetEvent("ps-mdt:server:OnPlayerUnload", function()
--// Delete player from the MDT on logout
local src = source
local player = QBCore.Functions.GetPlayer(src)
if GetActiveData(player.PlayerData.citizenid) then
activeUnits[player.PlayerData.citizenid] = nil
end
end)
AddEventHandler('playerDropped', function(reason)
local src = source
local PlayerData = GetPlayerData(src)
if PlayerData == nil then return end -- Player not loaded in correctly and dropped early
local time = os.date("%Y-%m-%d %H:%M:%S")
local job = PlayerData.job.name
local firstName = PlayerData.charinfo.firstname:sub(1,1):upper()..PlayerData.charinfo.firstname:sub(2)
local lastName = PlayerData.charinfo.lastname:sub(1,1):upper()..PlayerData.charinfo.lastname:sub(2)
-- Auto clock out if the player is off duty
if IsPoliceOrEms(job) and PlayerData.job.onduty then
MySQL.query.await('UPDATE mdt_clocking SET clock_out_time = NOW(), total_time = TIMESTAMPDIFF(SECOND, clock_in_time, NOW()) WHERE user_id = @user_id ORDER BY id DESC LIMIT 1', {
['@user_id'] = PlayerData.citizenid
})
local result = MySQL.scalar.await('SELECT total_time FROM mdt_clocking WHERE user_id = @user_id', {
['@user_id'] = PlayerData.citizenid
})
if result then
local time_formatted = format_time(tonumber(result))
sendToDiscord(16711680, "MDT Clock-Out", 'Player: **' .. firstName .. " ".. lastName .. '**\n\nJob: **' .. PlayerData.job.name .. '**\n\nRank: **' .. PlayerData.job.grade.name .. '**\n\nStatus: **Off Duty**\n Total time:' .. time_formatted, "ps-mdt | Made by Project Sloth")
end
end
-- Delete player from the MDT on logout
if PlayerData ~= nil then
if GetActiveData(PlayerData.citizenid) then
activeUnits[PlayerData.citizenid] = nil
end
else
local license = QBCore.Functions.GetIdentifier(src, "license")
local citizenids = GetCitizenID(license)
for _, v in pairs(citizenids) do
if GetActiveData(v.citizenid) then
activeUnits[v.citizenid] = nil
end
end
end
end)
RegisterNetEvent("ps-mdt:server:ToggleDuty", function()
local src = source
local player = QBCore.Functions.GetPlayer(src)
if not player.PlayerData.job.onduty then
--// Remove from MDT
if GetActiveData(player.PlayerData.citizenid) then
activeUnits[player.PlayerData.citizenid] = nil
end
end
end)
QBCore.Commands.Add("mdtleaderboard", "Show MDT leaderboard", {}, false, function(source, args)
local PlayerData = GetPlayerData(source)
local job = PlayerData.job.name
if not IsPoliceOrEms(job) then
TriggerClientEvent('QBCore:Notify', source, "You don't have permission to use this command.", 'error')
return
end
local result = MySQL.Sync.fetchAll('SELECT firstname, lastname, total_time FROM mdt_clocking ORDER BY total_time DESC')
local leaderboard_message = '**MDT Leaderboard**\n\n'
for i, record in ipairs(result) do
local firstName = record.firstname:sub(1,1):upper()..record.firstname:sub(2)
local lastName = record.lastname:sub(1,1):upper()..record.lastname:sub(2)
local total_time = format_time(record.total_time)
leaderboard_message = leaderboard_message .. i .. '. **' .. firstName .. ' ' .. lastName .. '** - ' .. total_time .. '\n'
end
sendToDiscord(16753920, "MDT Leaderboard", leaderboard_message, "ps-mdt | Made by Project Sloth")
TriggerClientEvent('QBCore:Notify', source, "MDT leaderboard sent to Discord!", 'success')
end)
RegisterNetEvent("ps-mdt:server:ClockSystem", function()
local src = source
local PlayerData = GetPlayerData(src)
local time = os.date("%Y-%m-%d %H:%M:%S")
local firstName = PlayerData.charinfo.firstname:sub(1,1):upper()..PlayerData.charinfo.firstname:sub(2)
local lastName = PlayerData.charinfo.lastname:sub(1,1):upper()..PlayerData.charinfo.lastname:sub(2)
if PlayerData.job.onduty then
TriggerClientEvent('QBCore:Notify', source, "You're clocked-in", 'success')
MySQL.Async.insert('INSERT INTO mdt_clocking (user_id, firstname, lastname, clock_in_time) VALUES (:user_id, :firstname, :lastname, :clock_in_time) ON DUPLICATE KEY UPDATE user_id = :user_id, firstname = :firstname, lastname = :lastname, clock_in_time = :clock_in_time', {
user_id = PlayerData.citizenid,
firstname = firstName,
lastname = lastName,
clock_in_time = time
}, function()
end)
sendToDiscord(65280, "MDT Clock-In", 'Player: **' .. firstName .. " ".. lastName .. '**\n\nJob: **' .. PlayerData.job.name .. '**\n\nRank: **' .. PlayerData.job.grade.name .. '**\n\nStatus: **On Duty**', "ps-mdt | Made by Project Sloth")
else
TriggerClientEvent('QBCore:Notify', source, "You're clocked-out", 'success')
MySQL.query.await('UPDATE mdt_clocking SET clock_out_time = NOW(), total_time = TIMESTAMPDIFF(SECOND, clock_in_time, NOW()) WHERE user_id = @user_id ORDER BY id DESC LIMIT 1', {
['@user_id'] = PlayerData.citizenid
})
local result = MySQL.scalar.await('SELECT total_time FROM mdt_clocking WHERE user_id = @user_id', {
['@user_id'] = PlayerData.citizenid
})
local time_formatted = format_time(tonumber(result))
sendToDiscord(16711680, "MDT Clock-Out", 'Player: **' .. firstName .. " ".. lastName .. '**\n\nJob: **' .. PlayerData.job.name .. '**\n\nRank: **' .. PlayerData.job.grade.name .. '**\n\nStatus: **Off Duty**\n Total time:' .. time_formatted, "ps-mdt | Made by Project Sloth")
end
end)
RegisterNetEvent('mdt:server:openMDT', function()
local src = source
local PlayerData = GetPlayerData(src)
if not PermCheck(src, PlayerData) then return end
local Radio = Player(src).state.radioChannel or 0
activeUnits[PlayerData.citizenid] = {
cid = PlayerData.citizenid,
callSign = PlayerData.metadata['callsign'],
firstName = PlayerData.charinfo.firstname:sub(1,1):upper()..PlayerData.charinfo.firstname:sub(2),
lastName = PlayerData.charinfo.lastname:sub(1,1):upper()..PlayerData.charinfo.lastname:sub(2),
radio = Radio,
unitType = PlayerData.job.name,
duty = PlayerData.job.onduty
}
local JobType = GetJobType(PlayerData.job.name)
local bulletin = GetBulletins(JobType)
local calls = exports['ps-dispatch']:GetDispatchCalls()
TriggerClientEvent('mdt:client:open', src, bulletin, activeUnits, calls, PlayerData.citizenid)
end)
QBCore.Functions.CreateCallback('mdt:server:SearchProfile', function(source, cb, sentData)
if not sentData then return cb({}) end
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType ~= nil then
local people = MySQL.query.await("SELECT p.citizenid, p.charinfo, md.pfp, md.fingerprint FROM players p LEFT JOIN mdt_data md on p.citizenid = md.cid WHERE LOWER(CONCAT(JSON_VALUE(p.charinfo, '$.firstname'), ' ', JSON_VALUE(p.charinfo, '$.lastname'))) LIKE :query OR LOWER(`charinfo`) LIKE :query OR LOWER(`citizenid`) LIKE :query OR LOWER(md.fingerprint) LIKE :query AND jobtype = :jobtype LIMIT 20", { query = string.lower('%'..sentData..'%'), jobtype = JobType })
local citizenIds = {}
local citizenIdIndexMap = {}
if not next(people) then cb({}) return end
for index, data in pairs(people) do
people[index]['warrant'] = false
people[index]['convictions'] = 0
people[index]['licences'] = GetPlayerLicenses(data.citizenid)
people[index]['pp'] = ProfPic(data.gender, data.pfp)
if data.fingerprint and data.fingerprint ~= "" then
people[index]['fingerprint'] = data.fingerprint
else
people[index]['fingerprint'] = ""
end
citizenIds[#citizenIds+1] = data.citizenid
citizenIdIndexMap[data.citizenid] = index
end
local convictions = GetConvictions(citizenIds)
if next(convictions) then
for _, conv in pairs(convictions) do
if conv.warrant == "1" then people[citizenIdIndexMap[conv.cid]].warrant = true end
local charges = json.decode(conv.charges)
people[citizenIdIndexMap[conv.cid]].convictions = people[citizenIdIndexMap[conv.cid]].convictions + #charges
end
end
TriggerClientEvent('mdt:client:searchProfile', src, people, false)
return cb(people)
end
end
return cb({})
end)
QBCore.Functions.CreateCallback("mdt:server:getWarrants", function(source, cb)
local WarrantData = {}
local data = MySQL.query.await("SELECT * FROM mdt_convictions", {})
for _, value in pairs(data) do
if value.warrant == "1" then
WarrantData[#WarrantData+1] = {
cid = value.cid,
linkedincident = value.linkedincident,
name = GetNameFromId(value.cid),
time = value.time
}
end
end
cb(WarrantData)
end)
QBCore.Functions.CreateCallback('mdt:server:OpenDashboard', function(source, cb)
local PlayerData = GetPlayerData(source)
if not PermCheck(source, PlayerData) then return end
local JobType = GetJobType(PlayerData.job.name)
local bulletin = GetBulletins(JobType)
cb(bulletin)
end)
RegisterNetEvent('mdt:server:NewBulletin', function(title, info, time)
local src = source
local PlayerData = GetPlayerData(src)
if not PermCheck(src, PlayerData) then return end
local JobType = GetJobType(PlayerData.job.name)
local playerName = GetNameFromPlayerData(PlayerData)
local newBulletin = MySQL.insert.await('INSERT INTO `mdt_bulletin` (`title`, `desc`, `author`, `time`, `jobtype`) VALUES (:title, :desc, :author, :time, :jt)', {
title = title,
desc = info,
author = playerName,
time = tostring(time),
jt = JobType
})
AddLog(("A new bulletin was added by %s with the title: %s!"):format(playerName, title))
TriggerClientEvent('mdt:client:newBulletin', -1, src, {id = newBulletin, title = title, info = info, time = time, author = PlayerData.CitizenId}, JobType)
end)
RegisterNetEvent('mdt:server:deleteBulletin', function(id, title)
if not id then return false end
local src = source
local PlayerData = GetPlayerData(src)
if not PermCheck(src, PlayerData) then return end
local JobType = GetJobType(PlayerData.job.name)
MySQL.query.await('DELETE FROM `mdt_bulletin` where id = ?', {id})
AddLog("Bulletin with Title: "..title.." was deleted by " .. GetNameFromPlayerData(PlayerData) .. ".")
end)
QBCore.Functions.CreateCallback('mdt:server:GetProfileData', function(source, cb, sentId)
if not sentId then return cb({}) end
local src = source
local PlayerData = GetPlayerData(src)
if not PermCheck(src, PlayerData) then return cb({}) end
local JobType = GetJobType(PlayerData.job.name)
local target = GetPlayerDataById(sentId)
local JobName = PlayerData.job.name
if not target or not next(target) then return cb({}) end
if type(target.job) == 'string' then target.job = json.decode(target.job) end
if type(target.charinfo) == 'string' then target.charinfo = json.decode(target.charinfo) end
if type(target.metadata) == 'string' then target.metadata = json.decode(target.metadata) end
local licencesdata = target.metadata['licences'] or {
['driver'] = false,
['business'] = false,
['weapon'] = false,
['pilot'] = false
}
local job, grade = UnpackJob(target.job)
local apartmentData = GetPlayerApartment(target.citizenid)
if Config.UsingPsHousing and not Config.UsingDefaultQBApartments then
local propertyData = GetPlayerPropertiesByCitizenId(target.citizenid)
if propertyData and next(propertyData) then
if propertyData[1] then
apartmentData = propertyData[1].apartment .. ' Apt # (' .. propertyData[1].property_id .. ')'
else
TriggerClientEvent("QBCore:Notify", src, 'The citizen does not have a property.', 'error')
print('The citizen does not have a property. Set Config.UsingPsHousing to false.')
end
else
TriggerClientEvent("QBCore:Notify", src, 'The citizen does not have a property.', 'error')
print('The citizen does not have a property. Set Config.UsingPsHousing to false.')
end
elseif Config.UsingDefaultQBApartments then
apartmentData = GetPlayerApartment(target.citizenid)
if apartmentData then
if apartmentData[1] then
apartmentData = apartmentData[1].label .. ' (' ..apartmentData[1].name..')'
else
TriggerClientEvent("QBCore:Notify", src, 'The citizen does not have an apartment.', 'error')
print('The citizen does not have an apartment. Set Config.UsingDefaultQBApartments to false.')
end
else
TriggerClientEvent("QBCore:Notify", src, 'The citizen does not have an apartment.', 'error')
print('The citizen does not have an apartment. Set Config.UsingDefaultQBApartments to false.')
end
end
local person = {
cid = target.citizenid,
firstname = target.charinfo.firstname,
lastname = target.charinfo.lastname,
job = job.label,
grade = grade.name,
apartment = apartmentData,
pp = ProfPic(target.charinfo.gender),
licences = licencesdata,
dob = target.charinfo.birthdate,
fingerprint = target.metadata.fingerprint,
phone = target.charinfo.phone,
mdtinfo = '',
tags = {},
vehicles = {},
properties = {},
gallery = {},
isLimited = false
}
if Config.PoliceJobs[JobName] or Config.DojJobs[JobName] then
local convictions = GetConvictions({person.cid})
local incidents = {}
person.convictions2 = {}
local convCount = 1
if next(convictions) then
for _, conv in pairs(convictions) do
if conv.warrant == "1" then person.warrant = true end
-- Get the incident details
local id = conv.linkedincident
local incident = GetIncidentName(id)
if incident then
incidents[#incidents + 1] = {
id = id,
title = incident.title,
time = conv.time
}
end
local charges = json.decode(conv.charges)
for _, charge in pairs(charges) do
person.convictions2[convCount] = charge
convCount = convCount + 1
end
end
end
person.incidents = incidents
local hash = {}
person.convictions = {}
for _,v in ipairs(person.convictions2) do
if (not hash[v]) then
person.convictions[#person.convictions+1] = v
hash[v] = true
end
end
local vehicles = GetPlayerVehicles(person.cid)
if vehicles then
person.vehicles = vehicles
end
local Coords = {}
local Houses = {}
local properties= GetPlayerProperties(person.cid)
for k, v in pairs(properties) do
Coords[#Coords+1] = {
coords = json.decode(v["coords"]),
}
end
for index = 1, #Coords, 1 do
Houses[#Houses+1] = {
label = properties[index]["label"],
coords = tostring(Coords[index]["coords"]["enter"]["x"]..",".. Coords[index]["coords"]["enter"]["y"].. ",".. Coords[index]["coords"]["enter"]["z"]),
}
end
person.properties = Houses
end
local mdtData = GetPersonInformation(sentId, JobType)
if mdtData then
person.mdtinfo = mdtData.information
person.profilepic = mdtData.pfp
person.tags = json.decode(mdtData.tags)
person.gallery = json.decode(mdtData.gallery)
person.fingerprint = mdtData.fingerprint
print("Fetched fingerprint from mdt_data:", mdtData.fingerprint)
end
return cb(person)
end)
RegisterNetEvent("mdt:server:saveProfile", function(pfp, information, cid, fName, sName, tags, gallery, licenses, fingerprint)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
UpdateAllLicenses(cid, licenses)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'doj' then JobType = 'police' end
MySQL.Async.insert('INSERT INTO mdt_data (cid, information, pfp, jobtype, tags, gallery, fingerprint) VALUES (:cid, :information, :pfp, :jobtype, :tags, :gallery, :fingerprint) ON DUPLICATE KEY UPDATE cid = :cid, information = :information, pfp = :pfp, jobtype = :jobtype, tags = :tags, gallery = :gallery, fingerprint = :fingerprint', {
cid = cid,
information = information,
pfp = pfp,
jobtype = JobType,
tags = json.encode(tags),
gallery = json.encode(gallery),
fingerprint = fingerprint,
}, function()
end)
end
end)
-- Mugshotd
RegisterNetEvent('cqc-mugshot:server:triggerSuspect', function(suspect)
TriggerClientEvent('cqc-mugshot:client:trigger', suspect, suspect)
end)
RegisterNetEvent('psmdt-mugshot:server:MDTupload', function(citizenid, MugShotURLs)
MugShots[citizenid] = MugShotURLs
local cid = citizenid
MySQL.Async.insert('INSERT INTO mdt_data (cid, pfp, gallery, tags) VALUES (:cid, :pfp, :gallery, :tags) ON DUPLICATE KEY UPDATE cid = :cid, pfp = :pfp, tags = :tags, gallery = :gallery', {
cid = cid,
pfp = MugShotURLs[1],
tags = json.encode(tags),
gallery = json.encode(MugShotURLs),
})
end)
RegisterNetEvent("mdt:server:updateLicense", function(cid, type, status)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
if GetJobType(Player.PlayerData.job.name) == 'police' then
ManageLicense(cid, type, status)
end
end
end)
-- Incidents
RegisterNetEvent('mdt:server:getAllIncidents', function()
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'doj' then
local matches = MySQL.query.await("SELECT * FROM `mdt_incidents` ORDER BY `id` DESC LIMIT 30", {})
TriggerClientEvent('mdt:client:getAllIncidents', src, matches)
end
end
end)
RegisterNetEvent('mdt:server:searchIncidents', function(query)
if query then
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'doj' then
local matches = MySQL.query.await("SELECT * FROM `mdt_incidents` WHERE `id` LIKE :query OR LOWER(`title`) LIKE :query OR LOWER(`author`) LIKE :query OR LOWER(`details`) LIKE :query OR LOWER(`tags`) LIKE :query OR LOWER(`officersinvolved`) LIKE :query OR LOWER(`civsinvolved`) LIKE :query OR LOWER(`author`) LIKE :query ORDER BY `id` DESC LIMIT 50", {
query = string.lower('%'..query..'%') -- % wildcard, needed to search for all alike results
})
TriggerClientEvent('mdt:client:getIncidents', src, matches)
end
end
end
end)
RegisterNetEvent('mdt:server:getIncidentData', function(sentId)
if sentId then
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'doj' then
local matches = MySQL.query.await("SELECT * FROM `mdt_incidents` WHERE `id` = :id", {
id = sentId
})
local data = matches[1]
data['tags'] = json.decode(data['tags'])
data['officersinvolved'] = json.decode(data['officersinvolved'])
data['civsinvolved'] = json.decode(data['civsinvolved'])
data['evidence'] = json.decode(data['evidence'])
local convictions = MySQL.query.await("SELECT * FROM `mdt_convictions` WHERE `linkedincident` = :id", {
id = sentId
})
if convictions ~= nil then
for i=1, #convictions do
local res = GetNameFromId(convictions[i]['cid'])
if res ~= nil then
convictions[i]['name'] = res
else
convictions[i]['name'] = "Unknown"
end
convictions[i]['charges'] = json.decode(convictions[i]['charges'])
end
end
TriggerClientEvent('mdt:client:getIncidentData', src, data, convictions)
end
end
end
end)
RegisterNetEvent('mdt:server:getAllBolos', function()
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'ambulance' then
local matches = MySQL.query.await("SELECT * FROM `mdt_bolos` WHERE jobtype = :jobtype", {jobtype = JobType})
TriggerClientEvent('mdt:client:getAllBolos', src, matches)
end
end)
RegisterNetEvent('mdt:server:searchBolos', function(sentSearch)
if sentSearch then
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'ambulance' then
local matches = MySQL.query.await("SELECT * FROM `mdt_bolos` WHERE `id` LIKE :query OR LOWER(`title`) LIKE :query OR `plate` LIKE :query OR LOWER(`owner`) LIKE :query OR LOWER(`individual`) LIKE :query OR LOWER(`detail`) LIKE :query OR LOWER(`officersinvolved`) LIKE :query OR LOWER(`tags`) LIKE :query OR LOWER(`author`) LIKE :query AND jobtype = :jobtype", {
query = string.lower('%'..sentSearch..'%'), -- % wildcard, needed to search for all alike results
jobtype = JobType
})
TriggerClientEvent('mdt:client:getBolos', src, matches)
end
end
end)
RegisterNetEvent('mdt:server:getBoloData', function(sentId)
if sentId then
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'ambulance' then
local matches = MySQL.query.await("SELECT * FROM `mdt_bolos` WHERE `id` = :id AND jobtype = :jobtype LIMIT 1", {
id = sentId,
jobtype = JobType
})
local data = matches[1]
data['tags'] = json.decode(data['tags'])
data['officersinvolved'] = json.decode(data['officersinvolved'])
data['gallery'] = json.decode(data['gallery'])
TriggerClientEvent('mdt:client:getBoloData', src, data)
end
end
end)
RegisterNetEvent('mdt:server:newBolo', function(existing, id, title, plate, owner, individual, detail, tags, gallery, officersinvolved, time)
if id then
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'ambulance' then
local fullname = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
local function InsertBolo()
MySQL.insert('INSERT INTO `mdt_bolos` (`title`, `author`, `plate`, `owner`, `individual`, `detail`, `tags`, `gallery`, `officersinvolved`, `time`, `jobtype`) VALUES (:title, :author, :plate, :owner, :individual, :detail, :tags, :gallery, :officersinvolved, :time, :jobtype)', {
title = title,
author = fullname,
plate = plate,
owner = owner,
individual = individual,
detail = detail,
tags = json.encode(tags),
gallery = json.encode(gallery),
officersinvolved = json.encode(officersinvolved),
time = tostring(time),
jobtype = JobType
}, function(r)
if r then
TriggerClientEvent('mdt:client:boloComplete', src, r)
TriggerEvent('mdt:server:AddLog', "A new BOLO was created by "..fullname.." with the title ("..title..") and ID ("..id..")")
end
end)
end
local function UpdateBolo()
MySQL.update("UPDATE mdt_bolos SET `title`=:title, plate=:plate, owner=:owner, individual=:individual, detail=:detail, tags=:tags, gallery=:gallery, officersinvolved=:officersinvolved WHERE `id`=:id AND jobtype = :jobtype LIMIT 1", {
title = title,
plate = plate,
owner = owner,
individual = individual,
detail = detail,
tags = json.encode(tags),
gallery = json.encode(gallery),
officersinvolved = json.encode(officersinvolved),
id = id,
jobtype = JobType
}, function(r)
if r then
TriggerClientEvent('mdt:client:boloComplete', src, id)
TriggerEvent('mdt:server:AddLog', "A BOLO was updated by "..fullname.." with the title ("..title..") and ID ("..id..")")
end
end)
end
if existing then
UpdateBolo()
elseif not existing then
InsertBolo()
end
end
end
end)
RegisterNetEvent('mdt:server:deleteWeapons', function(id)
if id then
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Config.RemoveWeaponsPerms[Player.PlayerData.job.name] then
if Config.RemoveWeaponsPerms[Player.PlayerData.job.name][Player.PlayerData.job.grade.level] then
local fullName = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
MySQL.update("DELETE FROM `mdt_weaponinfo` WHERE id=:id", { id = id })
TriggerEvent('mdt:server:AddLog', "A Weapon Info was deleted by "..fullName.." with the ID ("..id..")")
else
local fullname = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
TriggerClientEvent("QBCore:Notify", src, 'No Permissions to do that!', 'error')
TriggerEvent('mdt:server:AddLog', fullname.." tryed to delete a Weapon Info with the ID ("..id..")")
end
end
end
end)
RegisterNetEvent('mdt:server:deleteReports', function(id)
if id then
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Config.RemoveReportPerms[Player.PlayerData.job.name] then
if Config.RemoveReportPerms[Player.PlayerData.job.name][Player.PlayerData.job.grade.level] then
local fullName = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
MySQL.update("DELETE FROM `mdt_reports` WHERE id=:id", { id = id })
TriggerEvent('mdt:server:AddLog', "A Report was deleted by "..fullName.." with the ID ("..id..")")
else
local fullname = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
TriggerClientEvent("QBCore:Notify", src, 'No Permissions to do that!', 'error')
TriggerEvent('mdt:server:AddLog', fullname.." tryed to delete a Report with the ID ("..id..")")
end
end
end
end)
RegisterNetEvent('mdt:server:deleteIncidents', function(id)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Config.RemoveIncidentPerms[Player.PlayerData.job.name] then
if Config.RemoveIncidentPerms[Player.PlayerData.job.name][Player.PlayerData.job.grade.level] then
local fullName = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
MySQL.update("DELETE FROM `mdt_convictions` WHERE `linkedincident` = :id", {id = id})
MySQL.update("UPDATE `mdt_convictions` SET `warrant` = '0' WHERE `linkedincident` = :id", {id = id}) -- Delete any outstanding warrants from incidents
MySQL.update("DELETE FROM `mdt_incidents` WHERE id=:id", { id = id }, function(rowsChanged)
if rowsChanged > 0 then
TriggerEvent('mdt:server:AddLog', "A Incident was deleted by "..fullName.." with the ID ("..id..")")
end
end)
else
local fullname = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
TriggerClientEvent("QBCore:Notify", src, 'No Permissions to do that!', 'error')
TriggerEvent('mdt:server:AddLog', fullname.." tried to delete an Incident with the ID ("..id..")")
end
end
end)
RegisterNetEvent('mdt:server:deleteBolo', function(id)
if id then
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' then
local fullname = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
MySQL.update("DELETE FROM `mdt_bolos` WHERE id=:id", { id = id, jobtype = JobType })
TriggerEvent('mdt:server:AddLog', "A BOLO was deleted by "..fullname.." with the ID ("..id..")")
end
end
end)
RegisterNetEvent('mdt:server:deleteICU', function(id)
if id then
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'ambulance' then
local fullname = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
MySQL.update("DELETE FROM `mdt_bolos` WHERE id=:id", { id = id, jobtype = JobType })
TriggerEvent('mdt:server:AddLog', "A ICU Check-in was deleted by "..fullname.." with the ID ("..id..")")
end
end
end)
RegisterNetEvent('mdt:server:incidentSearchPerson', function(query)
if query then
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'doj' or JobType == 'ambulance' then
local function ProfPic(gender, profilepic)
if profilepic then return profilepic end;
if gender == "f" then return "img/female.png" end;
return "img/male.png"
end
local firstname, lastname = query:match("^(%S+)%s*(%S*)$")
firstname = firstname or query
lastname = lastname or query
local result = MySQL.query.await("SELECT p.citizenid, p.charinfo, p.metadata, md.pfp from players p LEFT JOIN mdt_data md on p.citizenid = md.cid WHERE (LOWER(JSON_UNQUOTE(JSON_EXTRACT(`charinfo`, '$.firstname'))) LIKE :firstname AND LOWER(JSON_UNQUOTE(JSON_EXTRACT(`charinfo`, '$.lastname'))) LIKE :lastname) OR LOWER(`citizenid`) LIKE :citizenid AND `jobtype` = :jobtype LIMIT 30", {
firstname = string.lower('%' .. firstname .. '%'),
lastname = string.lower('%' .. lastname .. '%'),
citizenid = string.lower('%' .. query .. '%'),
jobtype = JobType
})
local data = {}
for i=1, #result do
local charinfo = json.decode(result[i].charinfo)
local metadata = json.decode(result[i].metadata)
data[i] = {
id = result[i].citizenid,
firstname = charinfo.firstname,
lastname = charinfo.lastname,
profilepic = ProfPic(charinfo.gender, result[i].pfp),
callsign = metadata.callsign
}
end
TriggerClientEvent('mdt:client:incidentSearchPerson', src, data)
end
end
end
end)
RegisterNetEvent('mdt:server:getAllReports', function()
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'doj' or JobType == 'ambulance' then
if JobType == 'doj' then JobType = 'police' end
local matches = MySQL.query.await("SELECT * FROM `mdt_reports` WHERE jobtype = :jobtype ORDER BY `id` DESC LIMIT 30", {
jobtype = JobType
})
TriggerClientEvent('mdt:client:getAllReports', src, matches)
end
end
end)
RegisterNetEvent('mdt:server:getReportData', function(sentId)
if sentId then
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'doj' or JobType == 'ambulance' then
if JobType == 'doj' then JobType = 'police' end
local matches = MySQL.query.await("SELECT * FROM `mdt_reports` WHERE `id` = :id AND `jobtype` = :jobtype LIMIT 1", {
id = sentId,
jobtype = JobType
})
local data = matches[1]
data['tags'] = json.decode(data['tags'])
data['officersinvolved'] = json.decode(data['officersinvolved'])
data['civsinvolved'] = json.decode(data['civsinvolved'])
data['gallery'] = json.decode(data['gallery'])
TriggerClientEvent('mdt:client:getReportData', src, data)
end
end
end
end)
RegisterNetEvent('mdt:server:searchReports', function(sentSearch)
if sentSearch then
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'doj' or JobType == 'ambulance' then
if JobType == 'doj' then JobType = 'police' end
local matches = MySQL.query.await("SELECT * FROM `mdt_reports` WHERE `id` LIKE :query OR LOWER(`author`) LIKE :query OR LOWER(`title`) LIKE :query OR LOWER(`type`) LIKE :query OR LOWER(`details`) LIKE :query OR LOWER(`tags`) LIKE :query AND `jobtype` = :jobtype ORDER BY `id` DESC LIMIT 50", {
query = string.lower('%'..sentSearch..'%'), -- % wildcard, needed to search for all alike results
jobtype = JobType
})
TriggerClientEvent('mdt:client:getAllReports', src, matches)
end
end
end
end)
RegisterNetEvent('mdt:server:newReport', function(existing, id, title, reporttype, details, tags, gallery, officers, civilians, time)
if id then
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType ~= nil then
local fullname = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
local function InsertReport()
MySQL.insert('INSERT INTO `mdt_reports` (`title`, `author`, `type`, `details`, `tags`, `gallery`, `officersinvolved`, `civsinvolved`, `time`, `jobtype`) VALUES (:title, :author, :type, :details, :tags, :gallery, :officersinvolved, :civsinvolved, :time, :jobtype)', {
title = title,
author = fullname,
type = reporttype,
details = details,
tags = json.encode(tags),
gallery = json.encode(gallery),
officersinvolved = json.encode(officers),
civsinvolved = json.encode(civilians),
time = tostring(time),
jobtype = JobType,
}, function(r)
if r then
TriggerClientEvent('mdt:client:reportComplete', src, r)
TriggerEvent('mdt:server:AddLog', "A new report was created by "..fullname.." with the title ("..title..") and ID ("..id..")")
end
end)
end
local function UpdateReport()
MySQL.update("UPDATE `mdt_reports` SET `title` = :title, type = :type, details = :details, tags = :tags, gallery = :gallery, officersinvolved = :officersinvolved, civsinvolved = :civsinvolved, jobtype = :jobtype WHERE `id` = :id LIMIT 1", {
title = title,
type = reporttype,
details = details,
tags = json.encode(tags),
gallery = json.encode(gallery),
officersinvolved = json.encode(officers),
civsinvolved = json.encode(civilians),
jobtype = JobType,
id = id,
}, function(affectedRows)
if affectedRows > 0 then
TriggerClientEvent('mdt:client:reportComplete', src, id)
TriggerEvent('mdt:server:AddLog', "A report was updated by "..fullname.." with the title ("..title..") and ID ("..id..")")
end
end)
end
if existing then
UpdateReport()
elseif not existing then
InsertReport()
end
end
end
end
end)
QBCore.Functions.CreateCallback('mdt:server:SearchVehicles', function(source, cb, sentData)
if not sentData then return cb({}) end
local src = source
local PlayerData = GetPlayerData(src)
if not PermCheck(source, PlayerData) then return cb({}) end
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'doj' then
local vehicles = MySQL.query.await("SELECT pv.id, pv.citizenid, pv.plate, pv.vehicle, pv.mods, pv.state, p.charinfo FROM `player_vehicles` pv LEFT JOIN players p ON pv.citizenid = p.citizenid WHERE LOWER(`plate`) LIKE :query OR LOWER(`vehicle`) LIKE :query LIMIT 25", {
query = string.lower('%'..sentData..'%')
})
if not next(vehicles) then cb({}) return end
for _, value in ipairs(vehicles) do
if value.state == 0 then
value.state = "Out"
elseif value.state == 1 then
value.state = "Garaged"
elseif value.state == 2 then
value.state = "Impounded"
end
value.bolo = false
local boloResult = GetBoloStatus(value.plate)
if boloResult then
value.bolo = true
end
value.code = false
value.stolen = false
value.image = "img/not-found.webp"
local info = GetVehicleInformation(value.plate)
if info then
value.code = info['code5']
value.stolen = info['stolen']
value.image = info['image']
end
local ownerResult = json.decode(value.charinfo)
value.owner = ownerResult['firstname'] .. " " .. ownerResult['lastname']
end
return cb(vehicles)
end
return cb({})
end
end)