-
-
Notifications
You must be signed in to change notification settings - Fork 239
/
client.lua
1416 lines (1211 loc) · 40.9 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
local GetEntityCoords = GetEntityCoords
local Wait = Wait
local IsDisabledControlPressed = IsDisabledControlPressed
local GetEntityBoneIndexByName = GetEntityBoneIndexByName
local GetWorldPositionOfEntityBone = GetWorldPositionOfEntityBone
local SetPauseMenuActive = SetPauseMenuActive
local DisableAllControlActions = DisableAllControlActions
local EnableControlAction = EnableControlAction
local NetworkGetEntityIsNetworked = NetworkGetEntityIsNetworked
local NetworkGetNetworkIdFromEntity = NetworkGetNetworkIdFromEntity
local GetEntityModel = GetEntityModel
local IsPedAPlayer = IsPedAPlayer
local GetEntityType = GetEntityType
local PlayerPedId = PlayerPedId
local GetShapeTestResult = GetShapeTestResult
local StartShapeTestLosProbe = StartShapeTestLosProbe
local SetDrawOrigin = SetDrawOrigin
local DrawSprite = DrawSprite
local ClearDrawOrigin = ClearDrawOrigin
local HasStreamedTextureDictLoaded = HasStreamedTextureDictLoaded
local RequestStreamedTextureDict = RequestStreamedTextureDict
local HasEntityClearLosToEntity = HasEntityClearLosToEntity
local currentResourceName = GetCurrentResourceName()
local Config, Types, Players, Entities, Models, Zones, nuiData, sendData, sendDistance = Config, { {}, {}, {} }, {}, {},
{}, {}, {}, {}, {}
local playerPed, targetActive, hasFocus, success, pedsReady, allowTarget = PlayerPedId(), false, false, false, false,
true
local screen = {}
local table_wipe = table.wipe
local pairs = pairs
local pcall = pcall
local CheckOptions = CheckOptions
local Bones = Load('bones')
local listSprite = {}
---------------------------------------
--- Source: https://github.com/citizenfx/lua/blob/luaglm-dev/cfx/libs/scripts/examples/scripting_gta.lua
--- Credits to gottfriedleibniz
local glm = require 'glm'
-- Cache common functions
local glm_rad = glm.rad
local glm_quatEuler = glm.quatEulerAngleZYX
local glm_rayPicking = glm.rayPicking
-- Cache direction vectors
local glm_up = glm.up()
local glm_forward = glm.forward()
local function ScreenPositionToCameraRay()
local pos = GetFinalRenderedCamCoord()
local rot = glm_rad(GetFinalRenderedCamRot(2))
local q = glm_quatEuler(rot.z, rot.y, rot.x)
return pos, glm_rayPicking(
q * glm_forward,
q * glm_up,
glm_rad(screen.fov),
screen.ratio,
0.10000, -- GetFinalRenderedCamNearClip(),
10000.0, -- GetFinalRenderedCamFarClip(),
0, 0
)
end
---------------------------------------
-- Functions
local function DrawTarget()
CreateThread(function()
while not HasStreamedTextureDictLoaded('shared') do
Wait(10)
RequestStreamedTextureDict('shared', true)
end
local sleep
local r, g, b, a
while targetActive do
sleep = 500
for _, zone in pairs(listSprite) do
sleep = 0
r = zone.targetoptions.drawColor?[1] or Config.DrawColor[1]
g = zone.targetoptions.drawColor?[2] or Config.DrawColor[2]
b = zone.targetoptions.drawColor?[3] or Config.DrawColor[3]
a = zone.targetoptions.drawColor?[4] or Config.DrawColor[4]
if zone.success then
r = zone.targetoptions.successDrawColor?[1] or Config.SuccessDrawColor[1]
g = zone.targetoptions.successDrawColor?[2] or Config.SuccessDrawColor[2]
b = zone.targetoptions.successDrawColor?[3] or Config.SuccessDrawColor[3]
a = zone.targetoptions.successDrawColor?[4] or Config.SuccessDrawColor[4]
end
SetDrawOrigin(zone.center.x, zone.center.y, zone.center.z, 0)
DrawSprite('shared', 'emptydot_32', 0, 0, 0.01, 0.02, 0, r, g, b, a)
ClearDrawOrigin()
end
Wait(sleep)
end
listSprite = {}
end)
end
local function RaycastCamera(flag, playerCoords)
if not playerPed then playerPed = PlayerPedId() end
if not playerCoords then playerCoords = GetEntityCoords(playerPed) end
local rayPos, rayDir = ScreenPositionToCameraRay()
local destination = rayPos + 16 * rayDir
local rayHandle = StartShapeTestLosProbe(rayPos.x, rayPos.y, rayPos.z, destination.x, destination.y, destination.z,
flag or -1, playerPed, 4)
while true do
local result, _, endCoords, _, entityHit = GetShapeTestResult(rayHandle)
if result ~= 1 then
local distance = playerCoords and #(playerCoords - endCoords)
if flag == 30 and entityHit then
entityHit = HasEntityClearLosToEntity(entityHit, playerPed, 7) and entityHit
end
local entityType = entityHit and GetEntityType(entityHit)
if entityType == 0 and pcall(GetEntityModel, entityHit) then
entityType = 3
end
return endCoords, distance, entityHit, entityType or 0
end
Wait(0)
end
end
exports('RaycastCamera', RaycastCamera)
local function DisableNUI()
SetNuiFocus(false, false)
SetNuiFocusKeepInput(false)
hasFocus = false
end
exports('DisableNUI', DisableNUI)
local function EnableNUI(options)
if not targetActive or hasFocus then return end
SetCursorLocation(0.5, 0.5)
SetNuiFocus(true, true)
SetNuiFocusKeepInput(true)
hasFocus = true
SendNUIMessage({ response = 'validTarget', data = options })
end
exports('EnableNUI', EnableNUI)
local function LeftTarget()
SetNuiFocus(false, false)
SetNuiFocusKeepInput(false)
success, hasFocus = false, false
table_wipe(sendData)
SendNUIMessage({ response = 'leftTarget' })
end
exports('LeftTarget', LeftTarget)
local function DisableTarget(forcedisable)
if (not targetActive and hasFocus and not Config.Toggle) or not forcedisable then return end
SetNuiFocus(false, false)
SetNuiFocusKeepInput(false)
Wait(100)
targetActive, success, hasFocus = false, false, false
SendNUIMessage({ response = 'closeTarget' })
end
exports('DisableTarget', DisableTarget)
local function DrawOutlineEntity(entity, bool)
if not Config.EnableOutline or IsEntityAPed(entity) then return end
SetEntityDrawOutline(entity, bool)
SetEntityDrawOutlineColor(Config.OutlineColor[1], Config.OutlineColor[2], Config.OutlineColor[3], Config.OutlineColor[4])
end
exports('DrawOutlineEntity', DrawOutlineEntity)
local function SetupOptions(datatable, entity, distance, isZone)
if not isZone then table_wipe(sendDistance) end
table_wipe(nuiData)
local slot = 0
for _, data in pairs(datatable) do
if CheckOptions(data, entity, distance) then
slot = data.num or slot + 1
sendData[slot] = data
sendData[slot].entity = entity
nuiData[slot] = {
icon = data.icon,
targeticon = data.targeticon,
label = data.label
}
if not isZone then
sendDistance[data.distance] = true
end
else
if not isZone then
sendDistance[data.distance] = false
end
end
end
return slot
end
local function CheckEntity(flag, datatable, entity, distance)
if not next(datatable) then return end
local slot = SetupOptions(datatable, entity, distance)
if not next(nuiData) then
LeftTarget()
DrawOutlineEntity(entity, false)
return
end
success = true
SendNUIMessage({ response = 'foundTarget', data = nuiData[slot].targeticon, options = nuiData })
DrawOutlineEntity(entity, true)
while targetActive and success do
local _, dist, entity2 = RaycastCamera(flag)
if entity ~= entity2 then
LeftTarget()
DrawOutlineEntity(entity, false)
break
elseif not hasFocus and IsDisabledControlPressed(0, Config.MenuControlKey) then
EnableNUI(nuiData)
DrawOutlineEntity(entity, false)
else
for k, v in pairs(sendDistance) do
if v and dist > k then
LeftTarget()
DrawOutlineEntity(entity, false)
break
end
end
end
Wait(0)
end
LeftTarget()
DrawOutlineEntity(entity, false)
end
exports('CheckEntity', CheckEntity)
local function CheckBones(coords, entity, bonelist)
local closestBone = -1
local closestDistance = 20
local closestPos, closestBoneName
for _, v in pairs(bonelist) do
if Bones.Options[v] then
local boneId = GetEntityBoneIndexByName(entity, v)
local bonePos = GetWorldPositionOfEntityBone(entity, boneId)
local distance = #(coords - bonePos)
if closestBone == -1 or distance < closestDistance then
closestBone, closestDistance, closestPos, closestBoneName = boneId, distance, bonePos, v
end
end
end
if closestBone ~= -1 then
return closestBone, closestPos, closestBoneName
else
return false
end
end
exports('CheckBones', CheckBones)
local function EnableTarget()
if not allowTarget or success or (not Config.Standalone and not LocalPlayer.state['isLoggedIn']) or IsNuiFocused() or (Config.DisableInVehicle and IsPedInAnyVehicle(playerPed or PlayerPedId(), false)) then return end
if targetActive then return end
targetActive = true
playerPed = PlayerPedId()
screen.ratio = GetAspectRatio(true)
screen.fov = GetFinalRenderedCamFov()
if Config.DrawSprite then DrawTarget() end
SendNUIMessage({ response = 'openTarget' })
CreateThread(function()
repeat
SetPauseMenuActive(false)
if Config.DisableControls then
DisableAllControlActions(0)
else
DisableControlAction(0, 1, true) -- look left/right
DisableControlAction(0, 2, true) -- look up/down
DisableControlAction(0, 4, true) -- look down only
DisableControlAction(0, 5, true) -- look left only
DisableControlAction(0, 6, true) -- look right only
DisableControlAction(0, 25, true) -- input aim
DisableControlAction(0, 24, true) -- attack
end
EnableControlAction(0, 30, true) -- move left/right
EnableControlAction(0, 31, true) -- move forward/back
if not hasFocus then
EnableControlAction(0, 1, true) -- look left/right
EnableControlAction(0, 2, true) -- look up/down
end
Wait(0)
until not targetActive
end)
local flag = 30
while targetActive do
local sleep = 0
if flag == 30 then flag = -1 else flag = 30 end
local coords, distance, entity, entityType = RaycastCamera(flag)
if distance <= Config.MaxDistance then
if entityType > 0 then
-- Local(non-net) entity targets
if Entities[entity] then
CheckEntity(flag, Entities[entity], entity, distance)
end
-- Owned entity targets
if NetworkGetEntityIsNetworked(entity) then
local data = Entities[NetworkGetNetworkIdFromEntity(entity)]
if data then CheckEntity(flag, data, entity, distance) end
end
-- Player and Ped targets
if entityType == 1 then
local data = Models[GetEntityModel(entity)]
if IsPedAPlayer(entity) then data = Players end
if data and next(data) then CheckEntity(flag, data, entity, distance) end
-- Vehicle bones and models
elseif entityType == 2 then
local closestBone, _, closestBoneName = CheckBones(coords, entity, Bones.Vehicle)
local datatable = Bones.Options[closestBoneName]
if datatable and next(datatable) and closestBone then
local slot = SetupOptions(datatable, entity, distance)
if next(nuiData) then
success = true
SendNUIMessage({ response = 'foundTarget', data = nuiData[slot].targeticon, options = nuiData })
DrawOutlineEntity(entity, true)
while targetActive and success do
local coords2, dist, entity2 = RaycastCamera(flag)
if entity == entity2 then
local closestBone2 = CheckBones(coords2, entity, Bones.Vehicle)
if closestBone ~= closestBone2 then
LeftTarget()
DrawOutlineEntity(entity, false)
break
elseif not hasFocus and IsDisabledControlPressed(0, Config.MenuControlKey) then
EnableNUI(nuiData)
DrawOutlineEntity(entity, false)
else
for k, v in pairs(sendDistance) do
if v and dist > k then
LeftTarget()
DrawOutlineEntity(entity, false)
break
end
end
end
else
LeftTarget()
DrawOutlineEntity(entity, false)
break
end
Wait(0)
end
LeftTarget()
DrawOutlineEntity(entity, false)
end
end
-- Vehicle model targets
local data = Models[GetEntityModel(entity)]
if data then CheckEntity(flag, data, entity, distance) end
-- Entity targets
elseif entityType > 2 then
local data = Models[GetEntityModel(entity)]
if data then CheckEntity(flag, data, entity, distance) end
end
-- Generic targets
if not success then
local data = Types[entityType]
if data and next(data) then CheckEntity(flag, data, entity, distance) end
end
else
sleep = sleep + 20
end
if not success then
-- Zone targets
local closestDis, closestZone
for k, zone in pairs(Zones) do
if distance < (closestDis or Config.MaxDistance) and distance <= zone.targetoptions.distance and zone:isPointInside(coords) then
closestDis = distance
closestZone = zone
end
if Config.DrawSprite then
local testCentre = type(zone.center) == 'vector2' and vector3(zone.center.x, zone.center.y, zone.maxZ) or zone.center
if #(coords - testCentre) < (zone.targetoptions.drawDistance or Config.DrawDistance) then
listSprite[k] = zone
else
listSprite[k] = nil
end
end
end
if closestZone then
local slot = SetupOptions(closestZone.targetoptions.options, entity, distance, true)
if next(nuiData) then
success = true
SendNUIMessage({ response = 'foundTarget', data = nuiData[slot].targeticon, options = nuiData })
if Config.DrawSprite then
listSprite[closestZone.name].success = true
end
DrawOutlineEntity(entity, true)
while targetActive and success do
local newCoords, dist = RaycastCamera(flag)
if not closestZone:isPointInside(newCoords) or dist > closestZone.targetoptions.distance then
LeftTarget()
DrawOutlineEntity(entity, false)
break
elseif not hasFocus and IsDisabledControlPressed(0, Config.MenuControlKey) then
EnableNUI(nuiData)
DrawOutlineEntity(entity, false)
end
Wait(0)
end
if Config.DrawSprite and listSprite[closestZone.name] then -- Check for when the targetActive is false and it removes the zone from listSprite
listSprite[closestZone.name].success = false
end
LeftTarget()
DrawOutlineEntity(entity, false)
end
else
sleep = sleep + 20
end
else
LeftTarget()
DrawOutlineEntity(entity, false)
end
else
sleep = sleep + 20
end
Wait(sleep)
end
DisableTarget(false)
end
local function AddCircleZone(name, center, radius, options, targetoptions)
local centerType = type(center)
center = (centerType == 'table' or centerType == 'vector4') and vec3(center.x, center.y, center.z) or center
Zones[name] = CircleZone:Create(center, radius, options)
targetoptions.distance = targetoptions.distance or Config.MaxDistance
Zones[name].targetoptions = targetoptions
return Zones[name]
end
exports('AddCircleZone', AddCircleZone)
local function AddBoxZone(name, center, length, width, options, targetoptions)
local centerType = type(center)
center = (centerType == 'table' or centerType == 'vector4') and vec3(center.x, center.y, center.z) or center
Zones[name] = BoxZone:Create(center, length, width, options)
targetoptions.distance = targetoptions.distance or Config.MaxDistance
Zones[name].targetoptions = targetoptions
return Zones[name]
end
exports('AddBoxZone', AddBoxZone)
local function AddPolyZone(name, points, options, targetoptions)
local _points = {}
local pointsType = type(points[1])
if pointsType == 'table' or pointsType == 'vector3' or pointsType == 'vector4' then
for i = 1, #points do
_points[i] = vec2(points[i].x, points[i].y)
end
end
Zones[name] = PolyZone:Create(#_points > 0 and _points or points, options)
targetoptions.distance = targetoptions.distance or Config.MaxDistance
Zones[name].targetoptions = targetoptions
return Zones[name]
end
exports('AddPolyZone', AddPolyZone)
local function AddComboZone(zones, options, targetoptions)
Zones[options.name] = ComboZone:Create(zones, options)
targetoptions.distance = targetoptions.distance or Config.MaxDistance
Zones[options.name].targetoptions = targetoptions
return Zones[options.name]
end
exports('AddComboZone', AddComboZone)
local function AddEntityZone(name, entity, options, targetoptions)
Zones[name] = EntityZone:Create(entity, options)
targetoptions.distance = targetoptions.distance or Config.MaxDistance
Zones[name].targetoptions = targetoptions
return Zones[name]
end
exports('AddEntityZone', AddEntityZone)
local function RemoveZone(name)
if not Zones[name] then return end
if Zones[name].destroy then Zones[name]:destroy() end
Zones[name] = nil
end
exports('RemoveZone', RemoveZone)
local function SetOptions(tbl, distance, options)
for _, v in pairs(options) do
if v.required_item then
v.item = v.required_item
v.required_item = nil
end
if not v.distance or v.distance > distance then v.distance = distance end
tbl[v.label] = v
end
end
local function AddTargetBone(bones, parameters)
local distance, options = parameters.distance or Config.MaxDistance, parameters.options
if type(bones) == 'table' then
for _, bone in pairs(bones) do
if not Bones.Options[bone] then Bones.Options[bone] = {} end
SetOptions(Bones.Options[bone], distance, options)
end
elseif type(bones) == 'string' then
if not Bones.Options[bones] then Bones.Options[bones] = {} end
SetOptions(Bones.Options[bones], distance, options)
end
end
exports('AddTargetBone', AddTargetBone)
local function RemoveTargetBone(bones, labels)
if type(bones) == 'table' then
for _, bone in pairs(bones) do
if labels then
if type(labels) == 'table' then
for _, v in pairs(labels) do
if Bones.Options[bone] then
Bones.Options[bone][v] = nil
end
end
elseif type(labels) == 'string' then
if Bones.Options[bone] then
Bones.Options[bone][labels] = nil
end
end
else
Bones.Options[bone] = nil
end
end
else
if labels then
if type(labels) == 'table' then
for _, v in pairs(labels) do
if Bones.Options[bones] then
Bones.Options[bones][v] = nil
end
end
elseif type(labels) == 'string' then
if Bones.Options[bones] then
Bones.Options[bones][labels] = nil
end
end
else
Bones.Options[bones] = nil
end
end
end
exports('RemoveTargetBone', RemoveTargetBone)
local function AddTargetEntity(entities, parameters)
local distance, options = parameters.distance or Config.MaxDistance, parameters.options
if type(entities) == 'table' then
for _, entity in pairs(entities) do
if NetworkGetEntityIsNetworked(entity) then entity = NetworkGetNetworkIdFromEntity(entity) end -- Allow non-networked entities to be targeted
if not Entities[entity] then Entities[entity] = {} end
SetOptions(Entities[entity], distance, options)
end
elseif type(entities) == 'number' then
if NetworkGetEntityIsNetworked(entities) then entities = NetworkGetNetworkIdFromEntity(entities) end -- Allow non-networked entities to be targeted
if not Entities[entities] then Entities[entities] = {} end
SetOptions(Entities[entities], distance, options)
end
end
exports('AddTargetEntity', AddTargetEntity)
local function RemoveTargetEntity(entities, labels)
if type(entities) == 'table' then
for _, entity in pairs(entities) do
if NetworkGetEntityIsNetworked(entity) then entity = NetworkGetNetworkIdFromEntity(entity) end -- Allow non-networked entities to be targeted
if labels then
if type(labels) == 'table' then
for _, v in pairs(labels) do
if Entities[entity] then
Entities[entity][v] = nil
end
end
elseif type(labels) == 'string' then
if Entities[entity] then
Entities[entity][labels] = nil
end
end
else
Entities[entity] = nil
end
end
elseif type(entities) == 'number' then
if NetworkGetEntityIsNetworked(entities) then entities = NetworkGetNetworkIdFromEntity(entities) end -- Allow non-networked entities to be targeted
if labels then
if type(labels) == 'table' then
for _, v in pairs(labels) do
if Entities[entities] then
Entities[entities][v] = nil
end
end
elseif type(labels) == 'string' then
if Entities[entities] then
Entities[entities][labels] = nil
end
end
else
Entities[entities] = nil
end
end
end
exports('RemoveTargetEntity', RemoveTargetEntity)
local function AddTargetModel(models, parameters)
local distance, options = parameters.distance or Config.MaxDistance, parameters.options
if type(models) == 'table' then
for _, model in pairs(models) do
if type(model) == 'string' then model = joaat(model) end
if not Models[model] then Models[model] = {} end
SetOptions(Models[model], distance, options)
end
else
if type(models) == 'string' then models = joaat(models) end
if not Models[models] then Models[models] = {} end
SetOptions(Models[models], distance, options)
end
end
exports('AddTargetModel', AddTargetModel)
local function RemoveTargetModel(models, labels)
if type(models) == 'table' then
for _, model in pairs(models) do
if type(model) == 'string' then model = joaat(model) end
if labels then
if type(labels) == 'table' then
for _, v in pairs(labels) do
if Models[model] then
Models[model][v] = nil
end
end
elseif type(labels) == 'string' then
if Models[model] then
Models[model][labels] = nil
end
end
else
Models[model] = nil
end
end
else
if type(models) == 'string' then models = joaat(models) end
if labels then
if type(labels) == 'table' then
for _, v in pairs(labels) do
if Models[models] then
Models[models][v] = nil
end
end
elseif type(labels) == 'string' then
if Models[models] then
Models[models][labels] = nil
end
end
else
Models[models] = nil
end
end
end
exports('RemoveTargetModel', RemoveTargetModel)
local function AddGlobalType(type, parameters)
local distance, options = parameters.distance or Config.MaxDistance, parameters.options
SetOptions(Types[type], distance, options)
end
exports('AddGlobalType', AddGlobalType)
local function AddGlobalPed(parameters) AddGlobalType(1, parameters) end
exports('AddGlobalPed', AddGlobalPed)
local function AddGlobalVehicle(parameters) AddGlobalType(2, parameters) end
exports('AddGlobalVehicle', AddGlobalVehicle)
local function AddGlobalObject(parameters) AddGlobalType(3, parameters) end
exports('AddGlobalObject', AddGlobalObject)
local function AddGlobalPlayer(parameters)
local distance, options = parameters.distance or Config.MaxDistance, parameters.options
SetOptions(Players, distance, options)
end
exports('AddGlobalPlayer', AddGlobalPlayer)
local function RemoveGlobalType(typ, labels)
if labels then
if type(labels) == 'table' then
for _, v in pairs(labels) do
Types[typ][v] = nil
end
elseif type(labels) == 'string' then
Types[typ][labels] = nil
end
else
Types[typ] = {}
end
end
exports('RemoveGlobalType', RemoveGlobalType)
local function RemoveGlobalPlayer(labels)
if labels then
if type(labels) == 'table' then
for _, v in pairs(labels) do
Players[v] = nil
end
elseif type(labels) == 'string' then
Players[labels] = nil
end
else
Players = {}
end
end
exports('RemoveGlobalPlayer', RemoveGlobalPlayer)
function SpawnPeds()
if pedsReady or not next(Config.Peds) then return end
for k, v in pairs(Config.Peds) do
if not v.currentpednumber or v.currentpednumber == 0 then
local spawnedped
RequestModel(v.model)
while not HasModelLoaded(v.model) do
Wait(0)
end
if type(v.model) == 'string' then v.model = joaat(v.model) end
if v.minusOne then
spawnedped = CreatePed(0, v.model, v.coords.x, v.coords.y, v.coords.z - 1.0, v.coords.w,
v.networked or false, false)
else
spawnedped = CreatePed(0, v.model, v.coords.x, v.coords.y, v.coords.z, v.coords.w, v.networked or false,
false)
end
if v.freeze then
FreezeEntityPosition(spawnedped, true)
end
if v.invincible then
SetEntityInvincible(spawnedped, true)
end
if v.blockevents then
SetBlockingOfNonTemporaryEvents(spawnedped, true)
end
if v.animDict and v.anim then
RequestAnimDict(v.animDict)
while not HasAnimDictLoaded(v.animDict) do
Wait(0)
end
TaskPlayAnim(spawnedped, v.animDict, v.anim, 8.0, 0, -1, v.flag or 1, 0, false, false, false)
end
if v.scenario then
SetPedCanPlayAmbientAnims(spawnedped, true)
TaskStartScenarioInPlace(spawnedped, v.scenario, 0, true)
end
if v.pedrelations then
if type(v.pedrelations.groupname) ~= 'string' then error(v.pedrelations.groupname .. ' is not a string') end
local pedgrouphash = joaat(v.pedrelations.groupname)
if not DoesRelationshipGroupExist(pedgrouphash) then
AddRelationshipGroup(v.pedrelations.groupname)
end
SetPedRelationshipGroupHash(spawnedped, pedgrouphash)
if v.pedrelations.toplayer then
SetRelationshipBetweenGroups(v.pedrelations.toplayer, pedgrouphash, joaat('PLAYER'))
end
if v.pedrelations.toowngroup then
SetRelationshipBetweenGroups(v.pedrelations.toowngroup, pedgrouphash, pedgrouphash)
end
end
if v.weapon then
if type(v.weapon.name) == 'string' then v.weapon.name = joaat(v.weapon.name) end
if IsWeaponValid(v.weapon.name) then
SetCanPedEquipWeapon(spawnedped, v.weapon.name, true)
GiveWeaponToPed(spawnedped, v.weapon.name, v.weapon.ammo, v.weapon.hidden or false, true)
SetPedCurrentWeaponVisible(spawnedped, not v.weapon.hidden or false, true)
end
end
if v.target then
if v.target.useModel then
AddTargetModel(v.model, {
options = v.target.options,
distance = v.target.distance
})
else
AddTargetEntity(spawnedped, {
options = v.target.options,
distance = v.target.distance
})
end
end
if v.action then
v.action(v)
end
Config.Peds[k].currentpednumber = spawnedped
end
end
pedsReady = true
end
function DeletePeds()
if not pedsReady or not next(Config.Peds) then return end
for k, v in pairs(Config.Peds) do
DeletePed(v.currentpednumber)
Config.Peds[k].currentpednumber = 0
end
pedsReady = false
end
exports('DeletePeds', DeletePeds)
local function SpawnPed(data)
local spawnedped
local key, value = next(data)
if type(value) == 'table' and type(key) ~= 'string' then
for _, v in pairs(data) do
if v.spawnNow then
RequestModel(v.model)
while not HasModelLoaded(v.model) do
Wait(0)
end
if type(v.model) == 'string' then v.model = joaat(v.model) end
if v.minusOne then
spawnedped = CreatePed(0, v.model, v.coords.x, v.coords.y, v.coords.z - 1.0, v.coords.w or 0.0,
v.networked or false, true)
else
spawnedped = CreatePed(0, v.model, v.coords.x, v.coords.y, v.coords.z, v.coords.w or 0.0,
v.networked or false, true)
end
if v.freeze then
FreezeEntityPosition(spawnedped, true)
end
if v.invincible then
SetEntityInvincible(spawnedped, true)
end
if v.blockevents then
SetBlockingOfNonTemporaryEvents(spawnedped, true)
end
if v.animDict and v.anim then
RequestAnimDict(v.animDict)
while not HasAnimDictLoaded(v.animDict) do
Wait(0)
end
TaskPlayAnim(spawnedped, v.animDict, v.anim, 8.0, 0, -1, v.flag or 1, 0, false, false, false)
end
if v.scenario then
SetPedCanPlayAmbientAnims(spawnedped, true)
TaskStartScenarioInPlace(spawnedped, v.scenario, 0, true)
end
if v.pedrelations and type(v.pedrelations.groupname) == 'string' then
if type(v.pedrelations.groupname) ~= 'string' then
error(v.pedrelations.groupname ..
' is not a string')
end
local pedgrouphash = joaat(v.pedrelations.groupname)
if not DoesRelationshipGroupExist(pedgrouphash) then
AddRelationshipGroup(v.pedrelations.groupname)
end
SetPedRelationshipGroupHash(spawnedped, pedgrouphash)
if v.pedrelations.toplayer then
SetRelationshipBetweenGroups(v.pedrelations.toplayer, pedgrouphash, joaat('PLAYER'))
end
if v.pedrelations.toowngroup then
SetRelationshipBetweenGroups(v.pedrelations.toowngroup, pedgrouphash, pedgrouphash)
end
end
if v.weapon then
if type(v.weapon.name) == 'string' then v.weapon.name = joaat(v.weapon.name) end
if IsWeaponValid(v.weapon.name) then
SetCanPedEquipWeapon(spawnedped, v.weapon.name, true)
GiveWeaponToPed(spawnedped, v.weapon.name, v.weapon.ammo, v.weapon.hidden or false, true)
SetPedCurrentWeaponVisible(spawnedped, not v.weapon.hidden or false, true)
end
end
if v.target then
if v.target.useModel then
AddTargetModel(v.model, {
options = v.target.options,
distance = v.target.distance
})
else
AddTargetEntity(spawnedped, {
options = v.target.options,
distance = v.target.distance
})
end
end
v.currentpednumber = spawnedped
if v.action then
v.action(v)
end
end
local nextnumber = #Config.Peds + 1
if nextnumber <= 0 then nextnumber = 1 end
Config.Peds[nextnumber] = v
end
else
if data.spawnNow then
RequestModel(data.model)
while not HasModelLoaded(data.model) do
Wait(0)
end
if type(data.model) == 'string' then data.model = joaat(data.model) end
if data.minusOne then
spawnedped = CreatePed(0, data.model, data.coords.x, data.coords.y, data.coords.z - 1.0, data.coords.w,
data.networked or false, true)
else
spawnedped = CreatePed(0, data.model, data.coords.x, data.coords.y, data.coords.z, data.coords.w,
data.networked or false, true)
end
if data.freeze then
FreezeEntityPosition(spawnedped, true)
end
if data.invincible then
SetEntityInvincible(spawnedped, true)
end
if data.blockevents then