-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathclient.lua
948 lines (893 loc) · 28.3 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
CreateThread(function()
local allow = false
local SceneId = nil
local defaultScope = false
RegisterNetEvent('Scene_creator:allow', function(p)
allow = p
end)
CreateThread(function()
Wait(500)
if Config.AutoEnable then
TriggerServerEvent('Scene_creator:requestAdmin')
end
end)
local sin,cos,abs,pi = math.sin,math.cos,math.abs,math.pi
local hp = (pi/180)
local function RaycastGameplayCamera(distance)
local rotation = GetGameplayCamRot()
local cameraCoord = GetGameplayCamCoord()
local x,z = hp * rotation.x, hp * rotation.z
local a, b, c, d, e = GetShapeTestResult(StartShapeTestRay(cameraCoord.x, cameraCoord.y, cameraCoord.z, (cameraCoord.x + (-sin(z) * abs(cos(x))) * distance), (cameraCoord.y + (cos(z) * abs(cos(x))) * distance), (cameraCoord.z + sin(x) * distance), -1, -1, 1))
return b, c, e
end
local Peds = {}
local Vehicles = {}
local Objects = {}
local EntitySetAs = {}
local function PrepareModel(model,err)
return(((type(model)=='string'and model~='')and GetHashKey(model)or type(model)=='number'and model)or err)
end
local function RequestModelSync(model)
RequestModel(model)
while not HasModelLoaded(model) do
Wait(10)
end
return true
end
local function CreateLocalPed(x,y,z,h,model,network)
if network then network = true else network = false end
model = PrepareModel(model,`a_m_m_mexlabor_01`)
RequestModelSync(model)
return CreatePed(1,model,x,y,z,h,network,false)
end
local function CreateLocalVehicle(x,y,z,h,model,network)
if network then network = true else network = false end
model = PrepareModel(model,`blista`)
RequestModelSync(model)
return CreateVehicle(model,x,y,z,h,network,false)
end
local function CreateLocalObject(x,y,z,model,network)
if network then network = true else network = false end
model = PrepareModel(model,`prop_weed_block_01`)
RequestModelSync(model)
return CreateObject(model,x,y,z,network,false,false)
end
Citizen.CreatePed = CreateLocalPed
Citizen.CreateVehicle = CreateLocalVehicle
Citizen.CreateObject = CreateLocalObject
local function SetEntityFocus(entity,focus,player)
local ped = PlayerPedId()
if focus then
if player then
SetEntityVisible(ped,false,0)
SetEntityLocallyInvisible(ped,true)
end
SetEntityNoCollisionEntity(ped,entity,false)
else
if player then
SetEntityVisible(ped,true,0)
SetEntityLocallyVisible(ped)
end
SetEntityNoCollisionEntity(ped,entity,true)
end
end
local function RequestNetworkControl(ent)
if DoesEntityExist(ent) then
local request = 0
NetworkRequestControlOfEntity(ent)
while not NetworkHasControlOfEntity(ent)and request<50 do
Wait(10)
NetworkRequestControlOfEntity(ent)
request=request+1
end
end
end
local function DeleteNetworkedEntity(entity)
if NetworkGetEntityIsNetworked(entity) then
while not NetworkHasControlOfEntity(entity) and DoesEntityExist(entity) do
NetworkRequestControlOfEntity(entity)
Wait(1)
end
if DoesEntityExist(entity) and NetworkHasControlOfEntity(entity) then
SetEntityAsMissionEntity(entity, false, true)
DeleteEntity(entity)
end
else
SetEntityAsMissionEntity(entity,false,false)
DeleteEntity(entity)
DeleteObject(entity)
end
end
local function DrawXYZGraphFromEntity(entity)
local start = GetEntityCoords(entity)
local x,y,z = start-GetOffsetFromEntityInWorldCoords(entity,2.0,0.0,0.0),start-GetOffsetFromEntityInWorldCoords(entity,0.0,2.0,0.0),start-GetOffsetFromEntityInWorldCoords(entity,0.0,0.0,2.0)
local x1,x2,y1,y2,z1,z2 = start-x,start+x,start-y,start+y,start-z,start+z
DrawLine(x1.x,x1.y,x1.z,x2.x,x2.y,x2.z,255,0,0,255)
DrawLine(y1.x,y1.y,y1.z,y2.x,y2.y,y2.z,0,0,255,255)
DrawLine(z1.x,z1.y,z1.z,z2.x,z2.y,z2.z,0,255,0,255)
end
SendWhenNUIActive({
lang = Config.Language or 'en',
data = Translation[Config.Language or 'en'],
type = 'translations'
})
local function TransformCompressed(data)
data.lang = nil
local retval = {}
for k,v in pairs(data)do
if tonumber(k) then
retval[tonumber(k)] = v
end
end
return retval
end
local nuienabled = false
local lnui = false
local isOn = false
RegisterNUIListener('nuioff', function()
lnui = false
nuienabled = false
isOn = false
end)
local template = {}
CreateThread(function()
while true do
if not allow then
Wait(200)
else
local pPed = PlayerPedId()
if (lnui or nuienabled) then
DisableControlAction(1,24,true)
TaskStandStill(pPed,200)
end
Wait(5)
DisableControlAction(1,37,true)
if not lnui and IsDisabledControlJustPressed(1,37) then
display(true,true)
lnui = true
isOn=true
elseif not nuienabled and lnui and not IsDisabledControlPressed(1,37) and isOn then
nuienabled=false
lnui = false
isOn=false
display(false,false)
elseif lnui and IsDisabledControlJustReleased(1,24) then
nuienabled = true
lnui = true
isOn=true
display(true,false)
end
end
end
end)
local curEnt = nil
local mMode_default = false
local spd = 0.05
CreateThread(function()
local rotation = 0.0
local pitch = 0.0
local roll = 0.0
local set = false
local entType = 0
local mMode = false
while true do
Wait(5)
if not curEnt or not allow then
rotation=0.0
pitch=0.0
roll=0.0
set=false
mMode=mMode_default
if spd > 100 then
spd=1
elseif spd < 0 then
spd=0.05
end
Wait(200)
else
DisableControlAction(1,44,true)
DisableControlAction(1,46,true)
DisableControlAction(1,178,true)
DisableControlAction(1,243,true)
if not set then
SendDebugData('speed',spd)
local is = NetworkGetEntityIsNetworked(curEnt)
SendDebugData('networked','<span '..(is and 'class="green">Yes'or'class="red">No')..'</span>')
SendDebugData('network', '<span '..(EntitySetAs[curEnt] and 'class="green">Yes'or'class="red">No')..'</span>')
FreezeEntityPosition(curEnt,true)
entType = GetEntityType(curEnt)
if entType ~= 1 then
SetEntityDrawOutline(curEnt, true)
SetEntityDrawOutlineColor(255,0,0,100)
else
SetEntityAlpha(curEnt, 200)
end
if entType ~= 3 then
rotation = GetEntityHeading(curEnt)
SendDebugData('rot',rotation)
else
local rot = GetEntityRotation(curEnt)
roll = rot.y
pitch = rot.x
rotation = rot.z
SendDebugData('rot',rotation)
end
SendDebugData('model',GetEntityModel(curEnt))
set=true
end
if IsDisabledControlPressed(1,44) then
rotation=rotation+spd
if rotation>360.0 then
rotation=0.0
end
if entType == 3 then
SetEntityRotation(curEnt, pitch, roll, rotation, false, true)
SendDebugData('rot',GetEntityRotation(curEnt))
else
SetEntityHeading(curEnt, rotation)
SendDebugData('rot',GetEntityHeading(curEnt))
end
elseif IsDisabledControlPressed(1,46) then
rotation=rotation-spd
if rotation<0.0 then
rotation=360.0
end
if entType == 3 then
SetEntityRotation(curEnt, pitch, roll, rotation, false, true)
SendDebugData('rot',GetEntityRotation(curEnt))
else
SetEntityHeading(curEnt, rotation)
SendDebugData('rot',GetEntityHeading(curEnt))
end
end
if IsDisabledControlJustPressed(1,178) then
if entType == 1 then
Peds[curEnt]=nil
elseif entType == 2 then
Vehicles[curEnt]=nil
elseif entType == 3 then
Objects[curEnt]=nil
end
SetEntityDrawOutline(curEnt, false)
ResetEntityAlpha(curEnt)
DeleteNetworkedEntity(curEnt)
TriggerEvent('Scene_creator:saveScene')
curEnt=nil
end
if IsDisabledControlJustPressed(1,243) then
mMode=not mMode
end
if entType==3 then
DisableControlAction(1,34,true)
DisableControlAction(1,30,true)
DisableControlAction(1,20,true)
DisableControlAction(1,73,true)
if IsDisabledControlPressed(1,20) then
pitch=pitch+spd
if pitch>180.0 then
pitch=-180.0
end
SetEntityRotation(curEnt,pitch,roll,rotation,false,true)
elseif IsDisabledControlPressed(1,73) then
pitch=pitch-spd
if pitch<-180.0 then
pitch=180.0
end
SetEntityRotation(curEnt,pitch,roll,rotation,false,true)
end
if IsDisabledControlPressed(1,30) then
roll=roll+spd
if roll>180.0 then
roll=-180.0
end
SetEntityRotation(curEnt,pitch,roll,rotation,false,true)
elseif IsDisabledControlPressed(1,34) then
roll=roll-spd
if roll<-180.0 then
roll=180.0
end
SetEntityRotation(curEnt,pitch,roll,rotation,false,true)
end
end
if IsControlPressed(1, 96) then
spd=spd+0.05
SendDebugData('speed',spd)
elseif IsControlPressed(1, 97) then
if spd-0.05>0 then
spd=spd-0.05
end
SendDebugData('speed',spd)
end
if mMode then
DisableControlAction(1,172,true)
DisableControlAction(1,173,true)
DisableControlAction(1,174,true)
DisableControlAction(1,175,true)
DisableControlAction(1,32,true)
DisableControlAction(1,33,true)
DrawXYZGraphFromEntity(curEnt)
TaskStandStill(PlayerPedId(),100)
if IsDisabledControlPressed(1,172) then
local offset = GetOffsetFromEntityInWorldCoords(curEnt, 0.0, spd, 0.0)
SetEntityCoordsNoOffset(curEnt, offset.x, offset.y, offset.z, false, false, false)
SendDebugData('pos',offset)
elseif IsDisabledControlPressed(1,173) then
local offset = GetOffsetFromEntityInWorldCoords(curEnt, 0.0, -spd, 0.0)
SetEntityCoordsNoOffset(curEnt, offset.x, offset.y, offset.z, false, false, false)
SendDebugData('pos',offset)
end
if IsDisabledControlPressed(1,174) then
local offset = GetOffsetFromEntityInWorldCoords(curEnt, spd, 0.0, 0.0)
SetEntityCoordsNoOffset(curEnt, offset.x, offset.y, offset.z, false, false, false)
SendDebugData('pos',offset)
elseif IsDisabledControlPressed(1,175) then
local offset = GetOffsetFromEntityInWorldCoords(curEnt, -spd, 0.0, 0.0)
SetEntityCoordsNoOffset(curEnt, offset.x, offset.y, offset.z, false, false, false)
SendDebugData('pos',offset)
end
if IsDisabledControlPressed(1,32) then
local offset = GetOffsetFromEntityInWorldCoords(curEnt, 0.0, 0.0, spd)
SetEntityCoordsNoOffset(curEnt, offset.x, offset.y, offset.z, false, false, false)
SendDebugData('pos',offset)
elseif IsDisabledControlPressed(1,33) then
local offset = GetOffsetFromEntityInWorldCoords(curEnt, 0.0, 0.0, -spd)
SetEntityCoordsNoOffset(curEnt, offset.x, offset.y, offset.z, false, false, false)
SendDebugData('pos',offset)
end
else
local hit, coords, entity = RaycastGameplayCamera(1000.0)
if hit then
if entity ~= curEnt and not IsPedAPlayer(entity) then
SetEntityCoords(curEnt, coords.x, coords.y, coords.z, false, false, false, true)
if entType == 3 then
SetEntityRotation(curEnt, pitch, roll, rotation, false, true)
SendDebugData('rot',GetEntityRotation(curEnt))
else
SetEntityHeading(curEnt, rotation)
SendDebugData('rot',GetEntityHeading(curEnt))
end
end
end
end
if IsControlJustPressed(1,191)then
SetEntityDrawOutline(curEnt, false)
ResetEntityAlpha(curEnt)
curEnt = nil
TriggerEvent('Scene_creator:saveScene')
end
end
end
end)
local lastentity = nil
function RegisterEntityAsMoveable(entity, ray)
if lastentity then
SetEntityDrawOutline(lastentity, false)
ResetEntityAlpha(lastentity)
end
if not entity then
return
end
lastentity = entity
FreezeEntityPosition(entity,true)
if ray then curEnt = entity end
end
function SaveMoveableEntity(entity)
if IsEntityAPed(entity) then
Peds[entity]=entity
elseif IsEntityAVehicle(entity) then
Vehicles[entity]=entity
elseif IsEntityAnObject(entity) then
Objects[entity]=entity
end
end
local curMan = nil
RegisterNUICallback('spawn', function(data)
curMan = nil
if data.data == 'S_Ped' then
local coords = GetEntityCoords(PlayerPedId())
local ped = Citizen.CreatePed(coords.x, coords.y, coords.z+5.0, 0.0, IsModelAPed(GetHashKey(data.model))and data.model, data.network)
SetEntityScope(defaultScope,ped)
SaveMoveableEntity(ped)
RegisterEntityAsMoveable(ped, true)
elseif data.data == 'S_Veh' then
local coords = GetEntityCoords(PlayerPedId())
local veh = Citizen.CreateVehicle(coords.x, coords.y, coords.z+5.0, 0.0, IsModelInCdimage(GetHashKey(data.model))and data.model, data.network)
SetEntityScope(defaultScope,veh)
SaveMoveableEntity(veh)
RegisterEntityAsMoveable(veh, true)
elseif data.data == 'S_Obj' then
local coords = GetEntityCoords(PlayerPedId())
local obj = Citizen.CreateObject(coords.x, coords.y, coords.z+5.0, IsModelValid(GetHashKey(data.model))and data.model, data.network)
SetEntityScope(defaultScope,obj)
SaveMoveableEntity(obj)
RegisterEntityAsMoveable(obj, true)
end
TriggerEvent('Scene_creator:saveScene')
end)
RegisterNUICallback('manage', function(data)
curMan = true
end)
CreateThread(function()
local lastEnt = nil
local lastType = nil
while true do
Wait(10)
if not curMan or not allow then
lastEnt = nil
lastType = nil
Wait(200)
else
local hit, coords, entity = RaycastGameplayCamera(1000.0)
if hit then
local ent = (Peds[entity]or Vehicles[entity]or Objects[entity])
if ent and not lastEnt and DoesEntityExist(entity) then
if not lastEnt then
lastType=GetEntityType(ent)
SetEntityFocus(ent,true,true)
if lastType==1 then
SetEntityAlpha(ent,200)
else
SetEntityDrawOutline(ent, true)
end
end
lastEnt = ent
elseif lastEnt and not lastEnt == ent then
if lastEnt then
SetEntityFocus(lastEnt,false,true)
if lastType==1 then
ResetEntityAlpha(lastEnt)
else
SetEntityDrawOutline(lastEnt, false)
end
lastEnt=nil
end
else
if lastEnt ~= ent then
SetEntityFocus(lastEnt,false,true)
if lastType==1 then
ResetEntityAlpha(lastEnt)
else
SetEntityDrawOutline(lastEnt, false)
end
lastEnt=nil
end
end
end
if IsControlJustPressed(1,191)then
if lastEnt then
SetEntityFocus(lastEnt,false,true)
if lastType==1 then
ResetEntityAlpha(lastEnt)
else
SetEntityDrawOutline(ent, false)
end
curEnt=lastEnt
lastEnt=nil
end
curMan = nil
end
end
end
end)
local isSearching = false
RegisterNUICallback('addent', function()
isSearching = true
end)
CreateThread(function()
local lastEnt = nil
local entType = nil
while true do
Wait(10)
if not isSearching or not allow then
Wait(200)
else
local hit, coords, entity = RaycastGameplayCamera(1000.0)
if hit then
if entity~=lastEnt and not (Peds[entity]or Vehicles[entity]or Objects[entity]) and not IsPedAPlayer(entity) and DoesEntityExist(entity) and GetEntityType(entity)~=0 then
if lastEnt then
SetEntityFocus(lastEnt,false,true)
ResetEntityAlpha(lastEnt)
SetEntityDrawOutline(lastEnt, false)
end
lastEnt = entity
entType = GetEntityType(entity)
SetEntityFocus(entity,true,true)
if entType ~= 1 then
SetEntityDrawOutline(entity, true)
SetEntityDrawOutlineColor(255,0,0,100)
else
SetEntityAlpha(entity, 200)
end
elseif lastEnt and entity~=lastEnt then
SetEntityFocus(lastEnt,false,true)
if entType==1 then
ResetEntityAlpha(lastEnt)
else
SetEntityDrawOutline(lastEnt, false)
end
lastEnt = nil
end
if IsControlJustPressed(1,191)then
if lastEnt then
SetEntityScope(defaultScope,lastEnt)
TriggerEvent('Scene_creator:saveScene')
if NetworkGetEntityIsNetworked(lastEnt) then
RequestNetworkControl(lastEnt)
end
SetEntityFocus(lastEnt,false,true)
if entType==1 then
ResetEntityAlpha(lastEnt)
Peds[lastEnt] = lastEnt
else
SetEntityDrawOutline(lastEnt, false)
if entType==2 then
Vehicles[lastEnt] = lastEnt
else
Objects[lastEnt] = lastEnt
end
end
end
isSearching = false
lastEnt = nil
entType = nil
end
end
end
end
end)
RegisterNUICallback('UpdateSettings', function(data)
mMode_default = data.select
Config.SaveDefault = data.change
Config.SaveSpace = data.save
end)
local function DataFunc()
local retval = {}
for k,v in pairs(Peds)do
local net = false
if EntitySetAs[v]~=nil then
net = EntitySetAs[v]
else
net = NetworkGetEntityIsNetworked(v)
end
retval[#retval+1] = {
type = 'Ped',
pos = GetEntityCoords(v),
model = GetEntityModel(v),
heading = GetEntityHeading(v),
network = net
}
end
for k,v in pairs(Vehicles)do
local net = false
if EntitySetAs[v]~=nil then
net = EntitySetAs[v]
else
net = NetworkGetEntityIsNetworked(v)
end
retval[#retval+1] = {
type = 'Veh',
pos = GetEntityCoords(v),
model = GetEntityModel(v),
heading = GetEntityHeading(v),
network = net
}
end
for k,v in pairs(Objects)do
local net = false
if EntitySetAs[v]~=nil then
net = EntitySetAs[v]
else
net = NetworkGetEntityIsNetworked(v)
end
retval[#retval+1] = {
type = 'Obj',
pos = GetEntityCoords(v),
model = GetEntityModel(v),
rot = GetEntityRotation(v),
network = net
}
end
return retval
end
local function GetCurrentData()
return json.encode(DataFunc())
end
local crt = false
RegisterNUICallback('SaveProject', function()
if crt then
TriggerServerEvent('Scene_creator:save_session',GetCurrentData(Config.SaveSpace),Config.SaveSpace)
end
end)
RegisterCommand('createscene', function(_,args)
crt=true
TriggerServerEvent('Scene_creator:create_session',args[1])
end)
RegisterCommand('loadscene', function(_,args)
SceneId=args[1]
TriggerServerEvent('Scene_creator:load_session',args[1])
end)
RegisterNetEvent('Scene_creator:saveTemplate', function()
if crt then
local data = DataFunc()
if #data==0 then
return
else
local first = data[1]
local pos = first.pos
first.pos = nil
local offsets = {{offset=vector3(0,0,0),data=first,ent=0}}
first.pos = GetEntityCoords(first.ent)
for i=2,#data do
local offset = data[i].pos-first.pos
data[i].pos=nil
offsets[i]={offset=offset,data=data[i],ent=0}
end
TriggerServerEvent('Scene_creator:save_template',json.encode(offsets))
end
end
end)
RegisterCommand('loadtemplate', function(_,args)
if args[1] then
SceneId=args[1]
TriggerServerEvent('Scene_creator:load_template',args[1])
end
end)
local mtemp = false
RegisterNetEvent('Scene_creator:load_template', function(data)
crt=true
SendDebugData('id',SceneId)
local data = json.decode(data)
local first = GetOffsetFromEntityInWorldCoords(curEnt, 0.0, 0.0, 5.0)
for i=1,#data do
data[i].data.offset = vector3(data[i].offset.x,data[i].offset.y,data[i].offset.z)
if i~=1 then
data[i].data.pos=first+data[i].data.offset
end
if data[i].data.type=='Ped'then
local ped = Citizen.CreatePed(data[i].data.pos.x, data[i].data.pos.y, data[i].data.pos.z, data[i].data.heading, data[i].data.model, (data[i].data.network~=nil and data[i].data.network~=false))
SetEntityCoordsNoOffset(ped,data[i].data.pos.x, data[i].data.pos.y, data[i].data.pos.z, false, false, false)
Peds[ped]=ped
data[i].ent = ped
FreezeEntityPosition(ped,true)
elseif data[i].data.type=='Veh'then
local veh = Citizen.CreateVehicle(data[i].data.pos.x, data[i].data.pos.y, data[i].data.pos.z, data[i].data.heading, data[i].data.model, (data[i].data.network~=nil and data[i].data.network~=false))
SetEntityCoordsNoOffset(veh,data[i].data.pos.x, data[i].data.pos.y, data[i].data.pos.z, false, false, false)
Vehicles[veh]=veh
data[i].ent = veh
FreezeEntityPosition(veh,true)
elseif data[i].data.type=='Obj'then
local obj = Citizen.CreateObject(data[i].data.pos.x, data[i].data.pos.y, data[i].data.pos.z, data[i].data.model, (data[i].data.network~=nil and data[i].data.network~=false))
SetEntityCoordsNoOffset(obj,data[i].data.pos.x, data[i].data.pos.y, data[i].data.pos.z, false, false, false)
Objects[obj]=obj
data[i].ent = obj
SetEntityRotation(obj,data[i].data.rot.x,data[i].data.rot.y,data[i].data.rot.z,false,true)
FreezeEntityPosition(obj,true)
end
end
template=data
mtemp=true
end)
local function MoveTemplate(coords)
local offset = template[1]
if offset then
SetEntityCoordsNoOffset(offset.ent,coords.x,coords.y,coords.z,false,false,false)
for i=2,#template do
local c = coords+vector3(template[i].offset.x,template[i].offset.y,template[i].offset.z)
SetEntityCoordsNoOffset(template[i].ent,c.x,c.y,c.z,false,false,false)
end
end
mtemp=true
end
RegisterCommand('movetemplate', function()
mtemp=true
end)
local mModeTemp = false
CreateThread(function()
while true do
Wait(10)
if not mtemp or not template[1] or not allow then
Wait(200)
else
DisableControlAction(1,243,true)
if IsDisabledControlJustPressed(1,243) then
mModeTemp=not mModeTemp
end
if mModeTemp then
DisableControlAction(1,172,true)
DisableControlAction(1,173,true)
DisableControlAction(1,174,true)
DisableControlAction(1,175,true)
DisableControlAction(1,32,true)
DisableControlAction(1,33,true)
DisableControlAction(1,44,true)
DisableControlAction(1,46,true)
local curEnt = template[1].ent
DrawXYZGraphFromEntity(curEnt)
TaskStandStill(PlayerPedId(),100)
if IsDisabledControlPressed(1,172) then
local offset = GetOffsetFromEntityInWorldCoords(curEnt, 0.0, spd, 0.0)
MoveTemplate(offset)
elseif IsDisabledControlPressed(1,173) then
local offset = GetOffsetFromEntityInWorldCoords(curEnt, 0.0, -spd, 0.0)
MoveTemplate(offset)
end
if IsDisabledControlPressed(1,174) then
local offset = GetOffsetFromEntityInWorldCoords(curEnt, spd, 0.0, 0.0)
MoveTemplate(offset)
elseif IsDisabledControlPressed(1,175) then
local offset = GetOffsetFromEntityInWorldCoords(curEnt, -spd, 0.0, 0.0)
MoveTemplate(offset)
end
if IsDisabledControlPressed(1,32) then
local offset = GetOffsetFromEntityInWorldCoords(curEnt, 0.0, 0.0, spd)
MoveTemplate(offset)
elseif IsDisabledControlPressed(1,33) then
local offset = GetOffsetFromEntityInWorldCoords(curEnt, 0.0, 0.0, -spd)
MoveTemplate(offset)
end
else
local hit, coords, entity = RaycastGameplayCamera(1000.0)
if hit then
if not (Peds[entity]or Vehicles[entity]or Objects[entity]) then
MoveTemplate(coords)
end
end
end
if IsControlJustPressed(1,191)then
mtemp = false
end
end
end
end)
function SetEntityScope(scope,ent,p)
if ent then
EntitySetAs[ent]=scope
elseif not p then
for k,v in pairs(Peds)do
EntitySetAs[v] = scope
end
for k,v in pairs(Vehicles)do
EntitySetAs[v] = scope
end
for k,v in pairs(Objects)do
EntitySetAs[v] = scope
end
end
end
RegisterNUICallback('TempSelected', function(data)
if data.id == 'set_network' then
SetEntityScope(true)
defaultScope=true
elseif data.id == 'set_local' then
SetEntityScope(false)
defaultScope=false
elseif data.id == 'set_network_c' then
SetEntityScope(true,curEnt,true)
elseif data.id == 'set_local_c' then
SetEntityScope(false,curEnt,true)
end
SendDebugData('network', '<span '..(EntitySetAs[curEnt] and 'class="green">Yes'or'class="red">No')..'</span>')
end)
local function LoadScene(data)
if data.lang then
data = TransformCompressed(data)
end
for i=1,#data do
if data[i].type=='Ped'then
local ped = Citizen.CreatePed(data[i].pos.x, data[i].pos.y, data[i].pos.z, data[i].heading, data[i].model, (data[i].network~=nil and data[i].network~=false))
SetEntityCoordsNoOffset(ped,data[i].pos.x, data[i].pos.y, data[i].pos.z, false, false, false)
Peds[ped]=ped
FreezeEntityPosition(ped,true)
elseif data[i].type=='Veh'then
local veh = Citizen.CreateVehicle(data[i].pos.x, data[i].pos.y, data[i].pos.z, data[i].heading, data[i].model, (data[i].network~=nil and data[i].network~=false))
SetEntityCoordsNoOffset(veh,data[i].pos.x, data[i].pos.y, data[i].pos.z, false, false, false)
Vehicles[veh]=veh
FreezeEntityPosition(veh,true)
elseif data[i].type=='Obj'then
local obj = Citizen.CreateObject(data[i].pos.x, data[i].pos.y, data[i].pos.z, data[i].model, (data[i].network~=nil and data[i].network~=false))
SetEntityCoordsNoOffset(obj,data[i].pos.x, data[i].pos.y, data[i].pos.z, false, false, false)
Objects[obj]=obj
SetEntityRotation(obj,data[i].rot.x,data[i].rot.y,data[i].rot.z,false,true)
FreezeEntityPosition(obj,true)
end
end
end
RegisterNetEvent('Scene_creator:load_session', function(data)
if data then
SendDebugData('id',SceneId)
crt=true
if json.decode(data)then
LoadScene(json.decode(data))
end
end
end)
RegisterNetEvent('Scene_creator:saveScene', function()
if crt and Config.SaveDefault then
TriggerServerEvent('Scene_creator:save_session',GetCurrentData(Config.SaveSpace),Config.SaveSpace)
Wait(10)
SendNotification('Saved Scene With '..#DataFunc()..' Entities')
end
end)
RegisterNetEvent('Scene_creator:createdscene', function(name)
name=name:gsub('.txt',''):gsub('UNSC','')
print("Scene ID:",name)
SceneId=name
SendDebugData('id',SceneId)
end)
RegisterNetEvent('Scene_creator:sceneDeleteAll', function()
DebugDeleteAll()
for k,v in pairs(Peds)do
Peds[k] = nil
DeleteNetworkedEntity(v)
end
for k,v in pairs(Vehicles)do
Vehicles[k] = nil
DeleteNetworkedEntity(v)
end
for k,v in pairs(Objects)do
Objects[k] = nil
DeleteNetworkedEntity(v)
end
template={}
if crt then
crt=false
TriggerServerEvent('Scene_creator:unload')
end
EntitySetAs={}
end)
RegisterNUICallback('admin', function(data)
if data.data then
if data.data == 'AD_VS' then
TriggerServerEvent('Scene_creator:loadFiles', false)
elseif data.data == 'AD_MF' then
TriggerServerEvent('Scene_creator:loadFiles', true)
end
end
end)
RegisterNetEvent('Scene_creator:loadFiles', function(data,is)
SendNUIMessage({
type="admin",
data=data,
is=is
})
end)
RegisterNUICallback('adminselected', function(data)
if data.command == 'remove_file'or data.command == 'see_content'then
TriggerServerEvent('Scene_creator:manageFile', data.command, data.file)
else
TriggerServerEvent('Scene_creator:manageScene', data.command, data.file)
end
end)
RegisterNUICallback('setscenedata', function(data)
TriggerServerEvent('Scene_creator:setSceneData', data.file, data.data)
end)
RegisterNetEvent('Scene_creator:manageFile', function(data)
SendNotification('Peds: '..data.Ped..'; Vehs: '..data.Veh..'; Objs: '..data.Obj..'; All: '..data.Ent)
end)
local admin = false
RegisterNetEvent('Scene_creator:openAdmin', function()
admin=not admin
SendNUIMessage({
type='showadmin',
show=admin
})
SetNuiFocus(admin,admin)
end)
RegisterNUIListener('nuioff', function()
admin=false
end)
for k,v in pairs(Config.Commands)do
if v.name then
RegisterCommand(v.name,function()
TriggerServerEvent('Scene_creator:'..v.name)
end)
if #v.Keys == 1 then
RegisterKeyMapping(v.name,v.name,'keyboard',v.Keys[1])
elseif #v.Keys>1 then
RegisterKeybind(v.name,v.Keys)
end
else
RegisterKeybind(v.name,v.Keys)
end
end
end)