-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathclient.lua
3402 lines (2774 loc) · 84.8 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 Database = {}
local Cam
local Speed = Config.Speed
local AdjustSpeed = Config.AdjustSpeed
local RotateSpeed = Config.RotateSpeed
local AttachedEntity
local RotateMode = 2
local AdjustMode = 4
local SpeedMode = 0
local PlaceOnGround = false
local CurrentSpawn
local ShowControls = true
local KeepSelfInDb = true
local FocusTarget
local FocusTargetPos
local FreeFocus = false
local showEntityHandles = false
local SpoonerPrompts, ClearTasksPrompt, DetachPrompt
if Config.isRDR then
SpoonerPrompts = UipromptGroup:new("Spooner", false)
ClearTasksPrompt = Uiprompt:new(`INPUT_INTERACT_NEG`, "Clear Tasks", SpoonerPrompts)
ClearTasksPrompt:setHoldMode(true)
ClearTasksPrompt:setOnHoldModeJustCompleted(function()
TryClearTasks(PlayerPedId())
end)
DetachPrompt = Uiprompt:new(`INPUT_INTERACT_LEAD_ANIMAL`, "Detach", SpoonerPrompts)
DetachPrompt:setHoldMode(true)
DetachPrompt:setOnHoldModeJustCompleted(function()
TryDetach(PlayerPedId())
end)
end
local StoreDeleted = false
local DeletedEntities = {}
local Permissions = {}
Permissions.maxEntities = 0
Permissions.spawn = {}
Permissions.spawn.ped = false
Permissions.spawn.vehicle = false
Permissions.spawn.object = false
Permissions.spawn.propset = false
Permissions.spawn.pickup = false
Permissions.delete = {}
Permissions.delete.own = {}
Permissions.delete.own.networked = false
Permissions.delete.own.nonNetworked = false
Permissions.delete.other = {}
Permissions.delete.other.networked = false
Permissions.delete.other.nonNetworked = false
Permissions.modify = {}
Permissions.modify.own = {}
Permissions.modify.own.networked = false
Permissions.modify.own.nonNetworked = false
Permissions.modify.other = {}
Permissions.modify.other.networked = false
Permissions.modify.other.nonNetworked = false
Permissions.properties = {}
Permissions.properties.freeze = false
Permissions.properties.position = false
Permissions.properties.goTo = false
Permissions.properties.rotation = false
Permissions.properties.health = false
Permissions.properties.invincible = false
Permissions.properties.visible = false
Permissions.properties.gravity = false
Permissions.properties.collision = false
Permissions.properties.clone = false
Permissions.properties.attachments = false
Permissions.properties.lights = false
Permissions.properties.registerAsNetworked = false
Permissions.properties.focus = false
Permissions.properties.ped = {}
Permissions.properties.ped.changeModel = false
Permissions.properties.ped.outfit = false
Permissions.properties.ped.group = false
Permissions.properties.ped.scenario = false
Permissions.properties.ped.animation = false
Permissions.properties.ped.clearTasks = false
Permissions.properties.ped.weapon = false
Permissions.properties.ped.mount = false
Permissions.properties.ped.enterVehicle = false
Permissions.properties.ped.resurrect = false
Permissions.properties.ped.ai = false
Permissions.properties.ped.knockOffProps = false
Permissions.properties.ped.walkStyle = false
Permissions.properties.ped.clone = false
Permissions.properties.ped.cloneToTarget = false
Permissions.properties.ped.lookAtEntity = false
Permissions.properties.ped.clean = false
Permissions.properties.ped.scale = false
Permissions.properties.ped.configFlags = false
Permissions.properties.ped.goToWaypoint = false
Permissions.properties.ped.goToEntity = false
Permissions.properties.ped.attack = false
Permissions.properties.vehicle = {}
Permissions.properties.vehicle.repair = false
Permissions.properties.vehicle.getin = false
Permissions.properties.vehicle.engine = false
Permissions.properties.vehicle.lights = false
RegisterNetEvent('spooner:init')
RegisterNetEvent('spooner:toggle')
RegisterNetEvent('spooner:openDatabaseMenu')
RegisterNetEvent('spooner:openSaveDbMenu')
RegisterNetEvent('spooner:refreshPermissions')
function SetLightsIntensityForEntity(entity, intensity)
Citizen.InvokeNative(0x07C0F87AAC57F2E4, entity, intensity)
end
function SetLightsColorForEntity(entity, red, green, blue)
Citizen.InvokeNative(0x6EC2A67962296F49, entity, red, green, blue)
end
function SetLightsTypeForEntity(entity, type)
Citizen.InvokeNative(0xAB72C67163DC4DB4, entity, type)
end
function CreatePed_2(modelHash, x, y, z, heading, isNetwork, thisScriptCheck, p7, p8)
return Citizen.InvokeNative(0xD49F9B0955C367DE, modelHash, x, y, z, heading, isNetwork, thisScriptCheck, p7, p8)
end
function SetRandomOutfitVariation(ped, p1)
Citizen.InvokeNative(0x283978A15512B2FE, ped, p1)
end
function BlipAddForEntity(blipHash, entity)
return Citizen.InvokeNative(0x23F74C2FDA6E7C61, blipHash, entity)
end
function SetPedOnMount(ped, mount, seatIndex, p3)
Citizen.InvokeNative(0x028F76B6E78246EB, ped, mount, seatIndex, p3)
end
function IsUsingKeyboard(padIndex)
return Citizen.InvokeNative(0xA571D46727E2B718, padIndex)
end
function RequestPropset(hash)
return Citizen.InvokeNative(0xF3DE57A46D5585E9, hash)
end
function ReleasePropset(hash)
return Citizen.InvokeNative(0xB1964A83B345B4AB, hash)
end
function HasPropsetLoaded(hash)
return Citizen.InvokeNative(0x48A88FC684C55FDC, hash)
end
function CreatePropset(hash, x, y, z, p4, p5, p6, p7, p8)
return Citizen.InvokeNative(0xE65C5CBA95F0E510, hash, x, y, z, p4, p5, p6, p7, p8)
end
function DeletePropset(propSet, p1, p2)
return Citizen.InvokeNative(0x58AC173A55D9D7B4, propSet, p1, p2)
end
function DoesPropsetExist(propSet)
return Citizen.InvokeNative(0x7DDDCF815E650FF5, propSet)
end
function GetEntitiesFromPropset(propSet, itemSet, p2, p3, p4)
return Citizen.InvokeNative(0x738271B660FE0695, propSet, itemSet, p2, p3, p4)
end
function IsPickupTypeValid(pickupHash)
return Citizen.InvokeNative(0x007BD043587F7C82, pickupHash)
end
function IsEntityFrozen(entity)
return Citizen.InvokeNative(0x083D497D57B7400F, entity)
end
function IsPedUsingScenarioHash(ped, scenarioHash)
return Citizen.InvokeNative(0x34D6AC1157C8226C, ped, scenarioHash)
end
function IsPropSetFullyLoaded(propSet)
return Citizen.InvokeNative(0xF42DB680A8B2A4D9, propSet)
end
function PlaceEntityOnGroundProperly(entity, p1)
return Citizen.InvokeNative(0x9587913B9E772D29, entity, p1)
end
function EnableSpoonerMode()
local x, y, z = table.unpack(GetGameplayCamCoord())
local pitch, roll, yaw = table.unpack(GetGameplayCamRot(2))
local fov = GetGameplayCamFov()
Cam = CreateCam("DEFAULT_SCRIPTED_CAMERA", true)
SetCamCoord(Cam, x, y, z)
SetCamRot(Cam, pitch, roll, yaw, 2)
SetCamFov(Cam, fov)
RenderScriptCams(true, true, 500, true, true)
if FocusTarget then
FocusEntity(FocusTarget)
end
SendNUIMessage({
type = 'showSpoonerHud'
})
end
function DisableSpoonerMode()
if Cam then
RenderScriptCams(false, true, 500, true, true)
SetCamActive(Cam, false)
DetachCam(Cam)
DestroyCam(Cam, true)
Cam = nil
end
AttachedEntity = nil
SendNUIMessage({
type = 'hideSpoonerHud'
})
SetNuiFocus(false, false)
end
function ToggleSpoonerMode()
if Cam then
DisableSpoonerMode()
else
EnableSpoonerMode()
end
end
function OpenDatabaseMenu()
UpdateDatabase()
SendNUIMessage({
type = 'openDatabase',
database = json.encode(Database)
})
SetNuiFocus(true, true)
end
function OpenSaveDbMenu()
SendNUIMessage({
type = 'openSaveLoadDbMenu',
databaseNames = json.encode(GetSavedDatabases())
})
SetNuiFocus(true, true)
end
RegisterCommand('spooner', function(source, args, raw)
TriggerServerEvent('spooner:toggle')
end, false)
RegisterCommand('spooner_db', function(source, args, raw)
TriggerServerEvent('spooner:openDatabaseMenu')
end, false)
RegisterCommand('spooner_savedb', function(source, args, raw)
TriggerServerEvent('spooner:openSaveDbMenu')
end, false)
AddEventHandler('spooner:toggle', ToggleSpoonerMode)
AddEventHandler('spooner:openDatabaseMenu', OpenDatabaseMenu)
AddEventHandler('spooner:openSaveDbMenu', OpenSaveDbMenu)
AddEventHandler('spooner:init', function(permissions)
Permissions = permissions
SendNUIMessage({
type = 'updatePermissions',
permissions = json.encode(permissions)
})
end)
AddEventHandler('spooner:refreshPermissions', function()
TriggerServerEvent('spooner:init')
end)
function GetSpoonerEntityType(entity)
return Database[entity] and Database[entity].type or GetEntityType(entity)
end
function GetSpoonerEntityModel(entity)
return Database[entity] and Database[entity].model or GetEntityModel(entity)
end
function GetInView(x1, y1, z1, pitch, roll, yaw)
local rx = -math.sin(math.rad(yaw)) * math.abs(math.cos(math.rad(pitch)))
local ry = math.cos(math.rad(yaw)) * math.abs(math.cos(math.rad(pitch)))
local rz = math.sin(math.rad(pitch))
local x2 = x1 + rx * 10000.0
local y2 = y1 + ry * 10000.0
local z2 = z1 + rz * 10000.0
local retval, hit, endCoords, surfaceNormal, entityHit = GetShapeTestResult(StartShapeTestRay(x1, y1, z1, x2, y2, z2, -1, -1, 1))
if entityHit <= 0 or GetEntityType(entityHit) == 0 then
return endCoords, nil, 0
end
local entityCoords = GetEntityCoords(entityHit)
local distance = #(vector3(x1, y1, z1) - entityCoords)
if distance >= 100.0 then
return endCoords, nil, distance
end
return endCoords, entityHit, distance
end
function GetModelName(model)
for _, name in ipairs(Peds) do
if model == GetHashKey(name) then
return name
end
end
for _, name in ipairs(Vehicles) do
if model == GetHashKey(name) then
return name
end
end
for _, name in ipairs(Objects) do
if model == GetHashKey(name) then
return name
end
end
for _, name in ipairs(Pickups) do
if model == GetHashKey(name) then
return name
end
end
return tostring(model)
end
function GetPlayerFromPed(ped)
for _, playerId in ipairs(GetActivePlayers()) do
if ped == GetPlayerPed(playerId) then
return playerId
end
end
return nil
end
function GetBoneIndex(entity, bone)
if type(bone) == 'number' then
return bone
else
if Config.isRDR then
return GetEntityBoneIndexByName(entity, bone)
else
return GetPedBoneIndex(entity, Bones[bone])
end
end
end
function FindBoneName(entity, boneIndex)
if Config.isRDR then
for _, boneName in ipairs(Bones) do
if GetEntityBoneIndexByName(entity, boneName) == boneIndex then
return boneName
end
end
return boneIndex
else
for boneName, boneId in pairs(Bones) do
if GetPedBoneIndex(entity, boneId) == boneIndex then
return boneName
end
end
return boneIndex
end
end
function GetPedConfigFlags(ped)
local flags = {}
for i = 0, 600 do
flags[i] = GetPedConfigFlag(ped, i)
end
return flags
end
function GetLiveEntityProperties(entity)
local model = GetEntityModel(entity)
local x, y, z = table.unpack(GetEntityCoords(entity))
local pitch, roll, yaw = table.unpack(GetEntityRotation(entity, 2))
local isPlayer = IsPedAPlayer(entity)
local player = isPlayer and GetPlayerFromPed(entity)
local type = GetEntityType(entity)
return {
name = GetModelName(model),
type = type,
model = model,
x = x,
y = y,
z = z,
pitch = pitch,
roll = roll,
yaw = yaw,
health = GetEntityHealth(entity),
outfit = -1,
isInGroup = IsPedGroupMember(entity, GetPlayerGroup(PlayerId())),
collisionDisabled = GetEntityCollisionDisabled(entity),
blockNonTemporaryEvents = false,
isSelf = entity == PlayerPedId(),
playerName = player and GetPlayerName(player),
weapons = {},
isFrozen = Config.isRDR and IsEntityFrozen(entity) or false,
isVisible = IsEntityVisible(entity),
pedConfigFlags = type == 1 and GetPedConfigFlags(entity) or nil,
attachment = {
to = GetEntityAttachedTo(entity),
x = 0.0,
y = 0.0,
z = 0.0,
pitch = 0.0,
roll = 0.0,
yaw = 0.0
},
netId = NetworkGetEntityIsNetworked(entity) and NetworkGetNetworkIdFromEntity(entity),
exists = true
}
end
function AddEntityToDatabase(entity, name, attachment)
if not entity then
return nil
end
if not name and Database[entity] then
name = Database[entity].name
end
local model = Database[entity] and Database[entity].model
local type = Database[entity] and Database[entity].type
local outfit = Database[entity] and Database[entity].outfit or -1
local attachBone, attachX, attachY, attachZ, attachPitch, attachRoll, attachYaw, attachSoftPinning, attachCollision, attachVertex, attachFixedRot
local lightsIntensity = Database[entity] and Database[entity].lightsIntensity or nil
local lightsColour = Database[entity] and Database[entity].lightsColour or nil
local lightsType = Database[entity] and Database[entity].lightsType or nil
local animation = Database[entity] and Database[entity].animation
local scenario = Database[entity] and Database[entity].scenario
local blockNonTemporaryEvents = Database[entity] and Database[entity].blockNonTemporaryEvents or false
local weapons = Database[entity] and Database[entity].weapons or {}
local walkStyle = Database[entity] and Database[entity].walkStyle
local scale = Database[entity] and Database[entity].scale
if attachment then
attachBone = attachment.bone
attachX = attachment.x
attachY = attachment.y
attachZ = attachment.z
attachPitch = attachment.pitch
attachRoll = attachment.roll
attachYaw = attachment.yaw
attachSoftPinning = attachment.useSoftPinning
attachCollision = attachment.collision
attachVertex = attachment.vertex
attachFixedRot = attachment.fixedRot
else
attachBone = (Database[entity] and Database[entity].attachment.bone)
attachX = (Database[entity] and Database[entity].attachment.x or 0.0)
attachY = (Database[entity] and Database[entity].attachment.y or 0.0)
attachZ = (Database[entity] and Database[entity].attachment.z or 0.0)
attachPitch = (Database[entity] and Database[entity].attachment.pitch or 0.0)
attachRoll = (Database[entity] and Database[entity].attachment.roll or 0.0)
attachYaw = (Database[entity] and Database[entity].attachment.yaw or 0.0)
attachSoftPinning = (Database[entity] and Database[entity].attachment.useSoftPinning or false)
attachCollision = (Database[entity] and Database[entity].attachment.collision or true)
attachVertex = (Database[entity] and Database[entity].attachment.vertex or 0)
attachFixedRot = (Database[entity] and Database[entity].attachment.fixedRot or true)
end
local isFrozen = Database[entity] and Database[entity].isFrozen
Database[entity] = GetLiveEntityProperties(entity)
if name then
Database[entity].name = name
end
if model then
Database[entity].model = model
end
if type then
Database[entity].type = type
end
Database[entity].outfit = outfit
Database[entity].attachment.bone = attachBone
Database[entity].attachment.x = attachX
Database[entity].attachment.y = attachY
Database[entity].attachment.z = attachZ
Database[entity].attachment.pitch = attachPitch
Database[entity].attachment.roll = attachRoll
Database[entity].attachment.yaw = attachYaw
Database[entity].attachment.useSoftPinning = attachSoftPinning
Database[entity].attachment.collision = attachCollision
Database[entity].attachment.vertex = attachVertex
Database[entity].attachment.fixedRot = attachFixedRot
Database[entity].lightsIntensity = lightsIntensity
Database[entity].lightsColour = lightsColour
Database[entity].lightsType = lightsType
Database[entity].animation = animation
Database[entity].scenario = scenario
Database[entity].blockNonTemporaryEvents = blockNonTemporaryEvents
Database[entity].weapons = weapons
Database[entity].walkStyle = walkStyle
Database[entity].scale = scale
if not Config.isRDR then
Database[entity].isFrozen = isFrozen
end
return Database[entity]
end
function RemoveEntityFromDatabase(entity)
Database[entity] = nil
end
function GetEntityPropertiesFromDatabase(entity)
return AddEntityToDatabase(entity)
end
function EntityIsInDatabase(entity)
return Database[entity] ~= nil
end
function GetEntityProperties(entity)
if EntityIsInDatabase(entity) then
return GetEntityPropertiesFromDatabase(entity)
else
return GetLiveEntityProperties(entity)
end
end
function GetDatabaseSize()
local n = 0
for entity, props in pairs(Database) do
n = n + 1
end
return n
end
function IsDatabaseFull()
return Permissions.maxEntities and GetDatabaseSize() >= Permissions.maxEntities
end
function LoadModel(model)
if IsModelInCdimage(model) then
RequestModel(model)
while not HasModelLoaded(model) do
Wait(0)
end
return true
else
return false
end
end
function SetWalkStyle(ped, base, style)
Citizen.InvokeNative(0x923583741DC87BCE, ped, base)
Citizen.InvokeNative(0x89F5E7ADECCCB49C, ped, style)
if Database[ped] then
Database[ped].walkStyle = {
base = base,
style = style
}
end
end
function SpawnObject(name, model, x, y, z, pitch, roll, yaw, collisionDisabled, isVisible, lightsIntensity, lightsColour, lightsType)
if not Permissions.spawn.object then
return nil
end
if IsDatabaseFull() then
return nil
end
if not LoadModel(model) then
return nil
end
local object = CreateObjectNoOffset(model, x, y, z, true, false, true)
SetModelAsNoLongerNeeded(model)
if not object or object < 1 then
return nil
end
SetEntityRotation(object, pitch, roll, yaw, 2)
FreezeEntityPosition(object, true)
if collisionDisabled then
SetEntityCollision(object, false, false)
end
if isVisible == false then
SetEntityVisible(object, false)
end
if lightsIntensity then
SetLightsIntensityForEntity(object, lightsIntensity)
end
if lightsColour then
SetLightsColorForEntity(object, lightsColour.red, lightsColour.green, lightsColour.blue)
end
if lightsType then
SetLightsTypeForEntity(object, lightsType)
end
AddEntityToDatabase(object, name)
if not Config.isRDR and Database[object] then
Database[object].isFrozen = true
end
return object
end
function SpawnVehicle(name, model, x, y, z, pitch, roll, yaw, collisionDisabled, isVisible)
if not Permissions.spawn.vehicle then
return nil
end
if IsDatabaseFull() then
return nil
end
if not LoadModel(model) then
return nil
end
local veh = CreateVehicle(model, x, y, z, 0.0, true, false)
SetModelAsNoLongerNeeded(model)
if not veh or veh < 1 then
return nil
end
SetEntityRotation(veh, pitch, roll, yaw, 2)
if collisionDisabled then
FreezeEntityPosition(veh, true)
SetEntityCollision(veh, false, false)
end
if isVisible == false then
SetEntityVisible(veh, false)
end
-- Weird fix for the hot air balloon, otherwise it doesn't move with the wind and only travels straight up.
if model == GetHashKey('hotairballoon01') then
SetVehicleAsNoLongerNeeded(veh)
end
AddEntityToDatabase(veh, name)
if not Config.isRDR and Database[veh] then
Database[veh].isFrozen = collisionDisabled
end
return veh
end
function PlayAnimation(ped, anim)
if not DoesAnimDictExist(anim.dict) then
return false
end
RequestAnimDict(anim.dict)
while not HasAnimDictLoaded(anim.dict) do
Wait(0)
end
TaskPlayAnim(ped, anim.dict, anim.name, anim.blendInSpeed, anim.blendOutSpeed, anim.duration, anim.flag, anim.playbackRate, false, false, false, '', false)
RemoveAnimDict(anim.dict)
return true
end
local function startScenario(ped, scenario)
if Config.isRDR then
TaskStartScenarioInPlace(ped, GetHashKey(scenario), -1)
else
TaskStartScenarioInPlace(ped, scenario, -1)
end
end
function SpawnPed(props)
if not Permissions.spawn.ped then
return nil
end
if IsDatabaseFull() then
return nil
end
if not LoadModel(props.model) then
return nil
end
local ped
if Config.isRDR then
ped = CreatePed_2(props.model, props.x, props.y, props.z, 0.0, true, false)
else
ped = CreatePed(0, props.model, props.x, props.y, props.z, 0.0, true, false)
end
SetModelAsNoLongerNeeded(props.model)
if not ped or ped < 1 then
return nil
end
SetEntityRotation(ped, props.pitch, props.roll, props.yaw, 2)
if props.collisionDisabled then
FreezeEntityPosition(ped, true)
SetEntityCollision(ped, false, false)
end
if props.isVisible == false then
SetEntityVisible(ped, false)
end
if props.outfit == -1 then
SetRandomOutfitVariation(ped, true)
else
SetPedOutfitPreset(ped, props.outfit)
end
if props.isInGroup then
AddToGroup(ped)
end
if props.animation then
PlayAnimation(ped, props.animation)
end
if props.scenario then
Wait(500)
startScenario(ped, props.scenario)
end
if props.blockNonTemporaryEvents then
SetBlockingOfNonTemporaryEvents(ped, true)
end
if props.weapons then
for _, weapon in ipairs(props.weapons) do
if Config.isRDR then
GiveWeaponToPed_2(ped, GetHashKey(weapon), 500, true, false, 0, false, 0.5, 1.0, 0, false, 0.0, false)
else
GiveWeaponToPed(ped, GetHashKey(weapon), 500, false, true)
end
end
end
if props.walkStyle then
SetWalkStyle(ped, props.walkStyle.base, props.walkStyle.style)
end
if props.scale then
SetPedScale(ped, props.scale)
end
if props.pedConfigFlags then
for flag, value in pairs(props.pedConfigFlags) do
SetPedConfigFlag(ped, tonumber(flag), value)
end
end
AddEntityToDatabase(ped, props.name)
Database[ped].outfit = props.outfit
Database[ped].animation = props.animation
Database[ped].scenario = props.scenario
Database[ped].blockNonTemporaryEvents = props.blockNonTemporaryEvents
Database[ped].weapons = props.weapons
Database[ped].walkStyle = props.walkStyle
Database[ped].scale = props.scale
if not Config.isRDR and Database[ped] then
Database[ped].isFrozen = props.collisionDisabled
end
return ped
end
function WaitForPropSetToLoad(propSet)
local timeWaited = 0
while not IsPropSetFullyLoaded(propSet) and timeWaited <= 500 do
Wait(100)
timeWaited = timeWaited + 100
end
return true
end
function SpawnPropset(name, model, x, y, z, heading)
if not Permissions.spawn.propset then
return nil
end
if IsDatabaseFull() then
return nil
end
-- Spawn the propset
RequestPropset(model)
while not HasPropsetLoaded(model) do
Wait(0)
end
local propset = CreatePropset(model, x, y, z, 0, heading, 0.0, false, false)
ReleasePropset(hash)
if not propset or propset < 1 then
return nil
end
-- Give the propset time to fully load
WaitForPropSetToLoad(propset)
-- Objects spawned as part of a propset are not networked, so clone
-- those objects into your DB as new, networked objects, then delete
-- the propset.
local itemset = CreateItemset(true)
local size = GetEntitiesFromPropset(propset, itemset, 0, false, false)
if size > 0 then
for i = 0, size - 1 do
CloneEntity(GetIndexedItemInItemset(i, itemset))
end
end
if IsItemsetValid(itemset) then
DestroyItemset(itemset)
end
DeletePropset(propset, false, false)
return nil
end
function SpawnPickup(name, model, x, y, z)
if not Permissions.spawn.pickup then
return nil
end
if IsDatabaseFull() then
return nil
end
if not IsPickupTypeValid(model) then
return nil
end
local pickup = CreatePickup(model, x, y, z, 0, 0, false, 0, 0, 0.0, 0)
if not pickup or pickup < 1 then
return nil
end
AddEntityToDatabase(pickup, name)
Database[pickup].model = model
Database[pickup].type = 5
return pickup
end
function RequestControl(entity)
local type = GetEntityType(entity)
if type < 1 or type > 3 then
return
end
NetworkRequestControlOfEntity(entity)
end
function CanDeleteEntity(entity)
if EntityIsInDatabase(entity) then
if NetworkGetEntityIsNetworked(entity) then
return Permissions.delete.own.networked
else
return Permissions.delete.own.nonNetworked
end
else
if NetworkGetEntityIsNetworked(entity) then
return Permissions.delete.other.networked
else
return Permissions.delete.other.nonNetworked
end
end
end
function StoreDeletedEntity(entity)
local props = GetLiveEntityProperties(entity)
table.insert(DeletedEntities, {
x = props.x,
y = props.y,
z = props.z,
model = props.model,
})
end
function RemoveEntity(entity)
if not CanDeleteEntity(entity) then
return
end
if IsPedAPlayer(entity) then
return
end
local entityType = GetSpoonerEntityType(entity)
if entityType == 4 then
DeletePropset(entity)
elseif entityType == 5 then
RemovePickup(entity)
else
if StoreDeleted and not EntityIsInDatabase(entity) then
StoreDeletedEntity(entity)
end
RequestControl(entity)
SetEntityAsMissionEntity(entity, true, true)
DeleteEntity(entity)
end
RemoveEntityFromDatabase(entity)
end
function RemoveAllFromDatabase()
local entities = {}
for handle, info in pairs(Database) do
table.insert(entities, handle)
end
for _, handle in ipairs(entities) do
RemoveEntity(handle)