-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoffedit.lua
More file actions
1206 lines (1127 loc) · 38.5 KB
/
offedit.lua
File metadata and controls
1206 lines (1127 loc) · 38.5 KB
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 minc_default = 1
local mrinc_default = 15
local invalidmodels
local playerobj = {}
local maxobjects = 1500
local mapinfo = {}
local minc = {}
local mrinc = {}
local objects = {}
local gridlines = {}
local resourcemaps = {}
local realx, realy, realz = {}, {}, {}
local realrx, realry, realrz = {}, {}, {}
local nyiggas = {
'A25B7706EE8A96E9CD6F9E66AC42B343' --ishi
}
addCommandHandler('guestb',
function (player, command, name)
--if hasPerms(player) then
if hasObjectPermissionTo(player, 'function.kickPlayer', true) or getElementData(player, 'staff') == true then
local guest = getPlayerFromPartialName(name)
if guest then
local name = getPlayerName(guest)
if getElementData(guest, 'builder') == false then
outputChatBox('#0AC3F5'..name..' recieved map editor pass.', root, 255, 255, 255, true)
setElementData(guest, 'builder' , true)
else
outputChatBox('#0AC3F5'..name..' map editor pass removed.', root, 255, 255, 255, true)
setElementData(guest, 'builder' , false)
end
else
outputChatBox('Can not find player "'..name..'"', player)
end
else
outputChatBox('You do not have permission to do that.', player)
end
end
)
addCommandHandler('mappers',
function (player)
local mappers = {}
for k,v in pairs(getElementsByType('player')) do
if getElementData(v, 'builder') == true or getElementData(v, 'staff') == true then
table.insert(mappers, getPlayerName(v))
end
end
if #mappers > 0 then
outputChatBox('#0AC3F5Bob the builders: #e7d9b0'..table.concat(mappers, ", "), player, 231, 217, 176, true)
else
outputChatBox('There are no builders', player, 231, 217, 176, true)
end
end
)
addCommandHandler('mcreate',
function (player, command, objectid, width, depth, height)
if invalidmodels[objectid] then
return outputChatBox(objectid.. ' is not a valid model ID.', player)
end
if hasPerms(player) then
if not playerobj[player] then
if objectid then
local var = objectid
local x, y, z = getElementPosition(player)
local x, y, z = x + 2, y + 2, z
local int, dim = getElementInterior(player), getElementDimension(player)
if type(tonumber(var)) == 'number' then
local var = tonumber(var)
if var > 611 and var <= 20000 or (var <= 372 and var >= 321) then --objects
playerobj[player] = createObject(var, x, y, z)
elseif var <= 611 and var >= 400 then --vehicles
playerobj[player] = createVehicle(var, x, y, z)
elseif var <= 312 then --peds
playerobj[player] = createPed(var, x, y, z)
end
else
if var == 'water' then
if width and depth and height then
playerobj[player] = createWater(x - (.5 * width), y - (.5 * depth), height, x + (.5 * width), y - (.5 * depth), height, x - (.5 * width), y + (.5 * depth), height, x + (.5 * width), y + (.5 * depth), height)
else
outputChatBox('SYNTAX: /mcreate water <width> <depth> <height>', player)
end
else
local veh = getVehicleModelFromName(var)
if veh then
playerobj[player] = createVehicle(veh, x, y, z)
end
end
end
if playerobj[player] then
bindMovementKeys(player)
setElementInterior(playerobj[player], int)
setElementDimension(playerobj[player], dim)
if getElementType(playerobj[player]) == 'vehicle' or getElementType(playerobj[player]) == 'ped' then
setElementFrozen(playerobj[player], true)
end
setRealValues(playerobj[player], x, y, z, 0, 0, 0)
updateGridlines(playerobj[player], true)
else
outputChatBox(var.. ' is not a valid model ID.', player)
end
else
outputChatBox('SYNTAX: /mcreate objectID [width depth height]', player)
end
else
outputChatBox('You are already editing an object. Please save or delete to make another.', player)
end
end
end
)
--[[addCommandHandler('createwater',
function (player, command, southWest_X, southWest_Y, southWest_Z, southEast_X, southEast_Y, southEast_Z, northWest_X, northWest_Y, NorthWest_Z, northEast_X, northEast_Y, northEast_Z)
if northEast_Z then
water = createWater(southWest_X, southWest_Y, southWest_Z, southEast_X, southEast_Y, southEast_Z, northWest_X, northWest_Y, NorthWest_Z, northEast_X, northEast_Y, northEast_Z)
if water then
outputChatBox('Created water', player)
else
outputChatBox('nyigga bs')
end
else
outputChatBox('You must supply all 4 sets of values', player)
end
end
)]]
addCommandHandler('vehcol',
function (player, command, ...)
if playerobj[player] then
local model = getElementModel(playerobj[player])
if tonumber(model) <= 611 and tonumber(model) >= 400 then
local colors = { getVehicleColor(playerobj[player]) }
local args = { ... }
for i=1,12 do
if not args[i] then args[i] = 255 end
colors[i] = args[i] and tonumber(args[i]) or colors[i]
end
setVehicleColor(playerobj[player], unpack(colors))
else
outputChatBox('You must be editing a vehicle to change its colour.', player)
end
end
end
)
addCommandHandler('mclone',
function (player, command, times, addx, addy, addz, addrx, addry, addrz)
if hasPerms(player) then
if type(tonumber(times)) == 'number' then
local times = tonumber(times)
if times < 50 and times >= 1 then
if playerobj[player] then
local model = getElementModel(playerobj[player])
local addx, addy, addz, addrx, addry, addrz = addx or 0, addy or 0, addz or 0, addrx or 0, addry or 0, addrz or 0
local int, dim = getElementInterior(player), getElementDimension(player)
local type = getElementType(playerobj[player])
for i=1,times do
local x, y, z = getElementPosition(playerobj[player])
local rx, ry, rz = getElementRotation(playerobj[player])
local scalex, scaley, scalez = getObjectScale(playerobj[player])
local collon = getElementCollisionsEnabled(playerobj[player])
local newx, newy, newz = x + addx, y + addy, z + addz
local newrx, newry, newrz = rx + addrx, ry + addry, rz + addrz
saveObject(player)
if type == 'object' then
playerobj[player] = createObject(model, newx, newy, newz, newrx, newry, newrz)
setElementCollisionsEnabled (playerobj[player], collon)
setObjectScale(playerobj[player], scalex, scaley, scalez)
elseif type == 'vehicle' then
playerobj[player] = createVehicle(model, newx, newy, newz, newrx, newry, newrz)
setElementFrozen(playerobj[player], true)
elseif type == 'ped' then
playerobj[player] = createPed(model, newx, newy, newz, addrz, true)
setElementFrozen(playerobj[player], true)
end
setRealValues(playerobj[player], newx, newy, newz, newrx, newry, newrz)
setElementInterior(playerobj[player], int)
setElementDimension(playerobj[player], dim)
updateGridlines(playerobj[player], false)
end
end
if playerobj[player] then
updateGridlines(playerobj[player], true)
else
outputChatBox('Failed to clone model. Make sure you have one selected.', player)
end
else
outputChatBox('Failed to clone model. You can only clone between 1 and 50 items at once.', player)
end
else
outputChatBox('SYNTAX: /mclone times addX [addY addZ addRX addRY addRZ]', player)
end
end
end
)
addCommandHandler('mloopold',
function (player, command, pieces, radi, offset, rotaxis, loops, rota)
if hasPerms(player) then
local angle
local newi
local loops = tonumber(loops) or 1
if rota then
rota = rota*(math.pi/180)
else
rota = 0
end
if radi and pieces and offset then
radi = tonumber(radi)
pieces = tonumber(pieces)
offset = tonumber(offset)
local spiralp = math.atan((offset/2)/(2*radi))/loops
if playerobj[player] then
local orx, ory, orz = getElementPosition(playerobj[player])
local int, dim = getElementInterior(player), getElementDimension(player)
newi = -1
for i=0,pieces do
local x, y, z = getElementPosition(playerobj[player])
local rx, ry, rz = getObjectRotation(playerobj[player])
local model = getElementModel(playerobj[player])
saveObject(player)
local weight = 1-(1/(pieces/2))*math.abs((pieces/2)-i)
local radians =(i/pieces)*(2*math.pi)*loops
local newx = orx + radi*math.sin(radians)*math.cos(rota)+(offset/2)*math.cos(radians/(2*loops))*-math.sin(rota)
local newy = ory +(offset/2)*math.cos(radians/(2*loops))*math.cos(rota)+radi*math.sin(radians)*math.sin(rota)
local newz = orz + radi*-math.cos(radians)
newi = newi + 1
angle = (((360/pieces)* loops)* newi)
if rotaxis == 'x' then
newrotx = angle
newroty = ry --+((radians)-math.cos(rota)*spiralp*weight)
elseif rotaxis == '-x' then
newrotx = -angle
newroty = ry --+((radians)-math.cos(rota)*spiralp*weight)
elseif rotaxis == 'y' then
newrotx = rx --+((radians)-math.cos(rota)*spiralp*weight)
newroty = angle
elseif rotaxis == '-y' then
newrotx = rx --+((radians)-math.cos(rota)*spiralp*weight)
newroty = -angle
end
newz = newz + radi
playerobj[player] = createObject(model, newx, newy, newz, newrotx, newroty, rz)
setRealValues(playerobj[player], newx, newy, newz, newrotx, newroty, rz)
setElementInterior(playerobj[player], int)
setElementDimension(playerobj[player], dim)
updateGridlines(playerobj[player], true)
end
end
if not playerobj[player] then
outputChatBox('Failed to loop object. Make sure you have one selected.', player)
end
else
outputChatBox('SYNTAX: /mloop pieces radius offset [rotaxis loops rota]', player)
end
end
end
)
addCommandHandler('mloop',
function (player, command, pieces, radi, offset, rotaxis, rota, loops)
if hasPerms(player) then
local angle
local newi
local loops = tonumber(loops) or 1
if rota then
rota = rota*(math.pi/180)
else
rota = 0
end
if radi and pieces and offset then
radi = tonumber(radi)
pieces = tonumber(pieces)
offset = tonumber(offset)
local spiralp = math.atan((offset/2)/(2*radi))/loops
if playerobj[player] then
local orx, ory, orz = getElementPosition(playerobj[player])
local int, dim = getElementInterior(player), getElementDimension(player)
newi = -1
for i=0,pieces do
local x, y, z = getElementPosition(playerobj[player])
local rx, ry, rz = getObjectRotation(playerobj[player])
local model = getElementModel(playerobj[player])
saveObject(player)
local weight = 1-(1/(pieces/2))*math.abs((pieces/2)-i)
local radians =(i/pieces)*(2*math.pi)*loops
--local newx = orx + radi*math.sin(radians)*math.cos(rota)+(offset/2)*math.cos(radians/(2*loops))*-math.sin(rota)
--local newy = ory +(offset/2)*math.cos(radians/(2*loops))*math.cos(rota)+radi*math.sin(radians)*math.sin(rota)
local newz = orz + radi*-math.cos(radians)
newi = newi + 1
angle = (((360/pieces)* loops)* newi)
if rotaxis == 'x' then
newrotx = angle
newroty = ry --+((radians)-math.cos(rota)*spiralp*weight)
newx = x + (offset/pieces)
newy = ory +(offset/2)*math.cos(radians/(2*loops))*math.cos(rota)+radi*math.sin(radians)*math.sin(rota)
elseif rotaxis == '-x' then
newrotx = -angle
newroty = ry --+((radians)-math.cos(rota)*spiralp*weight)
newx = x - (offset/pieces)
newy = ory +(offset/2)*math.cos(radians/(2*loops))*math.cos(rota)+radi*math.sin(radians)*math.sin(rota)
elseif rotaxis == 'y' then
newrotx = rx --+((radians)-math.cos(rota)*spiralp*weight)
newroty = angle
newx = orx + radi*math.sin(radians)*math.cos(rota)+(offset/2)*math.cos(radians/(2*loops))*-math.sin(rota)
newy = y + (offset/pieces)
elseif rotaxis == '-y' then
newrotx = rx --+((radians)-math.cos(rota)*spiralp*weight)
newroty = -angle
newy = y - (offset/pieces)
newx = orx + radi*math.sin(radians)*math.cos(rota)+(offset/2)*math.cos(radians/(2*loops))*-math.sin(rota)
end
newz = newz + radi
playerobj[player] = createObject(model, newx, newy, newz, newrotx, newroty, rz)
setRealValues(playerobj[player], newx, newy, newz, newrotx, newroty, rz)
setElementInterior(playerobj[player], int)
setElementDimension(playerobj[player], dim)
--updateGridlines(playerobj[player], true)
end
saveObject(player)
else
outputChatBox('Failed to loop object. Make sure you have one selected.', player)
end
else
outputChatBox('SYNTAX: /mloop pieces radius offset [rotaxis rotation loops]', player)
end
end
end
)
local acceptstrings = {
yes = {['yes'] = true, ['true'] = true, ['1'] = true, ['y'] = true},
no = {['no'] = true, ['false'] = true, ['0'] = true, ['n'] = true}
}
function yayOrNay(str)
if acceptstrings.yes[string.lower(tostring(str))] then
return true, 'on'
end
return false, 'off'
end
addCommandHandler('mcol',
function (player, command, col)
if playerobj[player] then
local colon, str = yayOrNay(col)
setElementCollisionsEnabled(playerobj[player], colon)
outputChatBox('Object collisions '..str, player)
end
end
)
addCommandHandler('mbreak',
function (player, command, breakable)
if playerobj[player] then
local breakme, str = yayOrNay(breakable)
triggerClientEvent('setObjectBreakability', root, playerobj[player], breakme)
setElementFrozen(playerobj[player], not breakme) -- some objects are 'broken' by physics. freezing them is a solution.
outputChatBox('Object breakability '..str, player)
end
end
)
local movementkeys = {
num_4 = {axis = 'ox', direction = -1},
num_6 = {axis = 'ox', direction = 1},
num_8 = {axis = 'oy', direction = 1},
num_2 = {axis = 'oy', direction = -1},
num_add = {axis = 'oz', direction = 1},
num_sub = {axis = 'oz', direction = -1},
num_7 = {axis = 'rx', direction = 1},
num_9 = {axis = 'rx', direction = -1},
num_1 = {axis = 'ry', direction = 1},
num_3 = {axis = 'ry', direction = -1},
num_div = {axis = 'rz', direction = 1},
num_mul = {axis = 'rz', direction = -1}
}
function bindMovementKeys(player)
for k,_ in pairs (movementkeys) do
bindKey(player, k, 'down', movementkeys[k].axis, 'false '..movementkeys[k].direction)
end
toggleControl(player, "special_control_left", false)
toggleControl(player, "special_control_right", false)
toggleControl(player, "look_behind", false)
bindKey(player, 'num_5', 'down', changeInc)
end
function unbindMovementKeys(player)
for k,_ in pairs (movementkeys) do
unbindKey(player, k, 'down', movementkeys[k].axis)
end
toggleControl(player, "special_control_left", true)
toggleControl(player, "special_control_right", true)
toggleControl(player, "look_behind", true)
unbindKey(player, 'num_5', 'down', changeInc)
end
function _moveObject(player, command, value, direction)
if playerobj[player] then
if value == 'false' then
local startswith = command:sub(1,1)
if startswith:lower() == 'o' then
value = minc[player] * direction
else
value = mrinc[player] * direction
end
end
local value = tonumber(value)
if type(value) ~= 'number' then
outputChatBox('SYNTAX: /'..command..' float', player)
end
--local x, y, z = getElementPosition(playerobj[player])
local element = playerobj[player]
local rx, ry, rz = 0, 0, 0
if command == 'ox' then
realx[element] = realx[element] + value
elseif command == 'oy' then
realy[element] = realy[element] + value
elseif command == 'oz' then
realz[element] = realz[element] + value
elseif command == 'rx' then
rx = value
elseif command == 'ry' then
ry = value
elseif command == 'rz' then
rz = value
end
local type = getElementType(element)
if command == 'ox' or command == 'oy' or command == 'oz' then
if type == 'object' then
moveObject(element, 200, realx[element], realy[element], realz[element])
elseif type == 'ped' or type == 'vehicle' then
setElementPosition(element, realx[element], realy[element], realz[element])
setElementFrozen(element, true)
else
setElementPosition(element, realx[element], realy[element], realz[element])
end
elseif command == 'rx' or command == 'ry' or command == 'rz' then
if type == 'object' then
stopObject(element)
local currentrx, currentry, currentrz = getElementRotation(element)
local diffrx, diffry, diffrz = realrx[element] - currentrx, realry[element] - currentry, realrz[element] - currentrz
setRealRotValues(element, rx, ry, rz)
moveObject(element, 200, realx[element], realy[element], realz[element], rx + diffrx, ry + diffry, rz + diffrz)
elseif type == 'ped' or type == 'vehicle' then
setElementRotation(element, rx + realrx[element], ry + realry[element], rz + realrz[element])
setElementFrozen(element, true)
else
setElementRotation(element, rx + realrx[element], ry + realry[element], rz + realrz[element])
end
end
end
end
local movementcommands = {'ox', 'oy', 'oz', 'rx', 'ry', 'rz'}
for _,v in pairs (movementcommands) do
addCommandHandler(v, _moveObject)
end
function setInc(player, command, value)
minc[player] = tonumber(value)
outputChatBox('Movement incriments set to ' ..value.. '', player)
end
addCommandHandler('minc', setInc)
function setRInc(player, command, value)
mrinc[player] = tonumber(value)
outputChatBox('Rotational incriments set to ' ..value.. '', player)
end
addCommandHandler('mrinc', setRInc)
function changeInc(player)
if minc[player] == 1 then
minc[player] = 0.1
outputChatBox('Incriments set to 0.1', player)
elseif minc[player] == 0.1 then
minc[player] = 0.01
outputChatBox('Incriments set to 0.01', player)
elseif minc[player] == 0.01 then
minc[player] = 0.005
outputChatBox('Incriments set to 0.005', player)
elseif minc[player] == 0.005 then
minc[player] = 1
outputChatBox('Incriments set to 1', player)
else
minc[player] = 1
outputChatBox('Incriments set to 1', player)
end
end
addCommandHandler('mscale',
function (player, command, scalex, scaley, scalez)
if tonumber(scalex) then
if not scalez then
scaley = scalex
scalez = scalex
end
if playerobj[player] then
if getElementType(playerobj[player]) == 'object' then
local model = getElementModel(playerobj[player])
if model then
setObjectScale(playerobj[player], scalex, scaley, scalez)
end
else
outputChatBox('Only objects can be scaled.', player)
end
else
outputChatBox('You must select an object.', player)
end
else
outputChatBox('SYNTAX: /mscale scale or /mscale scaleX scaleY scaleZ', player)
end
end
)
function destroyObject(player, command, id)
if hasPerms(player) then
local element
local num = false
if id then
if type(tonumber(id)) == 'number' then
id = tonumber(id)
num = id
if objects[id] then
element = objects[id]
end
else
outputChatBox('Invalid object ID: '..id, player)
end
else
if playerobj[player] then
element = playerobj[player]
unbindMovementKeys(player)
for k in pairs (objects) do
if objects[k] == playerobj[player] then
num = k
break
end
end
else
outputChatBox('You must be either editing an object or supply a valid object ID', player)
end
end
if element then
if num then
outputChatBox('Object ID deleted: ' ..num, player)
objects[num] = false
else
outputChatBox('Current object deleted.', player)
end
local editing = getPlayersEditingObject(element)
for _,v in pairs (editing) do
playerobj[v] = false
end
updateGridlines(element, false)
unsetRealValues(element)
destroyElement(element)
end
end
end
addCommandHandler('mdestroy', destroyObject)
function saveObject(player, command)
if hasPerms(player) then
if playerobj[player] then
local model = getElementModel(playerobj[player])
local first = true
local id
for i=0,maxobjects+1 do
if objects[i] == playerobj[player] then
id = i
break
elseif not objects[i] then
if first then
first = false
id = i
else
break
end
end
end
if id > maxobjects then return outputChatBox('You have reached the limit of objects.', player) end
if getElementType(playerobj[player]) == 'vehicle' or getElementType(playerobj[player]) == 'ped' then
setElementFrozen(playerobj[player], false)
end
objects[id] = playerobj[player]
outputChatBox('Object saved as ID: ' ..id, player)
unbindMovementKeys(player)
local editing = getPlayersEditingObject(playerobj[player])
if not (#editing > 1) then
updateGridlines(playerobj[player], false)
unsetRealValues(playerobj[player])
end
playerobj[player] = false
end
end
end
addCommandHandler('msave', saveObject)
addCommandHandler('msel',
function (player, command, id)
if hasPerms(player) then
id = tonumber(id)
if playerobj[player] then
saveObject(player)
end
if objects[id] then
playerobj[player] = objects[id]
bindMovementKeys(player)
updateGridlines(playerobj[player], true)
local x, y, z = getElementPosition(playerobj[player])
local rx, ry, rz = getElementRotation(playerobj[player])
setRealValues(playerobj[player], x, y, z, rx, ry, rz)
outputChatBox('Object ID selected: ' ..id.. '', player)
end
end
end
)
addCommandHandler('minfo',
function (player, command, id)
if hasPerms(player) then
local element
if id then
local id = tonumber(id)
if objects[id] then
element = objects[id]
else
outputChatBox('Invalid object ID: '..id, player)
end
else
if playerobj[player] then
element = playerobj[player]
else
outputChatBox('You must be editing an object or supply a valid ID.', player)
end
end
if element then
local model = getElementModel(element)
if not model then return end
local x, y, z = getElementPosition(element)
local rx, ry, rz = getElementRotation(element)
local scalex, scaley, scalez = getObjectScale(element)
outputChatBox('Object Info - Object Model ID: ' .. model, player)
outputChatBox('Pos X: ' .. x .. ' Pos Y: ' .. y .. ' Pos Z: ' .. z, player)
outputChatBox('Rot X: ' .. rx .. ' Rot Y: ' .. ry .. ' Rot Z: ' .. rz, player)
outputChatBox('Scale X: '..scalex..' Scale Y: '..scaley..' Scale Z: '..scalez, player)
end
end
end
)
addCommandHandler('saveasmap',
function (player, command, mapname)
if hasPerms(player) then
if mapname then
local file = xmlCreateFile('maps/'..mapname..'.map', 'map')
xmlMetaBranch = xmlCreateChild(file, 'meta')
xmlInfoChild = xmlCreateChild(xmlMetaBranch, 'info')
xmlNodeSetAttribute(xmlInfoChild, 'name', 'In-game map editor')
xmlNodeSetAttribute(xmlInfoChild, 'author', 'JohnFlower')
xmlNodeSetAttribute(xmlInfoChild, 'description', 'File Generated with offedit')
for i=0,#objects do
if objects[i] then
local model = getElementModel(objects[i])
if model then
local x, y, z = getElementPosition(objects[i])
local rx, ry, rz = getElementRotation(objects[i])
if tonumber(model) <= 611 and tonumber(model) >= 400 then
local col1, col2, col3, col4 = getVehicleColor(objects[i])
xmlVehiclesBranch = xmlCreateChild(file, 'vehicle')
xmlNodeSetAttribute(xmlVehiclesBranch, 'id', i)
xmlNodeSetAttribute(xmlVehiclesBranch, 'posX', x)
xmlNodeSetAttribute(xmlVehiclesBranch, 'posY', y)
xmlNodeSetAttribute(xmlVehiclesBranch, 'posZ', z)
xmlNodeSetAttribute(xmlVehiclesBranch, 'rotX', rx)
xmlNodeSetAttribute(xmlVehiclesBranch, 'rotY', ry)
xmlNodeSetAttribute(xmlVehiclesBranch, 'rotZ', rz)
xmlNodeSetAttribute(xmlVehiclesBranch, 'model', model)
xmlNodeSetAttribute(xmlVehiclesBranch, 'col1', col1)
xmlNodeSetAttribute(xmlVehiclesBranch, 'col2', col2)
xmlNodeSetAttribute(xmlVehiclesBranch, 'col3', col3)
xmlNodeSetAttribute(xmlVehiclesBranch, 'col4', col4)
elseif tonumber(model) <= 312 then
xmlPedBranch = xmlCreateChild(file, 'ped')
xmlNodeSetAttribute(xmlPedBranch, 'id', i)
xmlNodeSetAttribute(xmlPedBranch, 'posX', x)
xmlNodeSetAttribute(xmlPedBranch, 'posY', y)
xmlNodeSetAttribute(xmlPedBranch, 'posZ', z)
xmlNodeSetAttribute(xmlPedBranch, 'rotX', rx)
xmlNodeSetAttribute(xmlPedBranch, 'rotY', ry)
xmlNodeSetAttribute(xmlPedBranch, 'rotZ', rz)
xmlNodeSetAttribute(xmlPedBranch, 'model', model)
else
xmlObjectsBranch = xmlCreateChild(file, 'object')
xmlNodeSetAttribute(xmlObjectsBranch, 'id', i)
xmlNodeSetAttribute(xmlObjectsBranch, 'posX', x)
xmlNodeSetAttribute(xmlObjectsBranch, 'posY', y)
xmlNodeSetAttribute(xmlObjectsBranch, 'posZ', z)
xmlNodeSetAttribute(xmlObjectsBranch, 'rotX', rx)
xmlNodeSetAttribute(xmlObjectsBranch, 'rotY', ry)
xmlNodeSetAttribute(xmlObjectsBranch, 'rotZ', rz)
xmlNodeSetAttribute(xmlObjectsBranch, 'model', model)
end
end
end
end
xmlSaveFile(file)
xmlUnloadFile(file)
outputChatBox('You saved ' .. mapname, player)
end
end
end
)
addCommandHandler('mapinfo',
function(player, command, mapname)
if hasPerms(player) then
local info = false
if mapname then
if fileExists('maps/' ..mapname..'.json') then
local file = fileOpen('maps/'..mapname..'.json')
local size = fileGetSize(file)
local buffer = fileRead(file, size)
local tempdata = fromJSON(buffer)
fileClose(file)
info = tempdata.info
tempdata = {}
else
outputChatBox(mapname..' does not exist', player)
end
else
info = mapinfo
end
if info then
outputChatBox('Creator: '..info.creator..' - Serial: '..info.serial..' - IP: '..info.ip..' - Time: '..info.time, player)
end
else
return outputChatBox ('#FA1464Only administrators can use this command', player, 255, 255, 255, true)
end
end
)
function clearPlayerObjects(player)
if hasPerms(player) then
for i=0,maxobjects do
if isElement(objects[i]) then
destroyElement(objects[i])
end
end
objects = {}
realx, realy, realz = {}, {}, {}
realrx, realry, realrz = {}, {}, {}
for k,v in ipairs (getElementsByType('player')) do
if playerobj[v] then
updateGridlines(playerobj[v], false)
destroyElement(playerobj[v])
end
playerobj[v] = false
unbindMovementKeys(v)
end
outputChatBox('Map cleared.')
end
end
addCommandHandler('mclear', clearPlayerObjects)
addCommandHandler('delmap',
function (player, command, type, string)
if hasPerms(player) then
if type and string then
if type == 'file' then
if fileExists('maps/' ..string..'.json') then
fileDelete('maps/' ..string..'.json')
outputChatBox('Deleted '..string, player)
outputDebugString('(ADMIN.offedit) '..getPlayerName(player)..' deleted map '..string)
else
outputChatBox(string..' does not exist', player)
end
--[[else
local files = {}
local fsys = createFilesystemInterface()
local dir = fsys.createTranslator('/home/server/mta_ramdisk/mods/deathmatch/resources/flowerattach/attachments/')
local function dirIterator(dirPath)
return
end
local function fileIterator(filePath)
local name = dir.relPathRoot(filePath)
table.insert(files, name)
end
dir.scanDirEx('@', '*', dirIterator, fileIterator, false)
for k,v in ipairs (files) do
outputChatBox(tostring(v))
break
end
if type == 'serial' then
elseif type == 'name' then
elseif type == 'ip' then
else
outputChatBox('SYNTAX: /delattach [id|file|serial|name|ip] <string>', player)
end]]
end
else
outputChatBox('SYNTAX: /delmap [id|file|serial|name|ip] <string>', player)
end
else
outputChatBox ('#FA1464Only administrators can use this command.', player, 255, 255, 255, true)
end
end
)
function updateGridlines(element, state)
if state == true then
gridlines[element] = true
else
gridlines[element] = nil
end
triggerClientEvent('updateGridlines', root, gridlines)
end
function getPlayerFromPartialName(name)
local matches = {}
for i,player in ipairs (getElementsByType('player')) do
if getPlayerName(player) == name then
return player
end
if string.find(string.lower(getPlayerName(player)),string.lower(name),0,false) then
table.insert(matches,player)
end
end
if #matches == 1 then
return matches[1]
else
return false
end
end
addCommandHandler('convertmap',
function (player, command, mapname)
if hasPerms(player) then
loadMapLua(player, mapname)
saveMap(player, mapname)
else
outputChatBox('You do not have permission to build.')
end
end
)
addCommandHandler('savemap',
function (player, command, mapname)
if hasPerms(player) then
saveMap(player, mapname)
end
end
)
addCommandHandler('loadmap',
function (player, command, mapname, int, dim)
if hasPerms(player) then
if fileExists('maps/'..mapname..'.json') then
clearPlayerObjects(player)
loadMap(mapname, objects, int or nil, dim or nil)
outputChatBox('New map loaded.')
outputChatBox('Map loaded: ' ..mapname, player)
outputDebugString('(ADMIN.offedit) player '..getPlayerName(player)..' loaded map '..mapname)
else
outputChatBox(mapname.. " doesn't exist", player)
end
end
end
)
function saveMap(player, mapname)
if mapname then
if not string.find(mapname, '%W') then
local tempdata = {}
tempdata['info'] = {}
tempdata['info']['creator'] = getPlayerName(player)
tempdata['info']['serial'] = getPlayerSerial(player)
tempdata['info']['ip'] = getPlayerIP(player)
tempdata['info']['time'] = getTimeStamp()
for i=0,#objects do
if objects[i] then
tempdata[i] = {}
tempdata[i]['model'] = getElementModel(objects[i])
tempdata[i]['col'] = getElementCollisionsEnabled(objects[i])
tempdata[i]['int'] = getElementInterior(objects[i])
tempdata[i]['dim'] = getElementDimension(objects[i])
local x, y, z = getElementPosition(objects[i])
local rx, ry, rz = getElementRotation(objects[i])
tempdata[i]['pos'] = {x, y, z, rx, ry, rz}
local elementtype = getElementType(objects[i])
if elementtype == 'vehicle' then
tempdata[i]['type'] = 'vehicle'
local colours = {getVehicleColor(objects[i], true)}
for k=1,12 do
if not colours[k] then colours[k] = 255 end
end
tempdata[i]['colour'] = colours
elseif elementtype == 'ped' then
tempdata[i]['type'] = 'ped'
elseif elementtype == 'water' then
tempdata[i]['vertices'] = {}
for j=1,4 do
local x, y, z = getWaterVertexPosition(objects[i], j)
table.insert(tempdata[i]['vertices'], j, {['x'] = x, ['y'] = y, ['z'] = z})
end
tempdata[i]['type'] = 'water'
else
local scalex, scaley, scalez = getObjectScale(objects[i])
tempdata[i]['scale'] = {scalex, scaley, scalez}
tempdata[i]['type'] = 'object'
end
end
end
local file = fileCreate('maps/'..mapname.. '.json')
fileWrite(file, toJSON(tempdata))
fileClose(file)
tempdata = {}
outputChatBox('Saved map as ' .. mapname, player)
else
outputChatBox('Invalid map name.', player)
end
else
outputChatBox('SYNTAX: /savemap mapname', player)
end
end
function loadMap(mapname, tbl, int, dim)
local file = fileOpen('maps/'..mapname..'.json')
local size = fileGetSize(file)
local buffer = fileRead(file, size)
local tempdata = fromJSON(buffer)
fileClose(file)
for k in pairs (tempdata) do
if k ~= 'info' then
local id = tonumber(k)
local ids = tostring(k)
local x, y, z, rx, ry, rz = unpack(tempdata[ids]['pos'])
if tempdata[ids]['type'] == 'vehicle' then
tbl[id] = createVehicle(tempdata[ids]['model'], x, y, z, rx, ry, rz)
setVehicleColor(tbl[id], unpack(tempdata[ids]['colour']))
elseif tempdata[ids]['type'] == 'ped' then
tbl[id] = createPed(tempdata[ids]['model'], x, y, z, rz, true)
elseif tempdata[ids]['type'] == 'water' then
vertices = tempdata[ids]['vertices']
tbl[id] = createWater(vertices[1].x, vertices[1].y, vertices[1].z, vertices[2].x, vertices[2].y, vertices[2].z, vertices[3].x, vertices[3].y, vertices[3].z, vertices[4].x, vertices[4].y, vertices[4].z)
else
tbl[id] = createObject(tempdata[ids]['model'], x, y, z, rx, ry, rz)
scalex, scaley, scalez = unpack(tempdata[ids]['scale'])
setObjectScale(tbl[id], scalex, scaley, scalez)
end
setElementCollisionsEnabled(tbl[id], tempdata[ids]['col'])
if tempdata[ids]['int'] and tempdata[ids]['dim'] and not (int and dim) then
setElementInterior(tbl[id], tempdata[ids]['int'])
setElementDimension(tbl[id], tempdata[ids]['dim'])
elseif int and dim then
setElementInterior(tbl[id], int)
setElementDimension(tbl[id], dim)
end
end
end
mapinfo = deepcopy(tempdata.info)
tempdata = {}
end
function loadMapLua(player, mapname)
if mapname then
if fileExists('maps/'..mapname..'.o23') then
clearPlayerObjects(player)
local file = fileOpen('maps/'..mapname..'.o23')
local size = fileGetSize(file)
local buffer = fileRead(file, size)
objectid = {}
assert(loadstring(buffer))()
objects = objectid