forked from hoangducvn/MojiaGarages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.lua
1699 lines (1638 loc) Β· 60 KB
/
client.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
-- Variables
local QBCore = exports['qb-core']:GetCoreObject()
local GarageLocation = {}
local inGarageStation = false
local currentgarage = nil
local nearspawnpoint = nil
local lastjobveh = nil
local OutsideVehicles = {}
local PlayerData = {}
local inJobStation = {}
local hasHouseKey = false
local HouseKeys = {}
local Blips = {}
local PlayerIdentifier = nil
local OutsideVehiclesData = {}
local GlobalVehicles = {}
local SpawnedVehicles = false
local DeletingEntities = false
local UpdateVeh = false
-- Functions
local function GetVehicleModifications(vehicle) --Get all vehicle information
if DoesEntityExist(vehicle) then
local colorPrimary, colorSecondary = GetVehicleColours(vehicle)
local pearlescentColor, wheelColor = GetVehicleExtraColours(vehicle)
local extras = {}
for extraId = 0, 20 do
if DoesExtraExist(vehicle, extraId) then
local state = IsVehicleExtraTurnedOn(vehicle, extraId) == 1
extras[tostring(extraId)] = state
end
end
if GetVehicleMod(vehicle, 48) == -1 and GetVehicleLivery(vehicle) ~= -1 then
modLivery = GetVehicleLivery(vehicle)
else
modLivery = GetVehicleMod(vehicle, 48)
end
local tiresBurst = {}
for id = 0, 5 do
if (IsVehicleTyreBurst(vehicle, id, true)) then
tiresBurst[tostring(id)] = true
elseif (IsVehicleTyreBurst(vehicle, id, false)) then
tiresBurst[tostring(id)] = false
end
end
local windowsBroken = {}
for id = 0, 7 do
if IsVehicleWindowIntact(vehicle, id) then
windowsBroken[tostring(id)] = true
else
windowsBroken[tostring(id)] = false
end
end
local doorsMissing = {}
for id = 0, 5 do
if IsVehicleDoorDamaged(vehicle, id) then
doorsMissing[tostring(id)] = true
else
doorsMissing[tostring(id)] = false
end
end
local hasCustomPrimaryColor = GetIsVehiclePrimaryColourCustom(vehicle)
local customPrimaryColor = nil
if (hasCustomPrimaryColor) then
local r, g, b = GetVehicleCustomPrimaryColour(vehicle)
customPrimaryColor = {
r = r,
g = g,
b = b
}
end
local hasCustomSecondaryColor = GetIsVehicleSecondaryColourCustom(vehicle)
local customSecondaryColor = nil
if (hasCustomSecondaryColor) then
local r, g, b = GetVehicleCustomSecondaryColour(vehicle)
customSecondaryColor = {
r = r,
g = g,
b = b
}
end
return {
model = GetEntityModel(vehicle),
plate = QBCore.Functions.GetPlate(vehicle),
plateIndex = GetVehicleNumberPlateTextIndex(vehicle),
lockstatus = GetVehicleDoorLockStatus(vehicle),
health = QBCore.Shared.Round(GetEntityHealth(vehicle), 0.1),
bodyHealth = QBCore.Shared.Round(GetVehicleBodyHealth(vehicle), 0.1),
engineHealth = QBCore.Shared.Round(GetVehicleEngineHealth(vehicle), 0.1),
tankHealth = QBCore.Shared.Round(GetVehiclePetrolTankHealth(vehicle), 0.1),
fuelLevel = QBCore.Shared.Round(GetVehicleFuelLevel(vehicle), 0.1),
dirtLevel = QBCore.Shared.Round(GetVehicleDirtLevel(vehicle), 0.1),
color1 = colorPrimary,
color2 = colorSecondary,
pearlescentColor = pearlescentColor,
interiorColor = GetVehicleInteriorColor(vehicle),
dashboardColor = GetVehicleDashboardColour(vehicle),
wheelColor = wheelColor,
wheels = GetVehicleWheelType(vehicle),
windowTint = GetVehicleWindowTint(vehicle),
xenonColor = GetVehicleXenonLightsColour(vehicle),
neonEnabled = {
IsVehicleNeonLightEnabled(vehicle, 0),
IsVehicleNeonLightEnabled(vehicle, 1),
IsVehicleNeonLightEnabled(vehicle, 2),
IsVehicleNeonLightEnabled(vehicle, 3)
},
neonColor = table.pack(GetVehicleNeonLightsColour(vehicle)),
extras = extras,
tyreSmokeColor = table.pack(GetVehicleTyreSmokeColor(vehicle)),
modSpoilers = GetVehicleMod(vehicle, 0),
modFrontBumper = GetVehicleMod(vehicle, 1),
modRearBumper = GetVehicleMod(vehicle, 2),
modSideSkirt = GetVehicleMod(vehicle, 3),
modExhaust = GetVehicleMod(vehicle, 4),
modFrame = GetVehicleMod(vehicle, 5),
modGrille = GetVehicleMod(vehicle, 6),
modHood = GetVehicleMod(vehicle, 7),
modFender = GetVehicleMod(vehicle, 8),
modRightFender = GetVehicleMod(vehicle, 9),
modRoof = GetVehicleMod(vehicle, 10),
modEngine = GetVehicleMod(vehicle, 11),
modBrakes = GetVehicleMod(vehicle, 12),
modTransmission = GetVehicleMod(vehicle, 13),
modHorns = GetVehicleMod(vehicle, 14),
modSuspension = GetVehicleMod(vehicle, 15),
modArmor = GetVehicleMod(vehicle, 16),
modTurbo = IsToggleModOn(vehicle, 18),
modSmokeEnabled = IsToggleModOn(vehicle, 20),
modXenon = IsToggleModOn(vehicle, 22),
modFrontWheels = GetVehicleMod(vehicle, 23),
modBackWheels = GetVehicleMod(vehicle, 24),
modCustomTiresF = GetVehicleModVariation(vehicle, 23),
modCustomTiresR = GetVehicleModVariation(vehicle, 24),
modPlateHolder = GetVehicleMod(vehicle, 25),
modVanityPlate = GetVehicleMod(vehicle, 26),
modTrimA = GetVehicleMod(vehicle, 27),
modOrnaments = GetVehicleMod(vehicle, 28),
modDashboard = GetVehicleMod(vehicle, 29),
modDial = GetVehicleMod(vehicle, 30),
modDoorSpeaker = GetVehicleMod(vehicle, 31),
modSeats = GetVehicleMod(vehicle, 32),
modSteeringWheel = GetVehicleMod(vehicle, 33),
modShifterLeavers = GetVehicleMod(vehicle, 34),
modAPlate = GetVehicleMod(vehicle, 35),
modSpeakers = GetVehicleMod(vehicle, 36),
modTrunk = GetVehicleMod(vehicle, 37),
modHydrolic = GetVehicleMod(vehicle, 38),
modEngineBlock = GetVehicleMod(vehicle, 39),
modAirFilter = GetVehicleMod(vehicle, 40),
modStruts = GetVehicleMod(vehicle, 41),
modArchCover = GetVehicleMod(vehicle, 42),
modAerials = GetVehicleMod(vehicle, 43),
modTrimB = GetVehicleMod(vehicle, 44),
modTank = GetVehicleMod(vehicle, 45),
modWindows = GetVehicleMod(vehicle, 46),
modLivery = modLivery,
tiresburst = tiresBurst,
windowsbroken = windowsBroken,
doorsmissing = doorsMissing,
bulletprooftires = not GetVehicleTyresCanBurst(vehicle),
customprimarycolor = customPrimaryColor,
customsecondarycolor = customSecondaryColor,
}
else
return
end
end
local function SetVehicleModifications(vehicle, props)-- Apply all modifications to a vehicle entity
if DoesEntityExist(vehicle) then
SetVehicleModKit(vehicle, 0)
-- plate:
if props.plate then
SetVehicleNumberPlateText(vehicle, props.plate)
end
if props.plateIndex then
SetVehicleNumberPlateTextIndex(vehicle, props.plateIndex)
end
-- lockStatus:
if props.lockstatus then
SetVehicleDoorsLocked(vehicle, props.lockstatus)
end
-- colours:
if props.color1 and props.color2 then
SetVehicleColours(vehicle, props.color1, props.color2)
end
if props.customprimarycolor then
SetVehicleCustomPrimaryColour(vehicle, props.customprimarycolor.r, props.customprimarycolor.g, props.customprimarycolor.b)
end
if props.customsecondarycolor then
SetVehicleCustomSecondaryColour(vehicle, props.customsecondarycolor.r, props.customsecondarycolor.g, props.customsecondarycolor.b)
end
if props.interiorColor then
SetVehicleInteriorColor(vehicle, props.interiorColor)
end
if props.dashboardColor then
SetVehicleDashboardColour(vehicle, props.dashboardColor)
end
if props.pearlescentColor and props.wheelColor then
SetVehicleExtraColours(vehicle, props.pearlescentColor, props.wheelColor)
end
if props.tyreSmokeColor then
SetVehicleTyreSmokeColor(vehicle, props.tyreSmokeColor[1], props.tyreSmokeColor[2], props.tyreSmokeColor[3])
end
-- wheels:
if props.wheels then
SetVehicleWheelType(vehicle, props.wheels)
end
-- windows:
if props.windowTint then
SetVehicleWindowTint(vehicle, props.windowTint)
end
-- neonlight:
if props.neonEnabled then
SetVehicleNeonLightEnabled(vehicle, 0, props.neonEnabled[1])
SetVehicleNeonLightEnabled(vehicle, 1, props.neonEnabled[2])
SetVehicleNeonLightEnabled(vehicle, 2, props.neonEnabled[3])
SetVehicleNeonLightEnabled(vehicle, 3, props.neonEnabled[4])
end
if props.neonColor then
SetVehicleNeonLightsColour(vehicle, props.neonColor[1], props.neonColor[2], props.neonColor[3])
end
-- mods:
if props.modSpoilers then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 0, props.modSpoilers, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 0, props.modSpoilers, false)
end
end
if props.modFrontBumper then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 1, props.modFrontBumper, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 1, props.modFrontBumper, false)
end
end
if props.modRearBumper then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 2, props.modRearBumper, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 2, props.modRearBumper, false)
end
end
if props.modSideSkirt then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 3, props.modSideSkirt, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 3, props.modSideSkirt, false)
end
end
if props.modExhaust then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 4, props.modExhaust, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 4, props.modExhaust, false)
end
end
if props.modFrame then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 5, props.modFrame, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 5, props.modFrame, false)
end
end
if props.modGrille then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 6, props.modGrille, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 6, props.modGrille, false)
end
end
if props.modHood then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 7, props.modHood, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 7, props.modHood, false)
end
end
if props.modFender then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 8, props.modFender, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 8, props.modFender, false)
end
end
if props.modRightFender then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 9, props.modRightFender, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 9, props.modRightFender, false)
end
end
if props.modRoof then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 10, props.modRoof, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 10, props.modRoof, false)
end
end
if props.modEngine then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 11, props.modEngine, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 11, props.modEngine, false)
end
end
if props.modBrakes then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 12, props.modBrakes, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 12, props.modBrakes, false)
end
end
if props.modTransmission then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 13, props.modTransmission, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 13, props.modTransmission, false)
end
end
if props.modHorns then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 14, props.modHorns, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 14, props.modHorns, false)
end
end
if props.modSuspension then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 15, props.modSuspension, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 15, props.modSuspension, false)
end
end
if props.modArmor then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 16, props.modArmor, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 16, props.modArmor, false)
end
end
if props.modTurbo then
ToggleVehicleMod(vehicle, 18, props.modTurbo)
end
if props.modSmokeEnabled then
ToggleVehicleMod(vehicle, 20, props.modSmokeEnabled)
end
if props.modXenon then
ToggleVehicleMod(vehicle, 22, props.modXenon)
end
if props.modFrontWheels then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 23, props.modFrontWheels, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 23, props.modFrontWheels, false)
end
end
if props.modBackWheels then
if props.modCustomTiresR then
SetVehicleMod(vehicle, 24, props.modBackWheels, props.modCustomTiresR)
else
SetVehicleMod(vehicle, 24, props.modBackWheels, false)
end
end
if props.modPlateHolder then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 25, props.modPlateHolder, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 25, props.modPlateHolder, false)
end
end
if props.modVanityPlate then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 26, props.modVanityPlate, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 26, props.modVanityPlate, false)
end
end
if props.modTrimA then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 27, props.modTrimA, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 27, props.modTrimA, false)
end
end
if props.modOrnaments then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 28, props.modOrnaments, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 28, props.modOrnaments, false)
end
end
if props.modDashboard then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 29, props.modDashboard, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 29, props.modDashboard, false)
end
end
if props.modDial then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 30, props.modDial, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 30, props.modDial, false)
end
end
if props.modDoorSpeaker then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 31, props.modDoorSpeaker, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 31, props.modDoorSpeaker, false)
end
end
if props.modSeats then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 32, props.modSeats, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 32, props.modSeats, false)
end
end
if props.modSteeringWheel then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 33, props.modSteeringWheel, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 33, props.modSteeringWheel, false)
end
end
if props.modShifterLeavers then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 34, props.modShifterLeavers, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 34, props.modShifterLeavers, false)
end
end
if props.modAPlate then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 35, props.modAPlate, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 35, props.modAPlate, false)
end
end
if props.modSpeakers then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 36, props.modSpeakers, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 36, props.modSpeakers, false)
end
end
if props.modTrunk then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 37, props.modTrunk, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 37, props.modTrunk, false)
end
end
if props.modHydrolic then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 38, props.modHydrolic, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 38, props.modHydrolic, false)
end
end
if props.modEngineBlock then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 39, props.modEngineBlock, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 39, props.modEngineBlock, false)
end
end
if props.modAirFilter then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 40, props.modAirFilter, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 40, props.modAirFilter, false)
end
end
if props.modStruts then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 41, props.modStruts, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 41, props.modStruts, false)
end
end
if props.modArchCover then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 42, props.modArchCover, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 42, props.modArchCover, false)
end
end
if props.modAerials then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 43, props.modAerials, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 43, props.modAerials, false)
end
end
if props.modTrimB then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 44, props.modTrimB, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 44, props.modTrimB, false)
end
end
if props.modTank then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 45, props.modTank, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 45, props.modTank, false)
end
end
if props.modWindows then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 46, props.modWindows, props.modCustomTiresF)
else
SetVehicleMod(vehicle, 46, props.modWindows, false)
end
end
if props.modLivery then
if props.modCustomTiresF then
SetVehicleMod(vehicle, 48, props.modLivery, props.modCustomTiresF)
SetVehicleLivery(vehicle, props.modLivery)
else
SetVehicleMod(vehicle, 48, props.modLivery, false)
SetVehicleLivery(vehicle, props.modLivery)
end
end
-- extras:
if props.extras then
for id, enabled in pairs(props.extras) do
if enabled then
SetVehicleExtra(vehicle, tonumber(id), 0)
else
SetVehicleExtra(vehicle, tonumber(id), 1)
end
end
end
-- stats:
if props.health then
SetEntityHealth(vehicle, props.health + 0.0)
end
if props.bodyHealth then
SetVehicleBodyHealth(vehicle, props.bodyHealth + 0.0)
end
if props.engineHealth then
SetVehicleEngineHealth(vehicle, props.engineHealth + 0.0)
end
if props.engineHealth and renderScorched and props.engineHealth < -3999.0 then
TriggerServerEvent('MojiaGarages:server:renderScorched', NetworkGetNetworkIdFromEntity(vehicle), true)
end
if props.tankHealth then
SetVehiclePetrolTankHealth(vehicle, props.tankHealth + 0.0)
end
if props.tankHealth and renderScorched and props.tankHealth < -999.0 then
TriggerServerEvent('MojiaGarages:server:renderScorched', NetworkGetNetworkIdFromEntity(vehicle), true)
end
if props.dirtLevel then
SetVehicleDirtLevel(vehicle, props.dirtLevel + 0.0)
end
if props.fuelLevel then
SetVehicleFuelLevel(vehicle, props.fuelLevel + 0.0)
end
-- doors:
if props.doorsmissing then
for id, state in pairs(props.doorsmissing) do
if state then
SetVehicleDoorBroken(vehicle, tonumber(id), state)
end
end
end
-- tires
SetVehicleTyresCanBurst(vehicle, not props.bulletprooftires)
if not props.bulletprooftires and props.tiresburst then
for id, state in pairs(props.tiresburst) do
SetVehicleTyreBurst(vehicle, tonumber(id), state, 1000.0)
end
end
-- windows:
if props.windowsbroken then
for id, state in pairs(props.windowsbroken) do
if not state then
SmashVehicleWindow(vehicle, tonumber(id))
end
end
end
-- xenon lights:
if props.xenonColor then
SetVehicleXenonLightsColor(vehicle, props.xenonColor)
end
end
end
local function GetRotationDifference(r1, r2) -- returns the difference in degrees from the axis with the highest difference
local x = math.abs(r1.x - r2.x)
local y = math.abs(r1.y - r2.y)
local z = math.abs(r1.z - r2.z)
if (x > y and x > z) then
return x
elseif (y > z) then
return y
else
return z
end
end
local function CreateBlip() -- Create Garages blip
if Garages then
for k, v in pairs(Garages) do
if v.showBlip then
if v.job ~= nil then
if PlayerData.job and PlayerData.job.name == v.job or PlayerData.gang and PlayerData.gang.name == v.job then
if not DoesBlipExist(Blips[k]) then
Blips[k] = AddBlipForCoord(v.blippoint)
SetBlipSprite(Blips[k], v.blipsprite)
SetBlipDisplay(Blips[k], 4)
SetBlipScale(Blips[k], v.blipscale)
SetBlipAsShortRange(Blips[k], true)
SetBlipColour(Blips[k], v.blipcolour)
SetBlipAlpha(Blips[k], 0.7)
BeginTextCommandSetBlipName('STRING')
if CustomFont ~= nil then
AddTextComponentString('<font face=\'' .. CustomFont ..'\'>' .. v.label .. '</font>')
else
AddTextComponentString(v.label)
end
EndTextCommandSetBlipName(Blips[k])
end
else
if DoesBlipExist(Blips[k]) then
RemoveBlip(Blips[k])
end
end
else
if v.isHouseGarage then
if HouseKeys[k] then
if not DoesBlipExist(Blips[k]) then
Blips[k] = AddBlipForCoord(v.blippoint)
SetBlipSprite(Blips[k], v.blipsprite)
SetBlipDisplay(Blips[k], 4)
SetBlipScale(Blips[k], v.blipscale)
SetBlipAsShortRange(Blips[k], true)
SetBlipColour(Blips[k], v.blipcolour)
SetBlipAlpha(Blips[k], 0.7)
BeginTextCommandSetBlipName('STRING')
if CustomFont ~= nil then
AddTextComponentString('<font face=\'' .. CustomFont ..'\'>' .. v.label .. '</font>')
else
AddTextComponentString(v.label)
end
EndTextCommandSetBlipName(Blips[k])
end
else
if DoesBlipExist(Blips[k]) then
RemoveBlip(Blips[k])
end
end
else
if not DoesBlipExist(Blips[k]) then
Blips[k] = AddBlipForCoord(v.blippoint)
SetBlipSprite(Blips[k], v.blipsprite)
SetBlipDisplay(Blips[k], 4)
SetBlipScale(Blips[k], v.blipscale)
SetBlipAsShortRange(Blips[k], true)
SetBlipColour(Blips[k], v.blipcolour)
SetBlipAlpha(Blips[k], 0.7)
BeginTextCommandSetBlipName('STRING')
if CustomFont ~= nil then
AddTextComponentString('<font face=\'' .. CustomFont ..'\'>' .. v.label .. '</font>')
else
AddTextComponentString(v.label)
end
EndTextCommandSetBlipName(Blips[k])
end
end
end
else
if DoesBlipExist(Blips[k]) then
RemoveBlip(Blips[k])
end
end
end
end
end
local function IsInGarage() -- Check if the player is in the garage area and if the garage is open for parking
local checkIsingarage, checkCanStoreVehicle = false, false
if inGarageStation and currentgarage ~= nil then
checkIsingarage = true
checkCanStoreVehicle = Garages[currentgarage].canStoreVehicle
end
return checkIsingarage, checkCanStoreVehicle
end
local function isInJobStation(job) -- Check player is in job gagage location or not
return inJobStation[job], lastjobveh
end
local function EnumerateEntitiesWithinDistance(entities, isPlayerEntities, coords, maxDistance)
local nearbyEntities = {}
if coords then
coords = vector3(coords.x, coords.y, coords.z)
else
local playerPed = PlayerPedId()
coords = GetEntityCoords(playerPed)
end
for k, entity in pairs(entities) do
local distance = #(coords - GetEntityCoords(entity))
if distance <= maxDistance then
nearbyEntities[#nearbyEntities+1] = isPlayerEntities and k or entity
end
end
return nearbyEntities
end
local function GetVehiclesInArea(coords, maxDistance) -- Vehicle inspection in designated area
return EnumerateEntitiesWithinDistance(QBCore.Functions.GetVehicles(), false, coords, maxDistance)
end
local function IsSpawnPointClear(coords, maxDistance) -- Check the spawn point to see if it's empty or not:
return #GetVehiclesInArea(coords, maxDistance) == 0
end
local function GetNearSpawnPoint() -- Get nearest spawn point
local near = nil
local distance = 10000
if inGarageStation and currentgarage ~= nil then
for k, v in pairs(Garages[currentgarage].spawnPoint) do
if IsSpawnPointClear(vector3(v.x, v.y, v.z), 2.5) then
local ped = PlayerPedId()
local pos = GetEntityCoords(ped)
local cur_distance = #(pos - vector3(v.x, v.y, v.z))
if cur_distance < distance then
distance = cur_distance
near = k
end
end
end
end
return near
end
local function GetNearJobSpawnPoint() -- Get nearest spawn point for job garage
local near = nil
local distance = 10000
PlayerData = QBCore.Functions.GetPlayerData()
if inGarageStation and inJobStation[PlayerData.job.name] then
for k, v in pairs(JobVeh[PlayerData.job.name][currentgarage].spawnPoint) do
if IsSpawnPointClear(vector3(v.x, v.y, v.z), 2.5) then
local ped = PlayerPedId()
local pos = GetEntityCoords(ped)
local cur_distance = #(pos - vector3(v.x, v.y, v.z))
if cur_distance < distance then
distance = cur_distance
near = k
end
end
end
end
return near
end
local function SetJobVehItems(job) -- Set trunk item for job vehicle
local items = {}
for k, item in pairs(VehJobItems[job]) do
local itemInfo = QBCore.Shared.Items[item.name:lower()]
items[item.slot] = {
name = itemInfo['name'],
amount = tonumber(item.amount),
info = item.info,
label = itemInfo['label'],
description = itemInfo['description'] and itemInfo['description'] or '',
weight = itemInfo['weight'],
type = itemInfo['type'],
unique = itemInfo['unique'],
useable = itemInfo['useable'],
image = itemInfo['image'],
slot = item.slot,
}
end
VehJobItems[job] = items
end
local function Deleteveh(plate) -- Delete the vehicle if it is somewhere outside
local gameVehicles = QBCore.Functions.GetVehicles()
for i = 1, #gameVehicles do
local vehicle = gameVehicles[i]
if DoesEntityExist(vehicle) then
if QBCore.Functions.GetPlate(vehicle) == plate then
QBCore.Functions.DeleteVehicle(vehicle)
end
end
end
end
local function isVehicleExistInRealLife(plate)
local gameVehicles = QBCore.Functions.GetVehicles()
local check = false
for i = 1, #gameVehicles do
local vehicle = gameVehicles[i]
if DoesEntityExist(vehicle) then
if QBCore.Functions.GetPlate(vehicle) == plate then
check = true
end
end
end
return check
end
local function CheckPlayers(vehicle) -- Check if there is someone in the car, if so, get that person out of the car
for i = -1, 5,1 do
seat = GetPedInVehicleSeat(vehicle,i)
if seat ~= 0 then
TaskLeaveVehicle(seat,vehicle,0)
SetVehicleDoorsLocked(vehicle)
Wait(3000)
local networkId = NetworkGetNetworkIdFromEntity(vehicle)
TriggerEvent('MojiaGarages:client:updateVehicle', networkId)
Wait(100)
QBCore.Functions.DeleteVehicle(vehicle)
end
end
end
function GetAllVehicles() -- Returns all loaded vehicles on client side
return QBCore.Functions.GetVehicles()
end
function updateOusiteVehicle()
QBCore.Functions.TriggerCallback('MojiaGarages:server:getOusiteVehicle', function(result)
if result then
for k, v in pairs(result) do
local vehspawned = true
if not isVehicleExistInRealLife(v.plate) then
vehspawned = false
else
vehspawned = true
end
OutsideVehiclesData[v.plate] = {
model = v.vehicle,
vehicle = nil,
position = vector3(v.posX, v.posY, v.posZ),
rotation = vector3(v.rotX, v.rotY, v.rotZ),
mods = json.decode(v.mods),
spawned = vehspawned
}
end
end
end)
end
-- Events
RegisterNetEvent('MojiaGarages:client:spawnOutsiteVehicle', function(properties)
if properties then
if properties.modifications then
if isVehicleExistInRealLife(properties.modifications.plate) then
else
if IsSpawnPointClear(properties.position, 2.5) then
QBCore.Functions.SpawnVehicle(properties.model, function(veh)
SetVehicleModifications(veh, properties.modifications)
SetEntityRotation(veh, properties.rotation)
exports['LegacyFuel']:SetFuel(veh, properties.modifications.fuelLevel)
end, properties.position, true)
else
local vehcheck = QBCore.Functions.GetClosestVehicle(properties.position)
local platecheck = QBCore.Functions.GetPlate(vehcheck)
if vehcheck ~= nil and NetworkGetEntityIsNetworked(vehcheck) and DoesEntityExist(vehcheck) then
QBCore.Functions.TriggerCallback('MojiaGarages:server:checkHasVehicleOwner', function(hasowned)
if hasowned then
else
QBCore.Functions.DeleteVehicle(vehcheck)
end
end, platecheck)
end
end
end
end
end
end)
RegisterNetEvent('MojiaGarages:client:renderScorched', function(vehicleNetId, scorched)
local vehicle = NetworkGetEntityFromNetworkId(vehicleNetId)
if (DoesEntityExist(vehicle)) then
SetEntityRenderScorched(vehicle, scorched)
end
end)
RegisterNetEvent('MojiaGarages:client:setVehicleMods', function(netId, plate, modifications)
local timer = GetGameTimer()
while (not NetworkDoesEntityExistWithNetworkId(netId)) do
Wait(0)
if (GetGameTimer() - 10000 > timer) then
TriggerServerEvent('MojiaGarages:server:setVehicleModsFailed', plate)
return
end
end
local vehicle = NetworkGetEntityFromNetworkId(netId)
if (DoesEntityExist(vehicle) and NetworkHasControlOfEntity(vehicle)) then
SetVehicleModifications(vehicle, modifications)
TriggerServerEvent('MojiaGarages:server:setVehicleModsSuccess', plate)
else
TriggerServerEvent('MojiaGarages:server:setVehicleModsFailed', plate)
end
end)
RegisterNetEvent('MojiaVehicles:client:UpdateVehicleData', function(data, plate)
OutsideVehiclesData[plate] = data
end)
RegisterNetEvent('MojiaGarages:client:updateVehicle', function(netId)
local vehicle = NetworkGetEntityFromNetworkId(netId)
if (vehicle == nil) then
return
end
local plate = QBCore.Functions.GetPlate(vehicle)
if NetworkGetEntityIsNetworked(vehicle) and DoesEntityExist(vehicle) then
QBCore.Functions.TriggerCallback('MojiaGarages:server:checkHasVehicleOwner', function(hasowned)
if hasowned then
QBCore.Functions.TriggerCallback('MojiaGarages:server:getVehicleData', function(VehicleData)
if VehicleData then
local modifications = GetVehicleModifications(vehicle)
local oldmodifications = json.decode(VehicleData.mods)
local vehpos = GetEntityCoords(vehicle)
local vehRot = GetEntityRotation(vehicle)
if modifications then
if oldmodifications then
if (#(vector3(VehicleData.posX, VehicleData.posY, VehicleData.posZ) - vehpos) > 1.0
or GetRotationDifference(vector3(VehicleData.rotX, VehicleData.rotY, VehicleData.rotZ), vehRot) > 15.0
or modifications.lockstatus ~= oldmodifications.lockstatus
or math.abs(modifications.bodyHealth - oldmodifications.bodyHealth) > 5.0
or math.abs(modifications.engineHealth - oldmodifications.engineHealth) > 5.0
or math.abs(modifications.tankHealth - oldmodifications.tankHealth) > 5.0
) then
UpdateVeh = true
local networkId = NetworkGetNetworkIdFromEntity(vehicle)
TriggerServerEvent('MojiaGarages:server:updateVehicle', networkId, plate, modifications)
Wait(100)
UpdateVeh = false
end
else
UpdateVeh = true
local networkId = NetworkGetNetworkIdFromEntity(vehicle)
TriggerServerEvent('MojiaGarages:server:updateVehicle', networkId, plate, modifications)
Wait(100)
UpdateVeh = false
end
end
end
end, plate)
end
end, plate)
end
end)
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() -- Event when player has successfully loaded
TriggerEvent('MojiaGarages:client:DestroyingZone') -- Destroying all zone
Wait(100)
PlayerData = QBCore.Functions.GetPlayerData() -- Reload player information
Wait(100)
TriggerServerEvent('MojiaGarages:server:updateHouseKeys') -- Reload house key information
Wait(100)
TriggerServerEvent('MojiaGarages:server:UpdateGaragesZone') -- Reload garage information
Wait(100)
TriggerServerEvent('MojiaGarages:server:updateOusiteVehicles') -- Reload vehicles information
Wait(100)
CreateBlip() --Reload blips
end)
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function() -- Event when the player has left --Reset all variables
TriggerEvent('MojiaGarages:client:DestroyingZone') -- Destroying all zone
GarageLocation = {}
inGarageStation = false
currentgarage = nil
nearspawnpoint = nil
lastjobveh = nil
OutsideVehicles = {}
PlayerData = {}
inJobStation = {}
hasHouseKey = false
HouseKeys = {}
Blips = {}
end)
AddEventHandler('onResourceStart', function(resource) -- Event when resource is reloaded
if resource == GetCurrentResourceName() then -- Reload player information
TriggerEvent('MojiaGarages:client:DestroyingZone') -- Destroying all zone
Wait(100)
PlayerData = QBCore.Functions.GetPlayerData() -- Reload player information
Wait(100)
TriggerServerEvent('MojiaGarages:server:updateHouseKeys') -- Reload house key information
Wait(100)
TriggerServerEvent('MojiaGarages:server:UpdateGaragesZone') -- Reload garage information
Wait(100)
TriggerServerEvent('MojiaGarages:server:updateOusiteVehicles') -- Reload vehicles information
Wait(100)
CreateBlip() --Reload blips
end