This repository has been archived by the owner on Feb 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
client.lua
1117 lines (947 loc) · 32.2 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 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 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 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 + 10000 * rayDir
local rayHandle = StartShapeTestLosProbe(rayPos.x, rayPos.y, rayPos.z, destination.x, destination.y, destination.z, flag or -1, playerPed, 0)
while true do
local result, _, endCoords, _, entityHit = GetShapeTestResult(rayHandle)
if result ~= 1 then
local distance = playerCoords and #(playerCoords - endCoords)
return endCoords, distance, entityHit, entityHit and GetEntityType(entityHit) 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(entity, Config.OutlineColor[1], Config.OutlineColor[2], Config.OutlineColor[3])
end
exports('DrawOutlineEntity', DrawOutlineEntity)
local function CheckEntity(flag, datatable, entity, distance)
if not next(datatable) then return end
table_wipe(sendDistance)
table_wipe(nuiData)
local slot = 0
for _, data in pairs(datatable) do
if CheckOptions(data, entity, distance) then
slot += 1
sendData[slot] = data
sendData[slot].entity = entity
nuiData[slot] = {
icon = data.icon,
label = data.label
}
sendDistance[data.distance] = true
else sendDistance[data.distance] = false end
end
if not next(nuiData) then
LeaveTarget()
DrawOutlineEntity(entity, false)
return
end
success = true
SendNUIMessage({response = "foundTarget", data = sendData[slot].targeticon})
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 not CheckOptions then CheckOptions = _ENV.CheckOptions end
if targetActive or not CheckOptions then return end
targetActive = true
playerPed = PlayerPedId()
screen.ratio = GetAspectRatio(true)
screen.fov = GetFinalRenderedCamFov()
SendNUIMessage({response = "openTarget"})
CreateThread(function()
repeat
SetPauseMenuActive(false)
DisableAllControlActions(0)
EnableControlAction(0, 30, true)
EnableControlAction(0, 31, true)
if not hasFocus then
EnableControlAction(0, 1, true)
EnableControlAction(0, 2, true)
end
Wait(0)
until not targetActive
end)
local flag
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
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
table_wipe(sendDistance)
table_wipe(nuiData)
local slot = 0
for _, data in pairs(datatable) do
if CheckOptions(data, entity, distance) then
slot += 1
sendData[slot] = data
sendData[slot].entity = entity
nuiData[slot] = {
icon = data.icon,
label = data.label
}
sendDistance[data.distance] = true
else sendDistance[data.distance] = false end
end
if next(nuiData) then
success = true
SendNUIMessage({response = "foundTarget", data = sendData[slot].targeticon})
DrawOutlineEntity(entity, true)
while targetActive and success do
local _, dist, entity2 = RaycastCamera(flag)
if entity == entity2 then
local closestBone2 = CheckBones(coords, 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
else
-- Vehicle Model targets
local data = Models[GetEntityModel(entity)]
if data then CheckEntity(flag, data, entity, distance) end
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 += 20 end
if not success then
local closestDis, closestZone, pedcoords
if Config.DrawSprite then pedcoords = GetEntityCoords(playerPed) end
for k, zone in pairs(Zones) do
if Config.DrawSprite then
if #(pedcoords - zone.center) < (zone.targetoptions.drawDistance or Config.DrawDistance) and not listSprite[k] then
listSprite[k] = true
CreateThread(function()
while not HasStreamedTextureDictLoaded("shared") do Wait(10) RequestStreamedTextureDict("shared", true) end
while targetActive do
Wait(0)
SetDrawOrigin(zone.center.x, zone.center.y, zone.center.z, 0)
DrawSprite("shared", "emptydot_32", 0, 0, 0.02, 0.035, 0, 255,255,255, 255.0)
ClearDrawOrigin()
end
listSprite[k] = false
end)
end
end
if distance < (closestDis or Config.MaxDistance) and distance <= zone.targetoptions.distance and zone:isPointInside(coords) then
closestDis = distance
closestZone = zone
end
end
if closestZone then
table_wipe(nuiData)
local slot = 0
for _, data in pairs(closestZone.targetoptions.options) do
if CheckOptions(data, entity, distance) then
slot += 1
sendData[slot] = data
sendData[slot].entity = entity
nuiData[slot] = {
icon = data.icon,
label = data.label
}
end
end
if next(nuiData) then
success = true
SendNUIMessage({response = "foundTarget", data = sendData[slot].targeticon})
DrawOutlineEntity(entity, true)
while targetActive and success do
local coords, distance = RaycastCamera(flag)
if not closestZone:isPointInside(coords) or distance > 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
LeftTarget()
DrawOutlineEntity(entity, false)
end
else sleep += 20 end
else LeftTarget() DrawOutlineEntity(entity, false) end
else sleep += 20 end
Wait(sleep)
end
DisableTarget(false)
end
local function AddCircleZone(name, center, radius, options, targetoptions)
center = type(center) == 'table' 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)
center = type(center) == 'table' 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 = {}
if type(points[1]) == 'table' 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
exports("SetOptions", SetOptions)
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 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
end
else
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
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 type(labels) == 'table' then
for k, 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
end
elseif type(entities) == 'number' then
if NetworkGetEntityIsNetworked(entities) then entities = NetworkGetNetworkIdFromEntity(entities) end -- Allow non-networked entities to be targeted
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
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 type(labels) == 'table' then
for k, 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
end
else
if type(models) == 'string' then models = joaat(models) end
if type(labels) == 'table' then
for k, 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
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 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
end
exports("RemoveGlobalType", RemoveGlobalType)
local function RemoveGlobalPlayer(labels)
if type(labels) == 'table' then
for _, v in pairs(labels) do
Players[v] = nil
end
elseif type(labels) == 'string' then
Players[labels] = nil
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 = 0
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, 0, 0, 0)
end
if v.scenario then
SetPedCanPlayAmbientAnims(spawnedped, true)
TaskStartScenarioInPlace(spawnedped, v.scenario, 0, true)
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
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 = 0
local key, value = next(data)
if type(value) == 'table' and key ~= 'target' and key ~= 'coords' 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, 0, 0, 0)
end
if v.scenario then
SetPedCanPlayAmbientAnims(spawnedped, true)
TaskStartScenarioInPlace(spawnedped, v.scenario, 0, true)
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
end
local nextnumber = #Config.Peds + 1
if nextnumber <= 0 then nextnumber = 1 end
Config.Peds[nextnumber] = v
end
else
if type(value) == 'table' and key ~= 'target' and key ~= 'coords' then
if Config.Debug then print('Wrong table format for SpawnPed export') end
return
end
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
SetBlockingOfNonTemporaryEvents(spawnedped, true)
end
if data.animDict and data.anim then
RequestAnimDict(data.animDict)
while not HasAnimDictLoaded(data.animDict) do
Wait(0)
end
TaskPlayAnim(spawnedped, data.animDict, data.anim, 8.0, 0, -1, data.flag or 1, 0, 0, 0, 0)
end
if data.scenario then
SetPedCanPlayAmbientAnims(spawnedped, true)
TaskStartScenarioInPlace(spawnedped, data.scenario, 0, true)
end
if data.target then
if data.target.useModel then
AddTargetModel(data.model, {
options = data.target.options,
distance = data.target.distance
})
else
AddTargetEntity(spawnedped, {
options = data.target.options,
distance = data.target.distance
})
end
end
data.currentpednumber = spawnedped
end
local nextnumber = #Config.Peds + 1
if nextnumber <= 0 then nextnumber = 1 end
Config.Peds[nextnumber] = data
end
end
exports("SpawnPed", SpawnPed)
local function RemovePed(peds)
if type(peds) == 'table' then
for k, v in pairs(peds) do
DeletePed(v)
if Config.Peds[k] then Config.Peds[k].currentpednumber = 0 end
end
elseif type(peds) == 'number' then
DeletePed(peds)
end
end
exports("RemoveSpawnedPed", RemovePed)
-- Misc. Exports
exports("RemoveGlobalPed", function(labels) RemoveGlobalType(1, labels) end)
exports("RemoveGlobalVehicle", function(labels) RemoveGlobalType(2, labels) end)
exports("RemoveGlobalObject", function(labels) RemoveGlobalType(3, labels) end)
exports("IsTargetActive", function() return targetActive end)
exports("IsTargetSuccess", function() return success end)
exports("GetGlobalTypeData", function(type, label) return Types[type][label] end)
exports("GetZoneData", function(name) return Zones[name] end)
exports("GetTargetBoneData", function(bone) return Bones.Options[bone][label] end)
exports("GetTargetEntityData", function(entity, label) return Entities[entity][label] end)
exports("GetTargetModelData", function(model, label) return Models[model][label] end)
exports("GetGlobalPedData", function(label) return Types[1][label] end)
exports("GetGlobalVehicleData", function(label) return Types[2][label] end)
exports("GetGlobalObjectData", function(label) return Types[3][label] end)
exports("GetGlobalPlayerData", function(label) return Players[label] end)
exports("UpdateGlobalTypeData", function(type, label, data) Types[type][label] = data end)
exports("UpdateZoneData", function(name, data) Zones[name] = data end)
exports("UpdateTargetBoneData", function(bone, label, data) Bones.Options[bone][label] = data end)
exports("UpdateTargetEntityData", function(entity, label, data) Entities[entity][label] = data end)
exports("UpdateTargetModelData", function(model, label, data) Models[model][label] = data end)
exports("UpdateGlobalPedData", function(label, data) Types[1][label] = data end)
exports("UpdateGlobalVehicleData", function(label, data) Types[2][label] = data end)
exports("UpdateGlobalObjectData", function(label, data) Types[3][label] = data end)
exports("UpdateGlobalPlayerData", function(label, data) Players[label] = data end)
exports("GetPeds", function() return Config.Peds end)
exports("UpdatePedsData", function(index, data) Config.Peds[index] = data end)
exports("AllowTargeting", function(bool) allowTarget = bool end)
-- NUI Callbacks
RegisterNUICallback('selectTarget', function(option, cb)
SetNuiFocus(false, false)
SetNuiFocusKeepInput(false)
Wait(100)
targetActive, success, hasFocus = false, false, false
if not next(sendData) then return end
local data = sendData[option]
if not data then return end
table_wipe(sendData)
CreateThread(function()
Wait(0)
if data.action then
data.action(data.entity)
elseif data.event then
if data.type == "client" then
TriggerEvent(data.event, data)
elseif data.type == "server" then
TriggerServerEvent(data.event, data)
elseif data.type == "command" then
ExecuteCommand(data.event)
elseif data.type == "qbcommand" then
TriggerServerEvent('QBCore:CallCommand', data.event, data)
else
TriggerEvent(data.event, data)
end
else
error("No trigger setup")
end
end)
cb('ok')
end)
RegisterNUICallback('closeTarget', function(_, cb)
SetNuiFocus(false, false)
SetNuiFocusKeepInput(false)
Wait(100)
targetActive, success, hasFocus = false, false, false
cb('ok')
end)
RegisterNUICallback('leftTarget', function(_, cb)
if Config.Toggle then
SetNuiFocus(false, false)
SetNuiFocusKeepInput(false)
Wait(100)
table_wipe(sendData)
success, hasFocus = false, false
else
DisableTarget(true)
end
cb('ok')
end)