-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.lua
More file actions
executable file
·1041 lines (890 loc) · 22 KB
/
Copy pathmenu.lua
File metadata and controls
executable file
·1041 lines (890 loc) · 22 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
---@type Plugin
local mode = ...
local server = server
local ipairs = ipairs
local TYPE_WORLD = TYPE_WORLD
local playersGetNonBots = players.getNonBots
local vehiclesGetAll = vehicles.getAll
local itemsGetAll = items.getAll
local humansGetAll = humans.getAll
local osRealClock = os.realClock
local tools = mode:require('tools')
local util = mode:require('util')
local TOP_FLAG = 0x01000000
local VEHICLE_COLORS = {
[0] = 'Black',
[1] = 'Red',
[2] = 'Blue',
[3] = 'Grey',
[4] = 'White',
[5] = 'Gold'
}
local OBJECT_BUTTONS = {
{
vehicle = assert(vehicleTypes.getByName('Town Car'))
},
{
vehicle = assert(vehicleTypes.getByName('Turbo'))
},
{
vehicle = assert(vehicleTypes.getByName('Turbo S'))
},
{
vehicle = assert(vehicleTypes.getByName('Beamer'))
},
{
vehicle = assert(vehicleTypes.getByName('Van'))
},
{
vehicle = assert(vehicleTypes.getByName('Minivan'))
},
-- {
-- vehicle = assert(vehicleTypes.getByName('Helicopter'))
-- },
{
vehicle = assert(vehicleTypes.getByName('Hatchback'))
},
{
item = assert(itemTypes.getByName('Box'))
},
{
name = 'Plank',
item = assert(itemTypes.getByName('Big Box'))
},
{
item = assert(itemTypes.getByName('Bottle'))
},
{
item = assert(itemTypes.getByName('Watermelon'))
},
{
item = assert(itemTypes.getByName('AK-47'))
},
{
item = assert(itemTypes.getByName('AK-47 Magazine'))
},
{
item = assert(itemTypes.getByName('M-16'))
},
{
item = assert(itemTypes.getByName('M-16 Magazine'))
},
{
item = assert(itemTypes.getByName('MP5'))
},
{
item = assert(itemTypes.getByName('MP5 Magazine'))
},
{
item = assert(itemTypes.getByName('Uzi'))
},
{
item = assert(itemTypes.getByName('Uzi Magazine'))
},
{
item = assert(itemTypes.getByName('9mm'))
},
{
item = assert(itemTypes.getByName('9mm Magazine'))
},
{
item = assert(itemTypes.getByName('Bandage'))
}
}
local BOT_TYPES = {
{
name = 'Goldmen',
suitColor = 6,
tieColor = 2,
model = 1,
team = 0
},
{
name = 'Monsota',
suitColor = 10,
tieColor = 9,
model = 1,
team = 1
},
{
name = 'OXS',
suitColor = 11,
tieColor = 8,
model = 1,
team = 2
},
{
name = 'Nexaco',
suitColor = 2,
tieColor = 3,
model = 1,
team = 3
},
{
name = 'Pentacom',
suitColor = 1,
tieColor = 7,
model = 1,
team = 4
},
{
name = 'Prodocon',
suitColor = 2,
tieColor = 1,
model = 1,
team = 5
},
{
name = 'Megacorp',
suitColor = 1,
tieColor = 0,
model = 1,
team = 6
},
{
name = 'Civilian',
suitColor = 0,
tieColor = 0,
model = 0,
team = 17
}
}
local SHIRT_COLORS = {
{
name = 'White',
color = 0
},
{
name = 'Pink',
color = 1
},
{
name = 'Light Yellow',
color = 2
},
{
name = 'Light Green',
color = 3
},
{
name = 'Light Blue',
color = 4
},
{
name = 'Red',
color = 5
},
{
name = 'Black',
color = 9
},
{
name = 'Dark Blue',
color = 10
},
{
name = 'Dark Green',
color = 11
}
}
local UTILITY_BUTTONS = {
'Clear All',
'Clear Vehicles',
'Clear Items',
'Clear Bots'
}
local TELEPORT_DESTINATIONS = {
{ Vector(1037, 25.5, 1038), 'Goldmen' },
{ Vector(1806, 25.5, 1010), 'RIO Inc.' },
{ Vector(1930, 25.5, 1083), 'Water Treatment' },
{ Vector(1068, 33.5, 1181), 'WNQY' },
{ Vector(1366, 25.5, 1146), 'Hotdogs' },
{ Vector(1614, 25.5, 1175), 'Gas' },
{ Vector(1501, 33, 1218), 'Crab Legs' },
{ Vector(1542, 33.5, 1286), 'Red Cube Park' },
{ Vector(1819, 25.5, 1258), 'Hondo Park' },
{ Vector(1342, 49.5, 1341), 'The Mall' },
{ Vector(1785, 49.5, 1419), 'Lumber' },
{ Vector(1476, 49.5, 1490), 'Isle of Burgers' },
{ Vector(1692, 45.5, 1486), 'Museum' },
{ Vector(1267, 49.25, 1521), 'Kamel Bldg.' },
{ Vector(1848, 41.25, 1534), 'Cul-de-sac' },
{ Vector(1506, 49.5, 1653), 'Library' },
{ Vector(1086, 25.5, 1716), 'Monsota' },
{ Vector(1929, 25.5, 1689), 'OXS' }
}
local nSpawn
mode:addHook(
'PostResetGame',
function ()
nSpawn = 0
end
)
mode:addEnableHandler(function ()
nSpawn = 0
end)
mode:addDisableHandler(function ()
nSpawn = nil
end)
---@param ply Player
local function drawMenu (ply)
local data = ply.data
local menuTab = data.sandboxMenuTab or 0
local numButtons = 0
for i, text in ipairs({ 'Objects', 'Bots', 'Teleport', 'Tool', 'Friends', 'Utilities' }) do
local btn = ply:getMenuButton(numButtons)
numButtons = numButtons + 1
if i == 4 then
local name
local toolID = data.sandboxTool
if toolID and toolID ~= 0 then
name = tools[toolID].name
else
name = 'None'
end
text = text .. ' (' .. name .. ')'
end
btn.id = TOP_FLAG + i - 1
btn.text = text
if i - 1 == menuTab then
btn.id = -1
end
end
if menuTab == 0 then
do
local btn = ply:getMenuButton(numButtons)
numButtons = numButtons + 1
local color = data.sandboxColor or 0
btn.id = 0
btn.text = 'Paint Colour: ' .. VEHICLE_COLORS[color]
end
for i, object in ipairs(OBJECT_BUTTONS) do
local btn = ply:getMenuButton(numButtons)
numButtons = numButtons + 1
local name = object.name
if not name then
if object.vehicle then
name = object.vehicle.name
else
name = object.item.name
end
end
btn.id = i
btn.text = 'Spawn ' .. name
end
elseif menuTab == 1 then
do
local btn = ply:getMenuButton(numButtons)
numButtons = numButtons + 1
local type = data.sandboxBotMode or 0
btn.id = 0
btn.text = 'Mode: ' .. (type == 0 and 'AI' or 'Ragdoll')
end
for i, type in ipairs(BOT_TYPES) do
local btn = ply:getMenuButton(numButtons)
numButtons = numButtons + 1
btn.id = i
btn.text = 'Spawn ' .. type.name
end
elseif menuTab == 2 then
for i, dest in ipairs(TELEPORT_DESTINATIONS) do
local btn = ply:getMenuButton(numButtons)
numButtons = numButtons + 1
btn.id = i
btn.text = dest[2]
end
elseif menuTab == 3 then
do
local btn = ply:getMenuButton(numButtons)
numButtons = numButtons + 1
btn.id = 0
btn.text = 'None'
end
for i, tool in ipairs(tools) do
local btn = ply:getMenuButton(numButtons)
numButtons = numButtons + 1
btn.id = i
btn.text = tool.name
end
elseif menuTab == 4 then
local pages = data.sandboxFriendsPages
local pageNum = data.sandboxFriendsPage
if pageNum > 1 then
local btn = ply:getMenuButton(numButtons)
numButtons = numButtons + 1
btn.id = 0
btn.text = 'Prev Page'
end
if pageNum < #pages then
local btn = ply:getMenuButton(numButtons)
numButtons = numButtons + 1
btn.id = 1
btn.text = 'Next Page'
end
for i, button in ipairs(pages[pageNum]) do
if numButtons >= 32 then break end
local btn = ply:getMenuButton(numButtons)
numButtons = numButtons + 1
btn.id = i + 1
btn.text = button.text
end
elseif menuTab == 5 then
local queue = data.sandboxUndoQueue
if queue and #queue > 0 then
local btn = ply:getMenuButton(numButtons)
numButtons = numButtons + 1
local action = queue[#queue]
local secondsAgo = math.floor(osRealClock() - action.time)
btn.id = 0
btn.text = 'Undo ' .. action.name .. ' (' .. secondsAgo .. 's ago)'
end
do
local btn = ply:getMenuButton(numButtons)
numButtons = numButtons + 1
local profile = util.getProfile(ply)
local shirt = SHIRT_COLORS[profile.shirt or 1]
btn.id = 1
btn.text = 'Shirt Colour: ' .. shirt.name
end
for id, text in ipairs(UTILITY_BUTTONS) do
local btn = ply:getMenuButton(numButtons)
numButtons = numButtons + 1
btn.id = id + 1
btn.text = text
end
end
ply.numMenuButtons = numButtons
end
mode:addHook(
'ServerSend',
function ()
server.type = TYPE_WORLD
for _, ply in ipairs(playersGetNonBots()) do
if ply.human then
ply.menuTab = 14
drawMenu(ply)
else
ply.menuTab = 1
end
end
end
)
mode:addHook(
'PostServerSend',
function ()
server.type = 20
for _, ply in ipairs(playersGetNonBots()) do
ply.menuTab = 0
end
end
)
local function buildFriendsButtons (ply, data)
local profile = util.getProfile(ply)
local friends = profile.friends
local nonBots = playersGetNonBots()
table.sort(nonBots, function (a, b)
return a.name:lower() < b.name:lower()
end)
local pages = {{}}
local page = pages[1]
for _, otherPly in ipairs(nonBots) do
if otherPly ~= ply and (not isHiddenModerator or not isHiddenModerator(otherPly)) then
if page and #page >= 22 then
page = {}
table.insert(pages, page)
end
local button = {}
button.phoneNumber = otherPly.phoneNumber
local key = tostring(otherPly.phoneNumber)
if friends and friends[key] then
button.text = 'Remove ' .. otherPly.name
else
button.text = 'Add ' .. otherPly.name
end
table.insert(page, button)
end
end
data.sandboxFriendsPages = pages
if not data.sandboxFriendsPage or data.sandboxFriendsPage > #pages or data.sandboxFriendsPage < 1 then
data.sandboxFriendsPage = 1
end
end
local function clickedMenuTab (ply, id, data)
if id >= 0 and id <= 5 then
if id == 4 then
buildFriendsButtons(ply, data)
end
data.sandboxMenuTab = id
local man = ply.human
if man then
events.createSound(21, man.pos, 0.1, 2)
end
end
end
local function getPlayersNumVehicles (ply)
local phone = ply.phoneNumber
local num = 0
for _, vcl in ipairs(vehiclesGetAll()) do
if vcl.data.sandboxCreatorPhone == phone then
num = num + 1
end
end
return num
end
local function getPlayersNumItems (ply)
local phone = ply.phoneNumber
local num = 0
for _, item in ipairs(itemsGetAll()) do
if item.data.sandboxCreatorPhone == phone then
num = num + 1
end
end
return num
end
local function getPlayersNumBots (ply)
local phone = ply.phoneNumber
local num = 0
for _, man in ipairs(humansGetAll()) do
if man.data.sandboxCreatorPhone == phone then
if not man.player or man.player.isBot then
num = num + 1
end
end
end
return num
end
local function clickedVehicle (ply, vehicleType)
local man = ply.human
if not man then return end
do
local limit = 250
local numPlayers = #playersGetNonBots()
if vehicles.getCount() >= limit then
ply:sendMessage('[ X ] Global vehicle limit reached (' .. limit .. ')')
util.sound('error', man.pos)
return
end
local personalLimit = math.floor(limit / numPlayers)
if getPlayersNumVehicles(ply) >= personalLimit then
ply:sendMessage('[ X ] Personal vehicle limit reached (' .. personalLimit .. ')')
util.sound('error', man.pos)
return
end
end
local ray = util.lineIntersectAll(man, getEyeLine(man, 2048))
if not ray.hit then
util.sound('error', man.pos)
return
end
local pos = ray.pos:clone()
local normal = ray.normal:clone()
pos:add(normal)
local color = ply.data.sandboxColor or 0
local vcl = vehicles.create(vehicleType, pos, yawToRotMatrix(man.viewYaw - math.pi/2), color)
if vcl then
vcl.data.sandboxCreatorPhone = ply.phoneNumber
vcl.rigidBody.data.sandboxCreatorPhone = ply.phoneNumber
util.addUndoAction(ply, {
obj = vcl,
name = 'Spawn Vehicle'
})
end
util.sound('general', man.pos)
end
local function clickedItem (ply, itemType)
local man = ply.human
if not man then return end
do
local limit = 500
local numPlayers = #playersGetNonBots()
if items.getCount() >= limit then
ply:sendMessage('[ X ] Global item limit reached (' .. limit .. ')')
util.sound('error', man.pos)
return
end
local personalLimit = math.floor(limit / numPlayers)
if getPlayersNumItems(ply) >= personalLimit then
ply:sendMessage('[ X ] Personal item limit reached (' .. personalLimit .. ')')
util.sound('error', man.pos)
return
end
end
local ray = util.lineIntersectAll(man, getEyeLine(man, 2048))
if not ray.hit then
util.sound('error', man.pos)
return
end
local pos = ray.pos:clone()
local normal = ray.normal:clone()
pos:add(normal)
local item = items.create(itemType, pos, yawToRotMatrix(man.viewYaw - math.pi/2))
if item then
item.despawnTime = 65536
item.data.sandboxCreatorPhone = ply.phoneNumber
item.rigidBody.data.sandboxCreatorPhone = ply.phoneNumber
util.addUndoAction(ply, {
obj = item,
name = 'Spawn Item'
})
end
util.sound('general', man.pos)
end
local function clickedObject (ply, id)
if id == 0 then
local color = ply.data.sandboxColor or 0
color = (color + 1) % (#VEHICLE_COLORS + 1)
ply.data.sandboxColor = color
return
end
local button = OBJECT_BUTTONS[id]
if not button then return end
if button.vehicle then
clickedVehicle(ply, button.vehicle)
else
clickedItem(ply, button.item)
end
end
local function clickedBot (ply, id)
local data = ply.data
local botMode = data.sandboxBotMode or 0
if id == 0 then
data.sandboxBotMode = botMode == 0 and 1 or 0
return
end
local type = BOT_TYPES[id]
if not type then return end
local man = ply.human
if not man then return end
do
local limit = 150
local numPlayers = #playersGetNonBots()
if humans.getCount() >= limit then
ply:sendMessage('[ X ] Global bot limit reached (' .. limit .. ')')
util.sound('error', man.pos)
return
end
local personalLimit = math.floor(limit / numPlayers)
if getPlayersNumBots(ply) >= personalLimit then
ply:sendMessage('[ X ] Personal bot limit reached (' .. personalLimit .. ')')
util.sound('error', man.pos)
return
end
end
local ray = util.lineIntersectAll(man, getEyeLine(man, 2048))
if not ray.hit then
util.sound('error', man.pos)
return
end
local pos = ray.pos:clone()
local normal = ray.normal:clone()
pos:add(normal)
local bot = players.createBot()
if bot then
bot.name = 'Bot'
bot.team = type.team or 0
bot.gender = math.random(0, 1)
bot.skinColor = math.random(0, 5)
bot.hairColor = math.random(0, 12)
bot.hair = math.random(0, 8)
bot.eyeColor = math.random(0, 7)
bot.head = math.random(0, 4)
bot.suitColor = type.suitColor or 0
bot.tieColor = type.tieColor or 0
bot.model = type.model or 0
local botMan = humans.create(pos, yawToRotMatrix(man.viewYaw + math.pi), bot)
if botMan then
botMan.data.sandboxCreatorPhone = ply.phoneNumber
for i = 0, 15 do
local body = botMan:getRigidBody(i)
body.data.sandboxCreatorPhone = ply.phoneNumber
end
util.addUndoAction(ply, {
obj = botMan,
name = 'Spawn Bot'
})
bot:update()
util.sound('general', man.pos)
if botMode == 1 then
botMan.isAlive = false
botMan.data.sandboxRagdoll = true
end
else
bot:remove()
end
end
end
local function clickedTeleport (ply, id)
local dest = TELEPORT_DESTINATIONS[id]
if not dest then return end
local man = ply.human
if not man then return end
man:teleport(dest[1])
man:setVelocity(Vector())
end
local function clickedTool (ply, id)
local tool = tools[id]
if id == 0 or tool then
if ply.data.sandboxTool ~= id then
local man = ply.human
if man then
ply.data.sandboxTool = id
if tool and tool.usage then
messagePlayerWrap(ply, '[' .. tool.name .. '] ' .. tool.usage)
util.invokeTool(tools, 'onEquip', false, ply, man)
end
end
end
end
end
local function clickedFriend (ply, id)
local data = ply.data
if id == 0 then
data.sandboxFriendsPage = data.sandboxFriendsPage - 1
buildFriendsButtons(ply, data)
return
elseif id == 1 then
data.sandboxFriendsPage = data.sandboxFriendsPage + 1
buildFriendsButtons(ply, data)
return
end
local button = data.sandboxFriendsPages[data.sandboxFriendsPage][id - 1]
if not button then return end
local otherPly = players.getByPhone(button.phoneNumber)
if not otherPly or otherPly.isBot or otherPly == ply then
buildFriendsButtons(ply, data)
return
end
local profile = util.getProfile(ply)
local key = tostring(otherPly.phoneNumber)
if profile.friends and profile.friends[key] then
profile.friends[key] = nil
ply:sendMessage(string.format('Removed %s (%s) as a friend', otherPly.name, dashPhoneNumber(otherPly.phoneNumber)))
else
if not profile.friends then
profile.friends = {}
end
profile.friends[key] = true
ply:sendMessage(string.format('Added %s (%s) as a friend', otherPly.name, dashPhoneNumber(otherPly.phoneNumber)))
end
util.setProfilesDirty()
buildFriendsButtons(ply, data)
end
local function clickedUndo (ply)
local queue = ply.data.sandboxUndoQueue
if not queue or #queue < 1 then return false end
local action = table.remove(queue, #queue)
if action.bond then
if not action.bond.isActive then
return false
end
action.bond.isActive = false
elseif action.obj then
if not action.obj.isActive then
return false
end
util.eraseObjectBodyUndos(action.obj)
action.obj:remove()
util.clearOrphanedBonds()
if action.obj.class == 'Human' then
util.clearOrphanedBotPlayers()
end
elseif action.body then
if not action.body.isActive then
return false
end
if action.mass then
action.body.mass = action.mass
elseif action.noCollideAll ~= nil then
action.body.data.sandboxNoCollideAll = action.noCollideAll and true or nil
else
return false
end
end
return true, action
end
local function clickedUtility (ply, id)
local man = ply.human
if not man then return end
local phone = ply.phoneNumber
if id == 0 then
local worked = clickedUndo(ply)
util.sound(worked and 'general' or 'error', man.pos)
elseif id == 1 then
local profile = util.getProfile(ply)
profile.shirt = ((profile.shirt or 1) % #SHIRT_COLORS) + 1
util.setProfilesDirty()
elseif id == 2 then
local num = util.clearObjects(phone, vehiclesGetAll()) + util.clearObjects(phone, itemsGetAll()) + util.clearBots(phone)
util.sound(num > 0 and 'general' or 'error', man.pos)
elseif id == 3 then
local num = util.clearObjects(phone, vehiclesGetAll())
util.sound(num > 0 and 'general' or 'error', man.pos)
elseif id == 4 then
local num = util.clearObjects(phone, itemsGetAll())
util.sound(num > 0 and 'general' or 'error', man.pos)
elseif id == 5 then
local num = util.clearBots(phone)
util.sound(num > 0 and 'general' or 'error', man.pos)
end
end
local function isClickRateLimited (ply)
local now = osRealClock()
local data = ply.data
local lastClickTime = data.sandboxLastClickTime or 0
if now - lastClickTime < 0.2 then
return true
end
data.sandboxLastClickTime = now
return false
end
local function clickedMenuButton (ply, id)
local data = ply.data
if id >= TOP_FLAG then
id = id - TOP_FLAG
clickedMenuTab(ply, id, data)
return
end
if isClickRateLimited(ply) then return end
local menuTab = data.sandboxMenuTab or 0
if menuTab == 0 then
clickedObject(ply, id)
elseif menuTab == 1 then
clickedBot(ply, id)
elseif menuTab == 2 then
clickedTeleport(ply, id)
elseif menuTab == 3 then
clickedTool(ply, id)
elseif menuTab == 4 then
clickedFriend(ply, id)
elseif menuTab == 5 then
clickedUtility(ply, id)
end
local man = ply.human
if man then
events.createSound(22, man.pos, 0.1, 2)
end
end
---@param ply Player
local function clickedEnterCity (ply)
if not ply.human then
ply.model = 0
local profile = util.getProfile(ply)
local shirt = SHIRT_COLORS[profile.shirt or 1]
ply.suitColor = shirt.color
ply.tieColor = 0
ply.team = 17
local pos = Vector(1387 + nSpawn, 49.1, 1462)
local man = humans.create(pos, orientations.n, ply)
if man then
if not hook.run('EventUpdatePlayer', ply) then
ply:update()
hook.run('PostEventUpdatePlayer', ply)
end
man.data.sandboxCreatorPhone = ply.phoneNumber
for i = 0, 15 do
local body = man:getRigidBody(i)
body.data.sandboxCreatorPhone = ply.phoneNumber
end
nSpawn = (nSpawn + 1) % 64
end
end
end
mode:addHook(
'PlayerActions',
---@param ply Player
function (ply)
if ply.numActions ~= ply.lastNumActions then
local action = ply:getAction(ply.lastNumActions)
if action.type == 0 then
if action.a == 14 then
ply.lastNumActions = ply.numActions
clickedMenuButton(ply, action.b)
elseif action.a == 1 then
clickedEnterCity(ply)
end
end
end
end
)
---@param ply Player
---@param man Human
local function handleControls (ply, man)
if man.isAlive then
man.stamina = 127
man.maxStamina = 127
local data = man.data
local flags = man.inputFlags
local lastFlags = data.sandboxLastInputFlags or 0
data.sandboxLastInputFlags = man.inputFlags
if not man:getInventorySlot(0).primaryItem and not man:getInventorySlot(1).primaryItem and not man.vehicle then
local andLeft = bit32.band(flags, 1)
local andRight = bit32.band(flags, 2)
local andE = bit32.band(flags, 2048)
if andLeft ~= bit32.band(lastFlags, 1) then
if andLeft ~= 0 then
if not isClickRateLimited(ply) then
data.sandboxLeftDown = true
util.invokeTool(tools, 'onLeftDown', true, ply, man)
end
elseif data.sandboxLeftDown then
data.sandboxLeftDown = false
util.invokeTool(tools, 'onLeftUp', true, ply, man)
end
elseif andLeft ~= 0 and data.sandboxLeftDown then
util.invokeTool(tools, 'onLeftHeld', false, ply, man)
end
if andRight ~= bit32.band(lastFlags, 2) then
if andRight ~= 0 then
if not isClickRateLimited(ply) then
data.sandboxRightDown = true
util.invokeTool(tools, 'onRightDown', true, ply, man)
end
elseif data.sandboxRightDown then
data.sandboxRightDown = false
util.invokeTool(tools, 'onRightUp', true, ply, man)
end
elseif andRight ~= 0 and data.sandboxRightDown then
util.invokeTool(tools, 'onRightHeld', false, ply, man)
end
if andE ~= bit32.band(lastFlags, 2048) then
if andE ~= 0 then
data.sandboxEDown = true
util.invokeTool(tools, 'onEDown', false, ply, man)