-
Notifications
You must be signed in to change notification settings - Fork 2
/
Policify.lua
2163 lines (1940 loc) · 90.2 KB
/
Policify.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
-- Policify
-- by Hexarobi
-- Turns any vehicle into a police vehicle, with controllable flashing lights and sirens.
-- Save and share your policified vehicles.
-- https://github.com/hexarobi/stand-lua-policify
local SCRIPT_VERSION = "3.3"
local AUTO_UPDATE_BRANCHES = {
{ "main", {}, "More stable, but updated less often.", "main", },
{ "dev", {}, "Cutting edge updates, but less stable.", "dev", },
}
local SELECTED_BRANCH_INDEX = 1
local selected_branch = AUTO_UPDATE_BRANCHES[SELECTED_BRANCH_INDEX][1]
---
--- Auto-Updater Lib Install
---
-- Auto Updater from https://github.com/hexarobi/stand-lua-auto-updater
local status, auto_updater = pcall(require, "auto-updater")
if not status then
local auto_update_complete = nil util.toast("Installing auto-updater...", TOAST_ALL)
async_http.init("raw.githubusercontent.com", "/hexarobi/stand-lua-auto-updater/main/auto-updater.lua",
function(result, headers, status_code)
local function parse_auto_update_result(result, headers, status_code)
local error_prefix = "Error downloading auto-updater: "
if status_code ~= 200 then util.toast(error_prefix..status_code, TOAST_ALL) return false end
if not result or result == "" then util.toast(error_prefix.."Found empty file.", TOAST_ALL) return false end
filesystem.mkdir(filesystem.scripts_dir() .. "lib")
local file = io.open(filesystem.scripts_dir() .. "lib\\auto-updater.lua", "wb")
if file == nil then util.toast(error_prefix.."Could not open file for writing.", TOAST_ALL) return false end
file:write(result) file:close() util.toast("Successfully installed auto-updater lib", TOAST_ALL) return true
end
auto_update_complete = parse_auto_update_result(result, headers, status_code)
end, function() util.toast("Error downloading auto-updater lib. Update failed to download.", TOAST_ALL) end)
async_http.dispatch() local i = 1 while (auto_update_complete == nil and i < 40) do util.yield(250) i = i + 1 end
if auto_update_complete == nil then error("Error downloading auto-updater lib. HTTP Request timeout") end
auto_updater = require("auto-updater")
end
if auto_updater == true then error("Invalid auto-updater lib. Please delete your Stand/Lua Scripts/lib/auto-updater.lua and try again") end
local auto_update_config = {
source_url="https://raw.githubusercontent.com/hexarobi/stand-lua-policify/main/Policify.lua",
script_relpath=SCRIPT_RELPATH,
switch_to_branch=selected_branch,
verify_file_begins_with="--",
check_interval=86400,
}
update_success = auto_updater.run_auto_update(auto_update_config)
util.ensure_package_is_installed('lua/natives-1663599433')
local native_status, natives = pcall(require, "natives-1660775568")
if not native_status then error("Could not natives lib. Make sure it is selected under Stand > Lua Scripts > Repository > natives-1660775568") end
util.ensure_package_is_installed('lua/json')
local json_status, json = pcall(require, "json")
if not json_status then error("Could not load json lib. Make sure it is selected under Stand > Lua Scripts > Repository > json") end
--local status, json = pcall(require, "inspect")
--if not status then error("Could not inspect lib") end
---
--- Config
---
local config = {
flash_delay = 50,
override_paint = true,
override_headlights = true,
override_neon = true,
override_plate = true,
override_horn = true,
override_light_multiplier = 1,
attach_invis_police_siren = true,
plate_text = "FIB",
horn_cycles_siren = true,
siren_status = 1,
siren_attachment = {
name = "Police Cruiser",
model = "police",
},
source_code_branch = "main",
edit_offset_step = 1,
edit_rotation_step = 1,
}
---
--- Data
---
local SIRENS_OFF = 1
local SIRENS_LIGHTS_ONLY = 2
local SIRENS_ALL_ON = 3
local VEHICLE_STORE_DIR = filesystem.store_dir() .. 'Policify\\vehicles\\'
filesystem.mkdirs(VEHICLE_STORE_DIR)
local policified_vehicles = {}
local last_policified_vehicle
--local example_policified_vehicle = {
-- name="Police",
-- model="police",
-- handle=1234,
-- options = {},
-- save_data = {},
-- attachments = {},
--}
--
--local example_attachment = {
-- name="Child #1", -- Name for this attachment
-- handle=5678, -- Handle for this attachment
-- root=example_policified_vehicle,
-- parent=1234, -- Parent Handle
-- bone_index = 0, -- Which bone of the parent should this attach to
-- offset = { x=0, y=0, z=0 }, -- Offset coords from parent
-- rotation = { x=0, y=0, z=0 },-- Rotation from parent
-- children = {
-- -- Other attachments
-- reflection_axis = { x = true, y = false, z = false }, -- Which axis should be reflected about
-- },
-- is_visible = true,
-- has_collision = true,
-- has_gravity = true,
-- is_light_disabled = true, -- If true this light will always be off, regardless of siren settings
--}
local policified_vehicle_base = {
target_version = SCRIPT_VERSION,
children = {},
options = {
override_paint = config.override_paint,
override_headlights = config.override_headlights,
override_neon = config.override_neon,
override_plate = config.override_plate,
override_horn = config.override_horn,
override_light_multiplier = config.override_light_multiplier,
attach_invis_police_siren = config.attach_invis_police_siren,
plate_text = config.plate_text,
siren_attachment = config.siren_attachment,
siren_status = SIRENS_OFF,
},
save_data = {
Horn = nil,
Headlights_Color = nil,
Lights = {
Neon = {
Color = {
r = 0,
g = 0,
b = 0,
},
Left = false,
Right = false,
Front = false,
Back = false
}
},
Livery = {
Style = nil
},
},
}
-- Good props for cop lights
-- prop_air_lights_02a blue
-- prop_air_lights_02b red
-- h4_prop_battle_lights_floorblue
-- h4_prop_battle_lights_floorred
-- prop_wall_light_10a
-- prop_wall_light_10b
-- prop_wall_light_10c
-- hei_prop_wall_light_10a_cr
local available_attachments = {
{
name = "Lights",
objects = {
{
name = "Red Spinning Light",
model = "hei_prop_wall_light_10a_cr",
offset = { x = 0, y = 0, z = 1 },
rotation = { x = 180, y = 0, z = 0 },
is_light_disabled = true,
children = {
{
model = "prop_wall_light_10a",
offset = { x = 0, y = 0.01, z = 0 },
is_light_disabled = false,
bone_index = 1,
},
},
},
{
name = "Blue Spinning Light",
model = "hei_prop_wall_light_10a_cr",
offset = { x = 0, y = 0, z = 1 },
rotation = { x = 180, y = 0, z = 0 },
is_light_disabled = true,
children = {
{
model = "prop_wall_light_10b",
offset = { x = 0, y = 0.01, z = 0 },
is_light_disabled = false,
bone_index = 1,
},
},
},
{
name = "Yellow Spinning Light",
model = "hei_prop_wall_light_10a_cr",
offset = { x = 0, y = 0, z = 1 },
rotation = { x = 180, y = 0, z = 0 },
is_light_disabled = true,
children = {
{
model = "prop_wall_light_10c",
offset = { x = 0, y = 0.01, z = 0 },
is_light_disabled = false,
bone_index = 1,
},
},
},
{
name = "Combo Red+Blue Spinning Light",
model = "hei_prop_wall_light_10a_cr",
offset = { x = 0, y = 0, z = 1 },
rotation = { x = 180, y = 0, z = 0 },
is_light_disabled = true,
children = {
{
model = "prop_wall_light_10b",
offset = { x = 0, y = 0.01, z = 0 },
is_light_disabled = false,
bone_index = 1,
},
{
model = "prop_wall_light_10a",
offset = { x = 0, y = 0.01, z = 0 },
rotation = { x = 0, y = 0, z = 180 },
is_light_disabled = false,
bone_index = 1,
},
},
--reflection = {
-- model = "hei_prop_wall_light_10a_cr",
-- reflection_axis = { x = true, y = false, z = false },
-- is_light_disabled = true,
-- children = {
-- {
-- model = "prop_wall_light_10a",
-- offset = { x = 0, y = 0.01, z = 0 },
-- rotation = { x = 0, y = 0, z = 180 },
-- is_light_disabled = false,
-- bone_index = 1,
-- },
-- },
--}
},
{
name = "Pair of Spinning Lights",
model = "hei_prop_wall_light_10a_cr",
offset = { x = 0.3, y = 0, z = 1 },
rotation = { x = 180, y = 0, z = 0 },
is_light_disabled = true,
children = {
{
model = "prop_wall_light_10b",
offset = { x = 0, y = 0.01, z = 0 },
is_light_disabled = false,
bone_index = 1,
},
{
model = "hei_prop_wall_light_10a_cr",
reflection_axis = { x = true, y = false, z = false },
is_light_disabled = true,
children = {
{
model = "prop_wall_light_10a",
offset = { x = 0, y = 0.01, z = 0 },
rotation = { x = 0, y = 0, z = 180 },
is_light_disabled = false,
bone_index = 1,
},
},
}
},
},
{
name = "Short Spinning Red Light",
model = "hei_prop_wall_alarm_on",
offset = { x = 0, y = 0, z = 1 },
rotation = { x = -90, y = 0, z = 0 },
},
{
name = "Small Red Warning Light",
model = "prop_warninglight_01",
offset = { x = 0, y = 0, z = 1 },
},
{
name = "Blue Recessed Light",
model = "h4_prop_battle_lights_floorblue",
offset = { x = 0, y = 0, z = 0.75 },
},
{
name = "Red Recessed Light",
model = "h4_prop_battle_lights_floorred",
offset = { x = 0, y = 0, z = 0.75 },
},
{
name = "Red/Blue Pair of Recessed Lights",
model = "h4_prop_battle_lights_floorred",
offset = { x = 0.3, y = 0, z = 1 },
children = {
{
model = "h4_prop_battle_lights_floorblue",
reflection_axis = { x = true, y = false, z = false },
}
}
},
{
name = "Blue/Red Pair of Recessed Lights",
model = "h4_prop_battle_lights_floorblue",
offset = { x = 0.3, y = 0, z = 1 },
children = {
{
model = "h4_prop_battle_lights_floorred",
reflection_axis = { x = true, y = false, z = false },
}
}
},
-- Flashing is still kinda wonky for networking
{
name = "Flashing Recessed Lights",
model = "h4_prop_battle_lights_floorred",
offset = { x = 0.3, y = 0, z = 1 },
flash_start_on = false,
children = {
{
model = "h4_prop_battle_lights_floorblue",
reflection_axis = { x = true, y = false, z = false },
flash_start_on = true,
}
}
},
{
name = "Alternating Pair of Recessed Lights",
model = "h4_prop_battle_lights_floorred",
offset = { x = 0.3, y = 0, z = 1 },
flash_start_on = true,
children = {
{
model = "h4_prop_battle_lights_floorred",
reflection_axis = { x = true, y = false, z = false },
flash_start_on = false,
children = {
{
model = "h4_prop_battle_lights_floorblue",
flash_start_on = true,
}
}
},
{
model = "h4_prop_battle_lights_floorblue",
flash_start_on = true,
}
}
},
{
name = "Red Disc Light",
model = "prop_runlight_r",
offset = { x = 0, y = 0, z = 1 },
},
{
name = "Blue Disc Light",
model = "prop_runlight_b",
offset = { x = 0, y = 0, z = 1 },
},
{
name = "Blue Pole Light",
model = "prop_air_lights_02a",
offset = { x = 0, y = 0, z = 1 },
},
{
name = "Red Pole Light",
model = "prop_air_lights_02b",
offset = { x = 0, y = 0, z = 1 },
},
{
name = "Red Angled Light",
model = "prop_air_lights_04a",
offset = { x = 0, y = 0, z = 1 },
},
{
name = "Blue Angled Light",
model = "prop_air_lights_05a",
offset = { x = 0, y = 0, z = 1 },
},
{
name = "Cone Light",
model = "prop_air_conelight",
offset = { x = 0, y = 0, z = 1 },
rotation = { x = 0, y = 0, z = 0 },
},
-- This is actually 2 lights, spaced 20 feet apart.
--{
-- name="Blinking Red Light",
-- model="hei_prop_carrier_docklight_01",
--}
},
},
{
name = "Props",
objects = {
{
name = "Riot Shield",
model = "prop_riot_shield",
rotation = { x = 180, y = 180, z = 0 },
},
{
name = "Ballistic Shield",
model = "prop_ballistic_shield",
rotation = { x = 180, y = 180, z = 0 },
},
{
name = "Minigun",
model = "prop_minigun_01",
rotation = { x = 0, y = 0, z = 90 },
},
{
name = "Monitor Screen",
model = "hei_prop_hei_monitor_police_01",
},
{
name = "Bomb",
model = "prop_ld_bomb_anim",
},
{
name = "Bomb (open)",
model = "prop_ld_bomb_01_open",
},
},
},
{
name = "Vehicles",
objects = {
{
name = "Police Cruiser",
model = "police",
type = "VEHICLE",
},
{
name = "Police Buffalo",
model = "police2",
type = "VEHICLE",
},
{
name = "Police Sports",
model = "police3",
type = "VEHICLE",
},
{
name = "Police Van",
model = "policet",
type = "VEHICLE",
},
{
name = "Police Bike",
model = "policeb",
type = "VEHICLE",
},
{
name = "FIB Cruiser",
model = "fbi",
type = "VEHICLE",
},
{
name = "FIB SUV",
model = "fbi2",
type = "VEHICLE",
},
{
name = "Sheriff Cruiser",
model = "sheriff",
type = "VEHICLE",
},
{
name = "Sheriff SUV",
model = "sheriff2",
type = "VEHICLE",
},
{
name = "Unmarked Cruiser",
model = "police3",
type = "VEHICLE",
},
{
name = "Snowy Rancher",
model = "policeold1",
type = "VEHICLE",
},
{
name = "Snowy Cruiser",
model = "policeold2",
type = "VEHICLE",
},
{
name = "Park Ranger",
model = "pranger",
type = "VEHICLE",
},
{
name = "Riot Van",
model = "rior",
type = "VEHICLE",
},
{
name = "Riot Control Vehicle (RCV)",
model = "riot2",
type = "VEHICLE",
},
},
},
}
local siren_types = {
{ "Police Cruiser", {}, "The standard siren sound from a Police Cruiser", "police", },
{ "Police Bike", {}, "The fast chirp siren sound from a Police Bike", "policeb", },
{ "Ambulance", {}, "The siren sounds from an Ambulance", "ambulance", },
{ "Fire Truck", {}, "The siren sounds from a Fire Truck", "firetruk", },
}
---
--- Utilities
---
function table.table_copy(obj)
if type(obj) ~= 'table' then
return obj
end
local res = setmetatable({}, getmetatable(obj))
for k, v in pairs(obj) do
res[table.table_copy(k)] = table.table_copy(v)
end
return res
end
function string.starts(String,Start)
return string.sub(String,1,string.len(Start))==Start
end
-- From https://stackoverflow.com/questions/12394841/safely-remove-items-from-an-array-table-while-iterating
local function array_remove(t, fnKeep)
local j, n = 1, #t;
for i=1,n do
if (fnKeep(t, i, j)) then
-- Move i's kept value to j's position, if it's not already there.
if (i ~= j) then
t[j] = t[i];
t[i] = nil;
end
j = j + 1; -- Increment position of where we'll place the next kept value.
else
t[i] = nil;
end
end
return t;
end
local function load_hash(hash)
STREAMING.REQUEST_MODEL(hash)
while not STREAMING.HAS_MODEL_LOADED(hash) do
util.yield()
end
end
---
--- Tick Phase
---
local phase_options = {
headlight_colors = {1, 8},
neon_colors = {{r=255,g=0,b=0}, {r=0,g=0,b=255}},
}
local function policify_tick_phase(attachment, phase)
if attachment.root.options.siren_status == SIRENS_LIGHTS_ONLY or attachment.root.options.siren_status == SIRENS_ALL_ON then
if attachment.root.options.override_headlights then
VEHICLE._SET_VEHICLE_XENON_LIGHTS_COLOR(attachment.handle, phase_options.headlight_colors[phase])
end
if attachment.root.options.override_neon then
local neon_color = phase_options.neon_colors[phase]
VEHICLE._SET_VEHICLE_NEON_LIGHTS_COLOUR(attachment.handle, neon_color.r, neon_color.g, neon_color.b)
end
end
if attachment.flash_start_on ~= nil then
local flashing
if phase == 1 then
flashing = attachment.flash_start_on
else
flashing = not attachment.flash_start_on
end
ENTITY.SET_ENTITY_VISIBLE(attachment.handle, flashing, 0)
end
for _, child_attachment in pairs(attachment.children) do
policify_tick_phase(child_attachment, phase)
end
end
local tick_counter = 0
local function policify_tick()
local phase = 1
if tick_counter > config.flash_delay then phase = 2 end
if tick_counter > (config.flash_delay * 2) then tick_counter = 0 end
tick_counter = tick_counter + 1
for _, policified_vehicle in pairs(policified_vehicles) do
policify_tick_phase(policified_vehicle, phase)
end
end
---
--- Specific Serializers
---
local function serialize_vehicle_headlights(vehicle, serialized_vehicle)
if serialized_vehicle.headlights == nil then serialized_vehicle.headlights = {} end
serialized_vehicle.headlights.headlights_color = VEHICLE._GET_VEHICLE_XENON_LIGHTS_COLOR(vehicle.handle)
serialized_vehicle.headlights.headlights_type = VEHICLE.IS_TOGGLE_MOD_ON(vehicle.handle, 22)
return serialized_vehicle
end
local function deserialize_vehicle_headlights(vehicle, serialized_vehicle)
util.log("deserializing "..vehicle.name)
--VEHICLE.SET_VEHICLE_LIGHTS(policified_vehicle.handle, 0) -- Restore full headlight control
VEHICLE._SET_VEHICLE_XENON_LIGHTS_COLOR(vehicle.handle, serialized_vehicle.headlights.headlights_color)
VEHICLE.TOGGLE_VEHICLE_MOD(vehicle.handle, 22, serialized_vehicle.headlights.headlights_type or false)
end
local function serialize_vehicle_paint(vehicle, serialized_vehicle)
if serialized_vehicle.paint == nil then
serialized_vehicle.paint = {
primary = {},
secondary = {},
}
end
-- Create pointers to hold color values
local color = { r = memory.alloc(4), g = memory.alloc(4), b = memory.alloc(4) }
VEHICLE.GET_VEHICLE_COLOR(vehicle, color.r, color.g, color.b)
serialized_vehicle.paint.vehicle_custom_color = { r = memory.read_int(color.r), g = memory.read_int(color.g), b = memory.read_int(color.b) }
VEHICLE.GET_VEHICLE_COLOURS(vehicle, color.r, color.g)
serialized_vehicle.paint.primary.vehicle_standard_color = memory.read_int(color.r)
serialized_vehicle.paint.secondary.vehicle_standard_color = memory.read_int(color.g)
serialized_vehicle.paint.primary.is_custom = VEHICLE.GET_IS_VEHICLE_PRIMARY_COLOUR_CUSTOM(vehicle.handle)
if serialized_vehicle.paint.primary.is_custom then
VEHICLE.GET_VEHICLE_CUSTOM_PRIMARY_COLOUR(vehicle.handle, color.r, color.g, color.b)
serialized_vehicle.paint.primary.custom_color = { r = memory.read_int(color.r), b = memory.read_int(color.g), g = memory.read_int(color.b) }
else
VEHICLE.GET_VEHICLE_MOD_COLOR_1(vehicle.handle, color.r, color.g, color.b)
serialized_vehicle.paint.primary.paint_type = memory.read_int(color.r)
serialized_vehicle.paint.primary.color = memory.read_int(color.g)
serialized_vehicle.paint.primary.pearlescent_color = memory.read_int(color.b)
end
serialized_vehicle.paint.secondary.is_custom = VEHICLE.GET_IS_VEHICLE_SECONDARY_COLOUR_CUSTOM(vehicle.handle)
if serialized_vehicle.paint.secondary.is_custom then
VEHICLE.GET_VEHICLE_CUSTOM_SECONDARY_COLOUR(vehicle.handle, color.r, color.g, color.b)
serialized_vehicle.paint.secondary.custom_color = { r = memory.read_int(color.r), b = memory.read_int(color.g), g = memory.read_int(color.b) }
else
VEHICLE.GET_VEHICLE_MOD_COLOR_2(vehicle.handle, color.r, color.g)
serialized_vehicle.paint.secondary.paint_type = memory.read_int(color.r)
serialized_vehicle.paint.secondary.color = memory.read_int(color.g)
end
VEHICLE.GET_VEHICLE_EXTRA_COLOURS(vehicle.handle, color.r, color.g)
serialized_vehicle.paint.extra_colors = { pearlescent = memory.read_int(color.r), wheel = memory.read_int(color.g) }
VEHICLE._GET_VEHICLE_DASHBOARD_COLOR(vehicle.handle, color.r)
serialized_vehicle.paint.dashboard_color = memory.read_int(color.r)
VEHICLE._GET_VEHICLE_INTERIOR_COLOR(vehicle.handle, color.r)
serialized_vehicle.paint.interior_color = memory.read_int(color.r)
serialized_vehicle.paint.fade = VEHICLE.GET_VEHICLE_ENVEFF_SCALE(vehicle.handle)
serialized_vehicle.paint.dirt_level = VEHICLE.GET_VEHICLE_DIRT_LEVEL(vehicle.handle)
serialized_vehicle.paint.color_combo = VEHICLE.GET_VEHICLE_COLOUR_COMBINATION(vehicle.handle)
-- Livery is also part of mods, but capture it here as well for when just saving paint
serialized_vehicle.paint.livery = VEHICLE.GET_VEHICLE_MOD(vehicle.handle, 48)
--memory.free(color.r) memory.free(color.g) memory.free(color.b)
end
local function deserialize_vehicle_paint(vehicle, serialized_vehicle)
--VEHICLE.SET_VEHICLE_MOD_KIT(vehicle.handle, 0)
VEHICLE.SET_VEHICLE_CUSTOM_PRIMARY_COLOUR(
vehicle,
serialized_vehicle.paint.vehicle_custom_color.r,
serialized_vehicle.paint.vehicle_custom_color.g,
serialized_vehicle.paint.vehicle_custom_color.b
)
VEHICLE.SET_VEHICLE_CUSTOM_SECONDARY_COLOUR(
vehicle,
serialized_vehicle.paint.vehicle_custom_color.r,
serialized_vehicle.paint.vehicle_custom_color.g,
serialized_vehicle.paint.vehicle_custom_color.b
)
VEHICLE.SET_VEHICLE_COLOURS(
vehicle,
serialized_vehicle.paint.primary.vehicle_standard_color or 0,
serialized_vehicle.paint.secondary.vehicle_standard_color or 0
)
if serialized_vehicle.paint.extra_colors then
VEHICLE.SET_VEHICLE_EXTRA_COLOURS(
vehicle.handle,
serialized_vehicle.paint.extra_colors.pearlescent,
serialized_vehicle.paint.extra_colors.wheel
)
end
if serialized_vehicle.paint.primary.is_custom then
VEHICLE.SET_VEHICLE_CUSTOM_PRIMARY_COLOUR(
vehicle.handle,
serialized_vehicle.paint.primary.custom_color.r,
serialized_vehicle.paint.primary.custom_color.g,
serialized_vehicle.paint.primary.custom_color.b
)
else
VEHICLE.SET_VEHICLE_MOD_COLOR_1(
vehicle.handle,
serialized_vehicle.paint.primary.paint_type,
serialized_vehicle.paint.primary.color,
serialized_vehicle.paint.primary.pearlescent_color
)
end
if serialized_vehicle.paint.secondary.is_custom then
VEHICLE.SET_VEHICLE_CUSTOM_SECONDARY_COLOUR(
vehicle.handle,
serialized_vehicle.paint.secondary.custom_color.r,
serialized_vehicle.paint.secondary.custom_color.g,
serialized_vehicle.paint.secondary.custom_color.b
)
else
VEHICLE.SET_VEHICLE_MOD_COLOR_2(
vehicle.handle,
serialized_vehicle.paint.secondary.paint_type,
serialized_vehicle.paint.secondary.color
)
end
VEHICLE._SET_VEHICLE_XENON_LIGHTS_COLOR(vehicle.handle, serialized_vehicle.headlights_color)
VEHICLE._SET_VEHICLE_DASHBOARD_COLOR(vehicle.handle, serialized_vehicle.paint.dashboard_color or -1)
VEHICLE._SET_VEHICLE_INTERIOR_COLOR(vehicle.handle, serialized_vehicle.paint.interior_color or -1)
VEHICLE.SET_VEHICLE_ENVEFF_SCALE(vehicle.handle, serialized_vehicle.paint.fade or 0)
VEHICLE.SET_VEHICLE_DIRT_LEVEL(vehicle.handle, serialized_vehicle.paint.dirt_level or 0.0)
VEHICLE.SET_VEHICLE_COLOUR_COMBINATION(vehicle.handle, serialized_vehicle.paint.color_combo or -1)
VEHICLE.SET_VEHICLE_MOD(vehicle.handle, 48, serialized_vehicle.paint.livery or -1)
end
local function serialize_vehicle_neon(vehicle, serialized_vehicle)
if serialized_vehicle.neon == nil then serialized_vehicle.neon = {} end
serialized_vehicle.neon.lights = {
left = VEHICLE._IS_VEHICLE_NEON_LIGHT_ENABLED(vehicle.handle, 0),
right = VEHICLE._IS_VEHICLE_NEON_LIGHT_ENABLED(vehicle.handle, 1),
front = VEHICLE._IS_VEHICLE_NEON_LIGHT_ENABLED(vehicle.handle, 2),
back = VEHICLE._IS_VEHICLE_NEON_LIGHT_ENABLED(vehicle.handle, 3),
}
local color = { r = memory.alloc(4), g = memory.alloc(4), b = memory.alloc(4) }
if (serialized_vehicle.neon.lights.left or serialized_vehicle.neon.lights.right
or serialized_vehicle.neon.lights.front or serialized_vehicle.neon.lights.back) then
VEHICLE._GET_VEHICLE_NEON_LIGHTS_COLOUR(vehicle.handle, color.r, color.g, color.b)
serialized_vehicle.neon.color = { r = memory.read_int(color.r), g = memory.read_int(color.g), b = memory.read_int(color.b) }
end
--memory.free(color.r) memory.free(color.g) memory.free(color.b)
end
local function deserialize_vehicle_neon(vehicle, serialized_vehicle)
VEHICLE._SET_VEHICLE_NEON_LIGHT_ENABLED(vehicle.handle, 0, serialized_vehicle.neon.lights.left or false)
VEHICLE._SET_VEHICLE_NEON_LIGHT_ENABLED(vehicle.handle, 1, serialized_vehicle.neon.lights.right or false)
VEHICLE._SET_VEHICLE_NEON_LIGHT_ENABLED(vehicle.handle, 2, serialized_vehicle.neon.lights.front or false)
VEHICLE._SET_VEHICLE_NEON_LIGHT_ENABLED(vehicle.handle, 3, serialized_vehicle.neon.lights.back or false)
if serialized_vehicle.neon.color then
VEHICLE._SET_VEHICLE_NEON_LIGHTS_COLOUR(
vehicle.handle,
serialized_vehicle.neon.color.r,
serialized_vehicle.neon.color.g,
serialized_vehicle.neon.color.b
)
end
end
local function serialize_vehicle_wheels(vehicle, serialized_vehicle)
if serialized_vehicle.wheels == nil then serialized_vehicle.wheels = {} end
serialized_vehicle.wheels.type = VEHICLE.GET_VEHICLE_WHEEL_TYPE(vehicle.handle)
local color = { r = memory.alloc(4), g = memory.alloc(4), b = memory.alloc(4) }
VEHICLE.GET_VEHICLE_TYRE_SMOKE_COLOR(vehicle.handle, color.r, color.g, color.b)
serialized_vehicle.wheels.tire_smoke_color = { r = memory.read_int(color.r), g = memory.read_int(color.g), b = memory.read_int(color.b) }
--memory.free(color.r) memory.free(color.g) memory.free(color.b)
end
local function deserialize_vehicle_wheels(vehicle, serialized_vehicle)
VEHICLE.SET_VEHICLE_TYRES_CAN_BURST(vehicle.handle, serialized_vehicle.bulletproof_tires or false)
VEHICLE.SET_VEHICLE_WHEEL_TYPE(vehicle.handle, serialized_vehicle.wheel_type or -1)
if serialized_vehicle.tire_smoke_color then
VEHICLE.SET_VEHICLE_TYRE_SMOKE_COLOR(vehicle.handle, serialized_vehicle.tire_smoke_color.r or 255,
serialized_vehicle.tire_smoke_color.g or 255, serialized_vehicle.tire_smoke_color.b or 255)
end
end
local function serialize_vehicle_mods(vehicle, serialized_vehicle)
if serialized_vehicle.mods == nil then serialized_vehicle.mods = {} end
for mod_index = 0, 49 do
local mod_value
if mod_index >= 17 and mod_index <= 22 then
mod_value = VEHICLE.IS_TOGGLE_MOD_ON(vehicle.handle, mod_index)
else
mod_value = VEHICLE.GET_VEHICLE_MOD(vehicle.handle, mod_index)
end
serialized_vehicle.mods["_"..mod_index] = mod_value
end
end
local function deserialize_vehicle_mods(vehicle, serialized_vehicle)
for mod_index = 0, 49 do
if mod_index >= 17 and mod_index <= 22 then
VEHICLE.TOGGLE_VEHICLE_MOD(vehicle.handle, mod_index, serialized_vehicle.mods["_"..mod_index])
else
VEHICLE.SET_VEHICLE_MOD(vehicle.handle, mod_index, serialized_vehicle.mods["_"..mod_index] or -1)
end
end
end
local function serialize_vehicle_extras(vehicle, serialized_vehicle)
if serialized_vehicle.extras == nil then serialized_vehicle.extras = {} end
for extra_index = 0, 14 do
if VEHICLE.DOES_EXTRA_EXIST(vehicle.handle, extra_index) then
serialized_vehicle.extras["_"..extra_index] = VEHICLE.IS_VEHICLE_EXTRA_TURNED_ON(vehicle.handle, extra_index)
end
end
end
local function deserialize_vehicle_extras(vehicle, serialized_vehicle)
for extra_index = 0, 14 do
local state = true
if serialized_vehicle.extras["_"..extra_index] ~= nil then
state = serialized_vehicle.extras["_"..extra_index]
end
VEHICLE.SET_VEHICLE_EXTRA(vehicle.handle, extra_index, not state)
end
end
local function serialize_vehicle_options(vehicle, serialized_vehicle)
if serialized_vehicle.options == nil then serialized_vehicle.options = {} end
serialized_vehicle.options.headlights_color = VEHICLE._GET_VEHICLE_XENON_LIGHTS_COLOR(vehicle.handle)
serialized_vehicle.options.bulletproof_tires = VEHICLE.GET_VEHICLE_TYRES_CAN_BURST(vehicle.handle)
serialized_vehicle.options.window_tint = VEHICLE.GET_VEHICLE_WINDOW_TINT(vehicle.handle)
serialized_vehicle.options.radio_loud = AUDIO.CAN_VEHICLE_RECEIVE_CB_RADIO(vehicle.handle)
serialized_vehicle.options.engine_running = VEHICLE.GET_IS_VEHICLE_ENGINE_RUNNING(vehicle.handle)
serialized_vehicle.options.siren = VEHICLE.IS_VEHICLE_SIREN_AUDIO_ON(vehicle.handle)
serialized_vehicle.options.emergency_lights = VEHICLE.IS_VEHICLE_SIREN_ON(vehicle.handle)
serialized_vehicle.options.search_light = VEHICLE.IS_VEHICLE_SEARCHLIGHT_ON(vehicle.handle)
serialized_vehicle.options.license_plate_text = VEHICLE.GET_VEHICLE_NUMBER_PLATE_TEXT(vehicle.handle)
serialized_vehicle.options.license_plate_type = VEHICLE.GET_VEHICLE_NUMBER_PLATE_TEXT_INDEX(vehicle.handle)
end
local function deserialize_vehicle_options(vehicle, serialized_vehicle)
if serialized_vehicle.options.siren then
AUDIO.SET_SIREN_WITH_NO_DRIVER(vehicle.handle, true)
VEHICLE.SET_VEHICLE_HAS_MUTED_SIRENS(vehicle.handle, false)
AUDIO._SET_SIREN_KEEP_ON(vehicle.handle, true)
AUDIO._TRIGGER_SIREN(vehicle.handle, true)
end
VEHICLE.SET_VEHICLE_SIREN(vehicle.handle, serialized_vehicle.options.emergency_lights or false)
VEHICLE.SET_VEHICLE_SEARCHLIGHT(vehicle.handle, serialized_vehicle.options.search_light or false, true)
AUDIO.SET_VEHICLE_RADIO_LOUD(vehicle.handle, serialized_vehicle.options.radio_loud or false)
VEHICLE.SET_VEHICLE_NUMBER_PLATE_TEXT(vehicle.handle, serialized_vehicle.options.license_plate_text or "UNKNOWN")
VEHICLE.SET_VEHICLE_NUMBER_PLATE_TEXT_INDEX(vehicle.handle, serialized_vehicle.options.license_plate_type or -1)
if serialized_vehicle.options.engine_running then
VEHICLE.SET_VEHICLE_ENGINE_ON(vehicle.handle, true, true, false)
end
end
---
--- Policify Overrides
---
local function save_headlights(policified_vehicle)
if policified_vehicle.original_vehicle == nil then policified_vehicle.original_vehicle = {} end
serialize_vehicle_headlights(
policified_vehicle,
policified_vehicle.original_vehicle
)
end
local function set_headlights(policified_vehicle)
VEHICLE.SET_VEHICLE_LIGHTS(policified_vehicle.handle, 2)
VEHICLE.TOGGLE_VEHICLE_MOD(policified_vehicle.handle, 22, true)
VEHICLE.SET_VEHICLE_ENGINE_ON(policified_vehicle.handle, true, true, true)
VEHICLE.SET_VEHICLE_LIGHT_MULTIPLIER(policified_vehicle.handle, policified_vehicle.options.override_light_multiplier)
end
local function restore_headlights(policified_vehicle)
deserialize_vehicle_headlights(
policified_vehicle,
policified_vehicle.original_vehicle
)
VEHICLE.SET_VEHICLE_LIGHTS(policified_vehicle.handle, 0)
end
local function save_neon(policified_vehicle)
if policified_vehicle.original_vehicle == nil then policified_vehicle.original_vehicle = {} end
serialize_vehicle_neon(
policified_vehicle,
policified_vehicle.original_vehicle
)
end
local function set_neon(policified_vehicle)
VEHICLE._SET_VEHICLE_NEON_LIGHT_ENABLED(policified_vehicle.handle, 0, true)
VEHICLE._SET_VEHICLE_NEON_LIGHT_ENABLED(policified_vehicle.handle, 1, true)
VEHICLE._SET_VEHICLE_NEON_LIGHT_ENABLED(policified_vehicle.handle, 2, true)
VEHICLE._SET_VEHICLE_NEON_LIGHT_ENABLED(policified_vehicle.handle, 3, true)
end
local function restore_neon(policified_vehicle)
deserialize_vehicle_neon(
policified_vehicle,
policified_vehicle.original_vehicle
)
end
local function save_paint(policified_vehicle)
if policified_vehicle.original_vehicle == nil then policified_vehicle.original_vehicle = {} end
serialize_vehicle_paint(
policified_vehicle,
policified_vehicle.original_vehicle
)
end
local function set_paint(policified_vehicle)
-- Paint matte black
VEHICLE.SET_VEHICLE_CUSTOM_PRIMARY_COLOUR(policified_vehicle.handle, 0, 0, 0)
VEHICLE.SET_VEHICLE_MOD_COLOR_1(policified_vehicle.handle, 3, 0, 0)
VEHICLE.SET_VEHICLE_CUSTOM_SECONDARY_COLOUR(policified_vehicle.handle, 0, 0, 0)
VEHICLE.SET_VEHICLE_MOD_COLOR_2(policified_vehicle.handle, 3, 0, 0)
-- Clear livery
VEHICLE.SET_VEHICLE_MOD(policified_vehicle.handle, 48, -1)
end
local function restore_paint(policified_vehicle)
deserialize_vehicle_paint(
policified_vehicle,
policified_vehicle.original_vehicle
)
end
local function save_horn(policified_vehicle)
if policified_vehicle.original_vehicle == nil then policified_vehicle.original_vehicle = {} end
policified_vehicle.original_vehicle.horn = VEHICLE.GET_VEHICLE_MOD(policified_vehicle.handle, 14)
VEHICLE.SET_VEHICLE_SIREN(policified_vehicle.handle, true)
end
local function set_horn(policified_vehicle)
VEHICLE.SET_VEHICLE_MOD(policified_vehicle.handle, 14, 1)
end
local function restore_horn(policified_vehicle)
VEHICLE.SET_VEHICLE_MOD(policified_vehicle.handle, 14, policified_vehicle.original_vehicle.horn)
VEHICLE.SET_VEHICLE_SIREN(policified_vehicle.handle, false)
end
local function save_plate(policified_vehicle)
if policified_vehicle.original_vehicle == nil then policified_vehicle.original_vehicle = {} end
if policified_vehicle.original_vehicle.options == nil then policified_vehicle.original_vehicle.options = {} end
policified_vehicle.original_vehicle.options.license_plate_text = VEHICLE.GET_VEHICLE_NUMBER_PLATE_TEXT(policified_vehicle.handle)
policified_vehicle.original_vehicle.options.license_plate_type = VEHICLE.GET_VEHICLE_NUMBER_PLATE_TEXT_INDEX(policified_vehicle.handle)
end