-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathclient.lua
More file actions
936 lines (879 loc) · 31.5 KB
/
Copy pathclient.lua
File metadata and controls
936 lines (879 loc) · 31.5 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
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
local QBCore = exports['qb-core']:GetCoreObject({ 'Functions', 'Shared' })
local PlayerData = QBCore.Functions.GetPlayerData()
local isLoggedIn = LocalPlayer.state['isLoggedIn']
local Config = Config
local canContinue = true
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local lastCoords = playerCoords
local nearbyDoors, closestDoor = {}, {}
local paused = false
local doorData = {}
-- Functions
function Draw3DText(coords, str)
local onScreen, worldX, worldY = World3dToScreen2d(coords.x, coords.y, coords.z)
local camCoords = GetGameplayCamCoord()
local scale = 200 / (GetGameplayCamFov() * #(camCoords - coords))
if onScreen then
SetTextScale(1.0, 0.5 * scale)
SetTextFont(4)
SetTextColour(255, 255, 255, 255)
SetTextEdge(2, 0, 0, 0, 150)
SetTextProportional(1)
SetTextOutline()
SetTextCentre(1)
BeginTextCommandDisplayText('STRING')
AddTextComponentSubstringPlayerName(str)
EndTextCommandDisplayText(worldX, worldY)
end
end
local function raycastWeapon()
local offset = GetOffsetFromEntityInWorldCoords(GetCurrentPedWeaponEntityIndex(playerPed), 0, 0, -0.01)
local direction = GetGameplayCamRot()
direction = vec2(direction.x * math.pi / 180.0, direction.z * math.pi / 180.0)
local num = math.abs(math.cos(direction.x))
direction = vec3((-math.sin(direction.y) * num), (math.cos(direction.y) * num), math.sin(direction.x))
local destination = vec3(offset.x + direction.x * 30, offset.y + direction.y * 30, offset.z + direction.z * 30)
local hit, entityHit, result
local rayHandle = StartShapeTestLosProbe(offset, destination, -1, playerPed, 0)
repeat
result, hit, _, _, entityHit = GetShapeTestResult(rayHandle)
Wait(0)
until result ~= 1
if GetEntityType(entityHit) == 3 then return hit, entityHit else return false, 0 end
end
local function RotationToDirection(rotation)
local adjustedRotation =
{
x = (math.pi / 180) * rotation.x,
y = (math.pi / 180) * rotation.y,
z = (math.pi / 180) * rotation.z
}
local direction =
{
x = -math.sin(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)),
y = math.cos(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)),
z = math.sin(adjustedRotation.x)
}
return direction
end
local function RayCastGamePlayCamera(distance)
local cameraRotation = GetGameplayCamRot()
local cameraCoord = GetGameplayCamCoord()
local direction = RotationToDirection(cameraRotation)
local destination =
{
x = cameraCoord.x + direction.x * distance,
y = cameraCoord.y + direction.y * distance,
z = cameraCoord.z + direction.z * distance
}
local _, hit, endCoords, _, _ = GetShapeTestResult(StartShapeTestRay(cameraCoord.x, cameraCoord.y, cameraCoord.z, destination.x, destination.y, destination.z, -1, PlayerPedId(), 0))
return hit == 1, endCoords
end
local function setTextCoords(data)
local minDimension, maxDimension = GetModelDimensions(data.objName or data.objHash)
local dimensions = maxDimension - minDimension
local dx, dy = tonumber(dimensions.x), tonumber(dimensions.y)
if dy <= -1 or dy >= 1 then dx = dy end
if data.fixText then
return GetOffsetFromEntityInWorldCoords(data.object, dx / 2, 0, 0)
else
return GetOffsetFromEntityInWorldCoords(data.object, -dx / 2, 0, 0)
end
end
local function getTextCoords(door)
if door.setText then return door.textCoords end
return setTextCoords(door)
end
local function loadAnimDict(dict)
RequestAnimDict(dict)
while not HasAnimDictLoaded(dict) do
Wait(0)
end
end
local function displayNUIText(text)
local color = Config.ChangeColor and (closestDoor.data.locked and Config.LockedColor or Config.UnlockedColor) or Config.DefaultColor
SendNUIMessage({
type = 'setDoorText',
enable = true,
text = text,
color = color
})
Wait(1)
end
local function HandleDoorDebug()
if not Config.DoorDebug then return end
CreateThread(function()
while Config.DoorDebug do
if closestDoor.data then
Draw3DText(closestDoor.data.textCoords, closestDoor.data.doorLabel or 'Door Here')
end
Wait(0)
end
end)
end
local function hideNUI()
SendNUIMessage({
type = 'setDoorText',
enable = false
})
Wait(1)
end
local function playSound(door, src, enableSounds)
if not Config.EnableSounds or not enableSounds then return end
local origin
if src and src ~= playerPed then src = NetworkGetEntityFromNetworkId(src) end
if not src then origin = door.textCoords elseif src == playerPed then origin = playerCoords else origin = NetworkGetPlayerCoords(src) end
local distance = #(playerCoords - origin)
if distance < 10 then
if not door.audioLock then
if door.audioRemote then
door.audioLock = { ['file'] = 'button-remote.ogg', ['volume'] = 0.08 }
door.audioUnlock = { ['file'] = 'button-remote.ogg', ['volume'] = 0.08 }
else
door.audioLock = { ['file'] = 'door-bolt-4.ogg', ['volume'] = 0.1 }
door.audioUnlock = { ['file'] = 'door-bolt-4.ogg', ['volume'] = 0.1 }
end
end
local sfx_level = GetProfileSetting(300)
local sound = door.locked and door.audioLock or door.audioUnlock
SendNUIMessage({
type = 'audio',
audio = sound,
distance = distance,
sfx = sfx_level
})
end
end
local function doorAnim()
if not Config.EnableAnimation then return end
CreateThread(function()
loadAnimDict('anim@heists@keycard@')
TaskPlayAnim(playerPed, 'anim@heists@keycard@', 'exit', 8.0, 1.0, -1, 48, 0, 0, 0, 0)
Wait(550)
ClearPedTasks(playerPed)
end)
end
local function updateDoors(specificDoor)
if #(playerCoords - lastCoords) > 30 then Wait(1000) end
playerCoords = GetEntityCoords(playerPed)
for doorID, data in pairs(Config.DoorList) do
if not specificDoor or doorID == specificDoor then
if data.doors then
if not data.doorType then data.doorType = 'double' end
for k, v in pairs(data.doors) do
if #(playerCoords - v.objCoords) < 30 then
if data.doorType == 'doublesliding' then
v.object = GetClosestObjectOfType(v.objCoords.x, v.objCoords.y, v.objCoords.z, 5.0, v.objName or v.objHash, false, false, false)
else
v.object = GetClosestObjectOfType(v.objCoords.x, v.objCoords.y, v.objCoords.z, 1.0, v.objName or v.objHash, false, false, false)
end
if v.object and v.object ~= 0 then
v.doorHash = 'door_' .. doorID .. '_' .. k
if not IsDoorRegisteredWithSystem(v.doorHash) then
local objCoords = GetEntityCoords(v.object)
local objHeading = GetEntityHeading(v.object)
local hasHeading = v.objYaw or v.objHeading or false
if v.objCoords ~= objCoords then v.objCoords = objCoords end -- Backwards compatibility fix
if not hasHeading then
v.objYaw = objHeading
else
if hasHeading ~= objHeading then -- Backwards compatibility fix
v.objYaw = v.objYaw and objHeading or nil
v.objHeading = v.objHeading and objHeading or nil
end
end
AddDoorToSystem(v.doorHash, v.objName or v.objHash, v.objCoords.x, v.objCoords.y, v.objCoords.z, false, false, false)
nearbyDoors[doorID] = true
if data.locked then
DoorSystemSetDoorState(v.doorHash, 4, false, false)
DoorSystemSetDoorState(v.doorHash, 1, false, false)
else
DoorSystemSetDoorState(v.doorHash, 0, false, false)
end
end
end
elseif v.object then
RemoveDoorFromSystem(v.doorHash)
nearbyDoors[doorID] = nil
end
end
elseif not data.doors then
if not data.doorType then data.doorType = 'door' end
if #(playerCoords - data.objCoords) < 30 then
if data.doorType == 'sliding' or data.doorType == 'garage' then
data.object = GetClosestObjectOfType(data.objCoords.x, data.objCoords.y, data.objCoords.z, 5.0, data.objName or data.objHash, false, false, false)
else
data.object = GetClosestObjectOfType(data.objCoords.x, data.objCoords.y, data.objCoords.z, 1.0, data.objName or data.objHash, false, false, false)
end
if data.object and data.object ~= 0 then
data.doorHash = 'door_' .. doorID
if not IsDoorRegisteredWithSystem(data.doorHash) then
local objCoords = GetEntityCoords(data.object)
local objHeading = GetEntityHeading(data.object)
local hasHeading = data.objYaw or data.objHeading or false
if data.objCoords ~= objCoords then data.objCoords = objCoords end -- Backwards compatibility fix
if not hasHeading then
data.objYaw = objHeading
else
if hasHeading ~= objHeading then -- Backwards compatibility fix
data.objYaw = data.objYaw and objHeading or nil
data.objHeading = data.objHeading and objHeading or nil
end
end
data.objCoords = GetEntityCoords(data.object)
AddDoorToSystem(data.doorHash, data.objName or data.objHash, data.objCoords.x, data.objCoords.y, data.objCoords.z, false, false, false)
nearbyDoors[doorID] = true
if data.locked then
DoorSystemSetDoorState(data.doorHash, 4, false, false)
DoorSystemSetDoorState(data.doorHash, 1, false, false)
else
DoorSystemSetDoorState(data.doorHash, 0, false, false)
end
end
end
elseif data.object then
RemoveDoorFromSystem(data.doorHash)
nearbyDoors[doorID] = nil
end
end
-- set text coords
if not data.setText and data.doors then
for k, v in pairs(data.doors) do
if k == 1 and DoesEntityExist(v.object) then
data.textCoords = v.objCoords
elseif k == 2 and DoesEntityExist(v.object) and data.textCoords then
local textDistance = data.textCoords - v.objCoords
data.textCoords = data.textCoords - (textDistance / 2)
data.setText = true
end
if k == 2 and data.textCoords and (data.doorType == 'sliding' or data.doorType == 'garage') then
if GetEntityHeightAboveGround(v.object) < 1 then
data.textCoords = vec3(data.textCoords.x, data.textCoords.y, data.textCoords.z + 1.2)
end
end
end
elseif not data.setText and not data.doors and DoesEntityExist(data.object) then
if data.doorType == 'garage' then
data.textCoords = data.objCoords
data.setText = true
else
data.textCoords = setTextCoords(data)
data.setText = true
end
if data.doorType == 'sliding' or data.doorType == 'garage' then
if GetEntityHeightAboveGround(data.object) < 1 then
data.textCoords = vec3(data.textCoords.x, data.textCoords.y, data.textCoords.z + 1.6)
end
end
end
end
end
lastCoords = playerCoords
end
local function isAuthorized(door)
if door.allAuthorized then return true end
if door.authorizedJobs then
if door.authorizedJobs[PlayerData.job.name] and PlayerData.job.grade.level >= door.authorizedJobs[PlayerData.job.name] then
return true
elseif type(door.authorizedJobs[1]) == 'string' then
for _, job in pairs(door.authorizedJobs) do -- Support for old format
if job == PlayerData.job.name then return true end
end
end
end
if door.authorizedGangs then
if door.authorizedGangs[PlayerData.gang.name] and PlayerData.gang.grade.level >= door.authorizedGangs[PlayerData.gang.name] then
return true
elseif type(door.authorizedGangs[1]) == 'string' then
for _, gang in pairs(door.authorizedGangs) do -- Support for old format
if gang == PlayerData.gang.name then return true end
end
end
end
if door.authorizedCitizenIDs then
if door.authorizedCitizenIDs[PlayerData.citizenid] then
return true
elseif type(door.authorizedCitizenIDs[1]) == 'string' then
for _, id in pairs(door.authorizedCitizenIDs) do -- Support for old format
if id == PlayerData.citizenid then return true end
end
end
end
if door.items then
local p = promise.new()
QBCore.Functions.TriggerCallback('qb-doorlock:server:checkItems', function(result)
p:resolve(result)
end, door.items, door.needsAllItems)
return Citizen.Await(p)
end
return false
end
function SetupDoors()
local p = promise.new()
QBCore.Functions.TriggerCallback('qb-doorlock:server:setupDoors', function(result)
p:resolve(result)
end)
Config.DoorList = Citizen.Await(p)
end
-- Events
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
QBCore.Functions.TriggerCallback('qb-doorlock:server:setupDoors', function(result)
Config.DoorList = result
PlayerData = QBCore.Functions.GetPlayerData()
isLoggedIn = true
end)
end)
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
isLoggedIn = false
PlayerData = {}
end)
RegisterNetEvent('QBCore:Client:OnPlayerUpdated', function(key, val)
if key ~= 'all' then return end
PlayerData = val
end)
RegisterNetEvent('qb-doorlock:client:setState', function(serverId, doorID, state, src, enableSounds, enableAnimation)
if not Config.DoorList[doorID] then return end
if enableAnimation == nil then enableAnimation = true end
if enableSounds == nil then enableSounds = true end
if serverId == PlayerData.source and enableAnimation then doorAnim() end
Config.DoorList[doorID].locked = state
updateDoors(doorID)
local current = Config.DoorList[doorID]
while true do
if current.doors then
if not current.doorType then current.doorType = 'double' end
for k, v in pairs(current.doors) do
if not IsDoorRegisteredWithSystem(v.doorHash) then return end
v.currentHeading = GetEntityHeading(v.object)
v.doorState = DoorSystemGetDoorState(v.doorHash)
if current.doorType == 'doublesliding' then
DoorSystemSetAutomaticRate(v.doorHash, v.doorRate or 1.0, false, false)
if current.locked then
DoorSystemSetDoorState(v.doorHash, 1, false, false)
DoorSystemSetAutomaticDistance(v.doorHash, 0.0, false, false)
if k == 2 then
playSound(current, src, enableSounds)
return
end
else
DoorSystemSetDoorState(v.doorHash, 0, false, false)
DoorSystemSetAutomaticDistance(v.doorHash, 30.0, false, false)
if k == 2 then
playSound(current, src, enableSounds)
return
end
end
elseif current.locked and v.doorState == 4 then
DoorSystemSetDoorState(v.doorHash, 1, false, false)
if current.doors[1].doorState == current.doors[2].doorState then
playSound(current, src, enableSounds)
return
end
elseif not current.locked then
DoorSystemSetDoorState(v.doorHash, 0, false, false)
if current.doors[1].doorState == current.doors[2].doorState then
playSound(current, src, enableSounds)
return
end
else
if QBCore.Shared.Round(v.currentHeading, 0) == QBCore.Shared.Round(v.objYaw or v.objHeading, 0) then
DoorSystemSetDoorState(v.doorHash, 4, false, false)
end
end
end
else
if not IsDoorRegisteredWithSystem(current.doorHash) then return end
if not current.doorType then current.doorType = 'door' end
current.currentHeading = GetEntityHeading(current.object)
current.doorState = DoorSystemGetDoorState(current.doorHash)
if current.doorType == 'sliding' or current.doorType == 'garage' then
DoorSystemSetAutomaticRate(current.doorHash, current.doorRate or 1.0, false, false)
if current.locked then
DoorSystemSetDoorState(current.doorHash, 1, false, false)
DoorSystemSetAutomaticDistance(current.doorHash, 0.0, false, false)
playSound(current, src, enableSounds)
return
else
DoorSystemSetDoorState(current.doorHash, 0, false, false)
DoorSystemSetAutomaticDistance(current.doorHash, 30.0, false, false)
playSound(current, src, enableSounds)
return
end
elseif current.locked and current.doorState == 4 then
DoorSystemSetDoorState(current.doorHash, 1, false, false)
playSound(current, src, enableSounds)
return
elseif not current.locked then
DoorSystemSetDoorState(current.doorHash, 0, false, false)
playSound(current, src, enableSounds)
return
else
if QBCore.Shared.Round(current.currentHeading, 0) == QBCore.Shared.Round(current.objYaw or current.objHeading, 0) then
DoorSystemSetDoorState(current.doorHash, 4, false, false)
end
end
end
Wait(0)
end
end)
RegisterNetEvent('lockpicks:UseLockpick', function(isAdvanced)
if not closestDoor.data or not next(closestDoor.data) or PlayerData.metadata['isdead'] or PlayerData.metadata['ishandcuffed'] or (not closestDoor.data.pickable and not closestDoor.data.lockpick) or not closestDoor.data.locked then
return
end
local difficulty = isAdvanced and 'easy' or 'medium' -- Use 'easy' difficulty for advanced lockpicks, medium for others
local success = exports['qb-minigames']:Skillbar(difficulty)
if success then
QBCore.Functions.Notify(Lang:t('success.lockpick_success'), 'success', 2500)
-- Determine which coordinates to face based on door data
local coordsToFace = closestDoor.data.doors and closestDoor.data.doors[1].objCoords or closestDoor.data.objCoords
TaskTurnPedToFaceCoord(playerPed, coordsToFace.x, coordsToFace.y, coordsToFace.z, 0)
-- Wait for the ped to turn towards the door
Wait(300)
local count = 0
while GetIsTaskActive(playerPed, 225) and count < 150 do
Wait(10)
count = count + 1
end
Wait(1800)
-- Unlock the door
TriggerServerEvent('qb-doorlock:server:updateState', closestDoor.id, false, false, true, false)
else
QBCore.Functions.Notify(Lang:t('error.lockpick_fail'), 'error', 2500)
if isAdvanced then
local chanceToRemove = math.random(1, 100) <= 17
if chanceToRemove then
TriggerServerEvent('qb-doorlock:server:removeLockpick', 'advancedlockpick')
TriggerEvent('qb-inventory:client:ItemBox', QBCore.Shared.Items['advancedlockpick'], 'remove')
end
else
TriggerServerEvent('qb-doorlock:server:removeLockpick', 'lockpick')
TriggerEvent('qb-inventory:client:ItemBox', QBCore.Shared.Items['lockpick'], 'remove')
end
end
end)
RegisterNetEvent('qb-doorlock:client:addNewDoor', function()
canContinue = false
hideNUI()
if not Config.SaveDoorDialog then doorData = {} end
local dialog = exports['qb-input']:ShowInput({
header = Lang:t('general.newdoor_menu_title'),
submitText = Lang:t('general.submit_text'),
inputs = {
{
text = Lang:t('general.configfile_title'),
name = 'configfile',
type = 'text',
isRequired = true,
default = Config.SaveDoorDialog and doorData.configfile,
},
{
text = Lang:t('general.dooridentifier_title'),
name = 'dooridentifier',
type = 'text',
isRequired = true,
default = Config.SaveDoorDialog and doorData.dooridentifier,
},
{
text = Lang:t('general.doorlabel_title'),
name = 'doorlabel',
type = 'text',
isRequired = false,
default = Config.SaveDoorDialog and doorData.doorlabel,
},
{
text = Lang:t('general.doortype_title'),
name = 'doortype',
type = 'select',
options = {
{ value = 'door', text = Lang:t('general.doortype_door') },
{ value = 'double', text = Lang:t('general.doortype_double') },
{ value = 'sliding', text = Lang:t('general.doortype_sliding') },
{ value = 'doublesliding', text = Lang:t('general.doortype_doublesliding') },
{ value = 'garage', text = Lang:t('general.doortype_garage') }
},
default = Config.SaveDoorDialog and doorData.doortype,
},
{
text = Lang:t('general.job_authorisation_menu'),
name = 'job',
type = 'text',
isRequired = false,
default = Config.SaveDoorDialog and doorData.job,
},
{
text = Lang:t('general.jobGrade_authorisation_menu'),
name = 'jobGrade',
type = 'number',
isRequired = false,
default = Config.SaveDoorDialog and doorData.jobGrade,
},
{
text = Lang:t('general.gang_authorisation_menu'),
name = 'gang',
type = 'text',
isRequired = false,
default = Config.SaveDoorDialog and doorData.gang,
},
{
text = Lang:t('general.gangGrade_authorisation_menu'),
name = 'gangGrade',
type = 'number',
isRequired = false,
default = Config.SaveDoorDialog and doorData.gangGrade,
},
{
text = Lang:t('general.citizenid_authorisation_menu'),
name = 'cid',
type = 'text',
isRequired = false,
default = Config.SaveDoorDialog and doorData.cid,
},
{
text = Lang:t('general.item_authorisation_menu'),
name = 'item',
type = 'text',
isRequired = false,
default = Config.SaveDoorDialog and doorData.item,
},
{
text = Lang:t('general.distance_menu'),
name = 'distance',
type = 'number',
isRequired = true,
default = Config.SaveDoorDialog and doorData.distance,
},
{
text = '',
name = 'checklock',
type = 'checkbox',
options = {
{ value = 'locked', text = Lang:t('general.locked_menu'), checked = (Config.SaveDoorDialog and doorData.locked) },
{ value = 'pickable', text = Lang:t('general.pickable_menu'), checked = (Config.SaveDoorDialog and doorData.pickable == 'true') },
{ value = 'cantunlock', text = Lang:t('general.cantunlock_menu'), checked = (Config.SaveDoorDialog and doorData.cantunlock == 'true') },
{ value = 'hidelabel', text = Lang:t('general.hidelabel_menu'), checked = (Config.SaveDoorDialog and doorData.hidelabel == 'true') },
}
}
}
})
if not dialog or not next(dialog) then
canContinue = true
return
end
doorData = dialog
local identifier = doorData.configfile .. '-' .. doorData.dooridentifier
if Config.DoorList[identifier] then
QBCore.Functions.Notify((Lang:t('error.door_identifier_exists')):format(identifier), 'error')
canContinue = true
return
end
if doorData.configfile == '' then doorData.configfile = false end
if doorData.job == '' then doorData.job = false end
if doorData.jobGrade == '' then doorData.jobGrade = nil end
if doorData.gang == '' then doorData.gang = false end
if doorData.gangGrade == '' then doorData.gangGrade = nil end
if doorData.cid == '' then doorData.cid = false end
if doorData.item == '' then doorData.item = false end
if doorData.doorlabel == '' then doorData.doorlabel = nil end
if doorData.pickable ~= 'true' then doorData.pickable = nil end
if doorData.cantunlock ~= 'true' then doorData.cantunlock = nil end
if doorData.hidelabel ~= 'true' then doorData.hidelabel = nil end
doorData.locked = doorData.locked == 'true'
doorData.distance = tonumber(doorData.distance)
if doorData.doortype == 'door' or doorData.doortype == 'sliding' or doorData.doortype == 'garage' then
SendNUIMessage({
type = 'setText',
aim = 'block'
})
local heading, result, entityHit
local entity, coords, model = 0, 0, 0
while true do
if IsPlayerFreeAiming(PlayerId()) then
result, entityHit = raycastWeapon()
if result and entityHit ~= entity then
SetEntityDrawOutline(entity, false)
SetEntityDrawOutline(entityHit, true)
entity = entityHit
coords = GetEntityCoords(entity)
model = GetEntityModel(entity)
heading = GetEntityHeading(entity)
SendNUIMessage({
type = 'setText',
aim = 'none',
details = 'block',
coords = coords,
heading = heading,
hash = model
})
end
if entity and IsControlPressed(0, 24) then break end
end
Wait(0)
end
SetEntityDrawOutline(entity, false)
SendNUIMessage({
type = 'setText',
aim = 'none',
details = 'none',
coords = '',
heading = '',
hash = ''
})
if not model or model == 0 then
QBCore.Functions.Notify(Lang:t('error.door_not_found'), 'error')
canContinue = true
return
end
result = DoorSystemFindExistingDoor(coords.x, coords.y, coords.z, model)
if result then
QBCore.Functions.Notify(Lang:t('error.door_registered'), 'error')
canContinue = true
return
end
doorData.doorHash = 'door_' .. doorData.dooridentifier
AddDoorToSystem(doorData.doorHash, model, coords, false, false, false)
DoorSystemSetDoorState(doorData.doorHash, 4, false, false)
coords = GetEntityCoords(entity)
heading = GetEntityHeading(entity)
RemoveDoorFromSystem(doorData.doorHash)
doorData.entity = entity
doorData.coords = coords
doorData.model = model
doorData.heading = heading
TriggerServerEvent('qb-doorlock:server:saveNewDoor', doorData, false)
canContinue = true
else
local result, entityHit
local entity, coords, heading, model = { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }
for i = 1, 2 do
SendNUIMessage({
type = 'setText',
aim = 'block',
details = 'none',
coords = '',
heading = '',
hash = ''
})
while true do
if IsPlayerFreeAiming(PlayerId()) then
result, entityHit = raycastWeapon()
if result and entityHit ~= entity[i] then
SetEntityDrawOutline(entity[i], false)
SetEntityDrawOutline(entityHit, true)
entity[i] = entityHit
coords[i] = GetEntityCoords(entity[i])
model[i] = GetEntityModel(entity[i])
heading[i] = GetEntityHeading(entity[i])
SendNUIMessage({
type = 'setText',
aim = 'none',
details = 'block',
coords = coords[i],
heading = heading[i],
hash = model[i]
})
end
if entity[i] and IsControlPressed(0, 24) then break end
end
Wait(0)
end
Wait(200)
end
SetEntityDrawOutline(entity[1], false)
SetEntityDrawOutline(entity[2], false)
SendNUIMessage({
type = 'setText',
aim = 'none',
details = 'none',
coords = '',
heading = '',
hash = ''
})
if not model[1] or model[1] == 0 or not model[2] or model[2] == 0 then
QBCore.Functions.Notify(Lang:t('error.door_not_found'), 'error')
return
end
if entity[1] == entity[2] then
QBCore.Functions.Notify(Lang:t('error.same_entity'), 'error')
canContinue = true
return
end
doorData.doorHash = {}
for i = 1, 2 do
result = DoorSystemFindExistingDoor(coords[i].x, coords[i].y, coords[i].z, model[i])
if result then
QBCore.Functions.Notify(Lang:t('error.door_registered'), 'error')
canContinue = true
return
end
doorData.doorHash[i] = 'door_' .. doorData.dooridentifier .. '_' .. i
AddDoorToSystem(doorData.doorHash[i], model[i], coords[i], false, false, false)
DoorSystemSetDoorState(doorData.doorHash[i], 4, false, false)
coords[i] = GetEntityCoords(entity[i])
heading[i] = GetEntityHeading(entity[i])
RemoveDoorFromSystem(doorData.doorHash[i])
end
doorData.entity = entity
doorData.coords = coords
doorData.model = model
doorData.heading = heading
TriggerServerEvent('qb-doorlock:server:saveNewDoor', doorData, true)
canContinue = true
end
end)
RegisterNetEvent('qb-doorlock:client:newDoorAdded', function(data, id, creatorSrc)
Config.DoorList[id] = data
TriggerEvent('qb-doorlock:client:setState', creatorSrc, id, data.locked, false, true, true)
end)
RegisterNetEvent('qb-doorlock:client:ToggleDoorDebug', function()
Config.DoorDebug = not Config.DoorDebug
HandleDoorDebug()
end)
-- Commands
RegisterCommand('toggledoorlock', function()
if not closestDoor.data or not next(closestDoor.data) then return end
local distanceCheck = closestDoor.distance > (closestDoor.data.distance or closestDoor.data.maxDistance)
local unlockableCheck = (closestDoor.data.cantUnlock and closestDoor.data.locked)
local busyCheck = PlayerData.metadata['isdead'] or PlayerData.metadata['inlaststand'] or PlayerData.metadata['ishandcuffed']
if distanceCheck or unlockableCheck or busyCheck then return end
playerPed = PlayerPedId()
local veh = GetVehiclePedIsIn(playerPed)
if veh then
CreateThread(function()
local siren = IsVehicleSirenOn(veh)
for _ = 0, 100 do
DisableControlAction(0, 86, true)
SetHornEnabled(veh, false)
if not siren then SetVehicleSiren(veh, false) end
Wait(0)
end
SetHornEnabled(veh, true)
end)
end
local locked = not closestDoor.data.locked
local src = false
if closestDoor.data.audioRemote then src = NetworkGetNetworkIdFromEntity(playerPed) end
TriggerServerEvent('qb-doorlock:server:updateState', closestDoor.id, locked, src, false, false, true, true) -- Broadcast new state of the door to everyone
end, false)
TriggerEvent('chat:removeSuggestion', '/toggledoorlock')
RegisterKeyMapping('toggledoorlock', Lang:t('general.keymapping_description'), 'keyboard', 'E')
RegisterCommand('remotetriggerdoor', function()
local hit, raycastCoords = RayCastGamePlayCamera(Config.RemoteTriggerDistance)
if not hit then return end
local nearestDoor = nil
for k in pairs(nearbyDoors) do
local door = Config.DoorList[k]
local canTrigger = door.remoteTrigger
local distance = #(raycastCoords - getTextCoords(door))
if canTrigger and (not nearestDoor or distance < nearestDoor.distance) and distance < math.max(door.distance, Config.RemoteTriggerMinDistance) then
nearestDoor = {
data = door,
id = k,
distance = distance
}
end
end
if not nearestDoor then return end
local unlockableCheck = (nearestDoor.data.cantUnlock and nearestDoor.data.locked)
local busyCheck = PlayerData.metadata['isdead'] or PlayerData.metadata['inlaststand'] or PlayerData.metadata['ishandcuffed']
if unlockableCheck or busyCheck then return end
playerPed = PlayerPedId()
local veh = GetVehiclePedIsIn(playerPed)
if veh then
CreateThread(function()
for _ = 0, 100 do
DisableControlAction(0, 74, true)
Wait(0)
end
end)
end
TriggerServerEvent('qb-doorlock:server:updateState', nearestDoor.id, not nearestDoor.data.locked, NetworkGetNetworkIdFromEntity(playerPed), false, false, true, true) -- Broadcast new state of the door to everyone
end, false)
TriggerEvent('chat:removeSuggestion', '/remotetriggerdoor')
RegisterKeyMapping('remotetriggerdoor', Lang:t('general.keymapping_remotetriggerdoor'), 'keyboard', 'H')
-- Threads
CreateThread(function()
if Config.PersistentDoorStates and isLoggedIn then
Wait(1000)
SetupDoors()
end -- Required for pulling in door states properly from live ensures
updateDoors()
HandleDoorDebug()
while true do
local sleep = 100
if isLoggedIn and canContinue then
playerPed = PlayerPedId()
playerCoords = GetEntityCoords(playerPed)
if not closestDoor.id then
local distance = #(playerCoords - lastCoords)
if distance > 15 then
updateDoors()
sleep = 1000
else
for k in pairs(nearbyDoors) do
local door = Config.DoorList[k]
if door.setText and door.textCoords then
distance = #(playerCoords - door.textCoords)
if distance < (closestDoor.distance or 15) then
if distance < (door.distance or door.maxDistance) then
closestDoor = { distance = distance, id = k, data = door }
sleep = 0
end
end
end
end
end
end
if closestDoor.id then
while isLoggedIn do
if not paused and IsPauseMenuActive() then
hideNUI()
paused = true
elseif paused then
if not IsPauseMenuActive() then paused = false end
else
playerCoords = GetEntityCoords(playerPed)
closestDoor.distance = #(closestDoor.data.textCoords - playerCoords)
if closestDoor.distance < (closestDoor.data.distance or closestDoor.data.maxDistance) then
local authorized = isAuthorized(closestDoor.data)
local displayText = ''
if not closestDoor.data.hideLabel and Config.UseDoorLabelText and closestDoor.data.doorLabel then
displayText = closestDoor.data.doorLabel
else
if not closestDoor.data.locked and not authorized then
displayText = Lang:t('general.unlocked')
elseif not closestDoor.data.locked and authorized then
displayText = Lang:t('general.unlocked_button')
elseif closestDoor.data.locked and not authorized then
displayText = Lang:t('general.locked')
elseif closestDoor.data.locked and authorized then
displayText = Lang:t('general.locked_button')
end
end
if displayText ~= '' and (closestDoor.data.hideLabel == nil or not closestDoor.data.hideLabel) then displayNUIText(displayText) end
else
hideNUI()
break
end
end
Wait(100)
end
closestDoor = {}
sleep = 0
end
end
Wait(sleep)
end
end)
exports('GetClosestDoor', function()
return closestDoor
end)
exports('GetNearbyDoors', function()
return nearbyDoors
end)
exports('GetDoorList', function()
return Config.DoorList
end)
exports('GetDoorStates', function()
return Config.DoorStates
end)