-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcommands.lua
More file actions
1279 lines (1103 loc) · 48.2 KB
/
commands.lua
File metadata and controls
1279 lines (1103 loc) · 48.2 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
-- Carl Frank Otto III
-- carlotto81@gmail.com
-- GitHub: https://github.com/M45-Science/SoftMod
-- License: MPL 2.0
-- Load command groups
require "commands_banish"
require "commands_stash"
local SM_VERSION = require("version")
function CMD_AddCommand(name, help, handler)
commands.remove_command(name)
commands.add_command(name, help, handler)
end
local function cleanSurface(psurface, pforce, delayTick, victim)
-- Phase 1: Unchart all
pforce.clear_chart(psurface)
if not storage.SM_Store.purge_tasks then
storage.SM_Store.purge_tasks = {}
end
-- Add to task queue
table.insert(storage.SM_Store.purge_tasks, {
surface = psurface,
force = pforce,
delay = game.tick + delayTick,
victim = victim,
})
end
function CMD_NoBanished(player)
if player and UTIL_Is_Banished(player) then
UTIL_SmartPrint(player, "No. You are banished.")
return true
end
return false
end
function CMD_ModsOnly(param)
if param and param.player_index then
local player = game.players[param.player_index]
if CMD_NoBanished(player) then
return true
end
if player then
if not player.admin then
UTIL_SmartPrint(player, "That command is for moderators only.")
return true
else
local args = ""
if param.parameter then
args = param.parameter
end
local cmd_name = param.name or "unknown"
UTIL_ConsolePrint(string.format("[AUDIT] %s ran /%s %s", player.name, cmd_name, args))
end
end
end
return false
end
function CMD_SysOnly(param)
if param and param.player_index then
local player = game.players[param.player_index]
UTIL_SmartPrint(player, "That command is for system use only.")
return true
end
return false
end
function CMD_NoSys(param)
if param and param.player_index then
local player = game.players[param.player_index]
if CMD_NoBanished(player) then
return true
end
if not player.character then
UTIL_SmartPrint(player, "This command can only be used in-game (requires a character body).")
return true
end
end
return false
end
-- Custom commands
function CMD_RegisterCommands()
BANISH_AddBanishCommands()
STASH_AddStashCommands()
-- Reset interval message
CMD_AddCommand("resetdur", "System use only.", function(param)
if CMD_SysOnly(param) then
return
end
local input = ""
if param.parameter then
input = param.parameter
end
if storage.SM_Store.resetDuration ~= input then
storage.SM_Store.resetDuration = input
-- Refresh open info windows
for _, victim in pairs(game.connected_players) do
if victim and victim.gui and victim.gui.screen and
victim.gui.screen.m45_info_window then
INFO_InfoWin(victim)
end
end
--Update clock
for _, victim in pairs(game.connected_players) do
UTIL_DrawMapClock(victim)
end
end
end)
-- Reset interval message
CMD_AddCommand("resetint", "System use only.", function(param)
if CMD_SysOnly(param) then
return
end
local input = ""
if param.parameter then
input = param.parameter
end
storage.SM_Store.resetDate = input
end)
-- Enable / disable friendly fire
CMD_AddCommand("friendlyfire", "System use only.", function(param)
local player = (param and param.player_index) and game.players[param.player_index] or nil
if CMD_SysOnly(param) then
return
end
if param and param.parameter then
local pforce = game.forces["player"]
if pforce then
if string.lower(param.parameter) == "off" then
pforce.friendly_fire = false
UTIL_SmartPrint(player, "friendly fire disabled.")
elseif string.lower(param.parameter) == "on" then
pforce.friendly_fire = true
UTIL_SmartPrint(player, "friendly fire enabled.")
end
end
else
UTIL_SmartPrint(player, "on or off?")
end
end)
-- Enable / disable blueprints
CMD_AddCommand("blueprints", "System use only.", function(param)
local player = (param and param.player_index) and game.players[param.player_index] or nil
if CMD_SysOnly(param) then
return
end
PERMS_EnsureGroups()
if param and param.parameter then
local pforce = game.forces["player"]
if pforce then
if string.lower(param.parameter) == "off" then
storage.SM_Store.noBlueprints = false
PERMS_SetBlueprintsAllowed(storage.SM_Store.defGroup, false)
PERMS_SetBlueprintsAllowed(storage.SM_Store.memGroup, false)
PERMS_SetBlueprintsAllowed(storage.SM_Store.regGroup, false)
PERMS_SetBlueprintsAllowed(storage.SM_Store.vetGroup, false)
PERMS_SetBlueprintsAllowed(storage.SM_Store.modGroup, false)
UTIL_SmartPrint(player, "blueprints disabled...")
elseif string.lower(param.parameter) == "on" then
storage.SM_Store.noBlueprints = true
PERMS_SetBlueprintsAllowed(storage.SM_Store.defGroup, true)
PERMS_SetBlueprintsAllowed(storage.SM_Store.memGroup, true)
PERMS_SetBlueprintsAllowed(storage.SM_Store.regGroup, true)
PERMS_SetBlueprintsAllowed(storage.SM_Store.vetGroup, true)
PERMS_SetBlueprintsAllowed(storage.SM_Store.modGroup, true)
UTIL_SmartPrint(player, "blueprints enabled...")
end
end
else
UTIL_SmartPrint(player, "on or off?")
end
end)
-- Enable / disable cheat mode
CMD_AddCommand("enablecheats", "System use only.", function(param)
local player = (param and param.player_index) and game.players[param.player_index] or nil
if CMD_SysOnly(param) then
return
end
if param and param.parameter then
local pforce = game.forces["player"]
if pforce then
if string.lower(param.parameter) == "off" then
storage.SM_Store.cheats = false
for _, victim in ipairs(game.connected_players) do
victim.cheat_mode = false
end
UTIL_SmartPrint(player, "cheats disabled...")
elseif string.lower(param.parameter) == "on" then
storage.SM_Store.cheats = true
for _, victim in ipairs(game.connected_players) do
victim.cheat_mode = true
end
pforce.research_all_technologies()
UTIL_SmartPrint(player, "cheats enabled...")
end
end
else
UTIL_SmartPrint(player, "on or off?")
end
end)
-- Enable / disable cheat mode
CMD_AddCommand("onelife", "Moderators Only: One life mode on/off or <playerName> for revive.",
function(param)
local player
if param and param.player_index then
player = game.players[param.player_index]
end
if CMD_ModsOnly(param) then
return
end
if param and param.parameter then
if param.parameter == "on" and not storage.SM_Store.oneLifeMode then
storage.SM_Store.oneLifeMode = true
UTIL_SmartPrint(player, "One-life mode enabled.")
UTIL_MsgAll("One-life mode enabled.")
for _, victim in ipairs(game.connected_players) do
ONELIFE_MakeButton(victim)
end
elseif param.parameter == "off" and storage.SM_Store.oneLifeMode then
storage.SM_Store.oneLifeMode = false
UTIL_SmartPrint(player, "One-life mode disabled.")
UTIL_MsgAll("One-life mode disabled.")
for _, victim in ipairs(game.connected_players) do
ONELIFE_MakeButton(victim)
end
elseif storage.SM_Store.oneLifeMode then
local victim = game.players[param.parameter]
if victim then
if storage.PData[victim.index].permDeath then
storage.SM_Store.oneLifeMode = false
ONELIFE_MakeButton(victim)
storage.SM_Store.oneLifeMode = true
ONELIFE_MakeButton(victim)
UTIL_MsgAll(victim.name .. " was revived!")
UTIL_SmartPrint(player, victim.name .. " was revived!")
else
UTIL_SmartPrint(player, victim.name .. " is already alive!!!")
end
else
UTIL_SmartPrint(player, "I don't see a player by that name.")
end
end
end
end)
-- adjust run speed
CMD_AddCommand("run", "Moderators only: speed: -1 to 100, 0 = normal speed", function(param)
local player
if param and param.player_index then
player = game.players[param.player_index]
end
if CMD_ModsOnly(param) then
return
end
if player and player.valid then
if player.character and player.character.valid then
if tonumber(param.parameter) then
local speed = tonumber(param.parameter)
-- Factorio doesn't like speeds less than -1
if speed < -0.99 then
speed = -0.99
end
-- Cap to reasonable amount
if speed > 1000 then
speed = 1000
end
player.character.character_running_speed_modifier = speed
UTIL_SmartPrint(player, "Walk speed set to " .. speed)
else
UTIL_SmartPrint(player, "Numbers only.")
end
else
UTIL_SmartPrint(player, "Can't set walk speed, because you don't have a body.")
end
else
UTIL_SmartPrint(player, "The console can't walk...")
end
end)
-- turn invincible
CMD_AddCommand("immortal", "Moderators only: optional: <name> (toggle player immortality, default self)",
function(param)
local player
local victim
if param and param.player_index then
player = game.players[param.player_index]
end
if CMD_ModsOnly(param) then
return
end
local target = player
if param and param.parameter then
victim = game.players[param.parameter]
end
if victim then
target = victim
end
if target and target.valid then
if target.character and target.character.valid then
if target.character.destructible then
target.character.destructible = false
UTIL_SmartPrint(player, target.name .. " is now immortal.")
else
target.character.destructible = true
UTIL_SmartPrint(player, target.name .. " is now mortal.")
end
else
UTIL_SmartPrint(player, "They don't have a character body right now.")
end
else
UTIL_SmartPrint(player, "Couldn't find a player by that name.")
end
end)
-- change new player restrictions
CMD_AddCommand("restrict", "System Use Only.", function(param)
local player
if CMD_SysOnly(param) then
return
end
-- Process argument
if not param.parameter then
UTIL_SmartPrint(player, "options: on, off")
return
elseif string.lower(param.parameter) == "off" then
storage.SM_Store.restrictNew = false
PERMS_SetPermissions()
UTIL_SmartPrint(player, "New player restrictions disabled.")
return
elseif string.lower(param.parameter) == "on" then
storage.SM_Store.restrictNew = true
PERMS_SetPermissions()
UTIL_SmartPrint(player, "New player restrictions enabled.")
return
end
STORAGE_MakePlayerStorage()
end)
-- register command
CMD_AddCommand("register", "<code> (Requires a registration code from discord)", function(param)
local player
if param and param.player_index then
player = game.players[param.player_index]
end
if CMD_NoSys(param) then
return
end
-- Only if arguments
if param.parameter and player and player.valid then
-- Init player if needed, else add to
if storage.PData[player.index].regAttempts > 3 then
UTIL_SmartPrint(player, "You have exhausted your registration attempts.")
return
end
storage.PData[player.index].regAttempts = storage.PData[player.index].regAttempts + 1
local ptype = "Error"
if player.admin then
ptype = "moderator"
elseif UTIL_Is_Veteran(player) then
ptype = "veteran"
elseif UTIL_Is_Regular(player) then
ptype = "regular"
elseif UTIL_Is_Member(player) then
ptype = "member"
else
ptype = "normal"
end
-- Send to ChatWire
print("[ACCESS] " .. ptype .. " " .. player.name .. " " .. param.parameter)
UTIL_SmartPrint(player, "Sending registration code...")
return
end
UTIL_SmartPrint(player, "You need to provide a registration code!")
end)
-- softmod version
CMD_AddCommand("sversion", "System use only.", function(param)
local player
if CMD_SysOnly(param) then
return
end
-- ChatWire calls /sversion after boot; historically this also refreshed state for existing saves.
RunSetup()
if param and param.player_index then
player = game.players[param.player_index]
end
if player then
UTIL_SmartPrint(player, "[SVERSION] " .. (storage.SM_Version or SM_VERSION or "?"))
else
print("[SVERSION] " .. (storage.SM_Version or SM_VERSION or "?"))
end
end)
-- Server name
CMD_AddCommand("cname", "System use only.", function(param)
if CMD_SysOnly(param) then
return
end
STORAGE_EnsureGlobal()
if param.parameter then
storage.SM_Store.serverName = param.parameter
LOGO_DrawLogo(true)
end
end)
-- Server chat
CMD_AddCommand("cchat", "System use only.", function(param)
if CMD_SysOnly(param) then
return
end
if param.parameter then
UTIL_MsgPlayers(param.parameter)
end
end)
-- Server whisper
CMD_AddCommand("cwhisper", "System use only.", function(param)
if CMD_SysOnly(param) then
return
end
-- Must have arguments
if param.parameter then
local args = UTIL_SplitStr(param.parameter, " ")
-- Require two args
if args and args[1] ~= "" and args[2] then
-- Find player
for _, player in pairs(game.connected_players) do
if player.name == args[1] then
args[1] = ""
UTIL_SmartPrint(player, table.concat(args, " "))
return
end
end
end
end
end)
-- Reset players's time and status
CMD_AddCommand("reset", "Moderators only: <player> -- (Set player to NEW)", function(param)
local player
if param and param.player_index then
player = game.players[param.player_index]
end
if CMD_ModsOnly(param) then
return
end
-- Argument needed
if param.parameter then
local victim = game.players[param.parameter]
PERMS_MakeNew(player, victim)
return
end
UTIL_SmartPrint(player, "Player not found.")
end)
-- Trust player
CMD_AddCommand("member", "Moderators only: <player> -- (Makes the player a member)", function(param)
local player
if param and param.player_index then
player = game.players[param.player_index]
end
if CMD_ModsOnly(param) then
return
end
-- Argument required
if param.parameter then
local victim = game.players[param.parameter]
if not victim then
UTIL_SmartPrint(player, "Player not found.")
return
end
PERMS_MakeMember(player, victim)
end
end)
-- Set player to veteran
CMD_AddCommand("veteran", "System use only.", function(param)
local player
if CMD_SysOnly(param) then
return
end
-- Argument required
if param.parameter then
local victim = game.players[param.parameter]
if not victim then
UTIL_SmartPrint(player, "Player not found.")
return
end
PERMS_MakeVeteran(player, victim)
end
end)
-- Set player to regular
CMD_AddCommand("regular", "System use only.", function(param)
local player
if CMD_SysOnly(param) then
return
end
-- Argument required
if param.parameter then
local victim = game.players[param.parameter]
if not victim then
UTIL_SmartPrint(player, "Player not found.")
return
end
PERMS_MakeRegular(player, victim)
end
end)
-- Set player to patreon
CMD_AddCommand("patreon", "System use only.", function(param)
local player
if CMD_SysOnly(param) then
return
end
-- Argument required
if param.parameter then
local victim = game.players[param.parameter]
if (victim) then
if victim then
if not storage.PData[victim.index].patreon then
storage.PData[victim.index].patreon = true
UTIL_SmartPrint(victim,
"*** Welcome back, and thank you for being a supporter " .. victim.name .. "!!! ***")
UTIL_SmartPrint(victim, "NEWS: See the new /stash and /unstash commands!")
UTIL_SmartPrint(victim,
"/stash will take your currently equipped armor, weapons and ammo and 'stashes' them.")
UTIL_SmartPrint(victim, "When you need them again, such as on respawn /unstash them!")
UTIL_SmartPrint(victim,
"It is very similar to putting them in a box at spawn, but they are safe from being lost or taken.")
victim.tag = "(supporter)"
ONLINE_MarkDirty()
end
end
end
end
end)
-- Set player to nitro
CMD_AddCommand("nitro", "System use only.", function(param)
local player
if CMD_SysOnly(param) then
return
end
-- Argument required
if param.parameter then
local victim = game.players[param.parameter]
if (victim) then
if victim then
if not storage.PData[victim.index].nitro then
storage.PData[victim.index].nitro = true
UTIL_SmartPrint(player, "Player given nitro status.")
ONLINE_MarkDirty()
else
UTIL_SmartPrint(player, "Player already has nitro status.")
end
return
end
end
end
UTIL_SmartPrint(player, "Player not found.")
end)
-- Add player to patreon credits
CMD_AddCommand("patreonlist", "System use only.", function(param)
local player
if CMD_SysOnly(param) then
return
end
-- Argument required
if param.parameter then
storage.SM_Store.patreonCredits = UTIL_SplitStr(param.parameter, ",")
end
end)
-- Add player to nitro credits
CMD_AddCommand("nitrolist", "System use only.", function(param)
local player
if CMD_SysOnly(param) then
return
end
-- Argument required
if param.parameter then
storage.SM_Store.nitroCredits = UTIL_SplitStr(param.parameter, ",")
end
end)
-- Change default spawn point
CMD_AddCommand("cspawn",
"Moderators only: <x,y> -- (OPTIONAL) (Sets spawn point to <x,y>, or where you stand by default)",
function(param)
local victim
local new_pos_x
local new_pos_y
if param and param.player_index then
victim = game.players[param.player_index]
end
if CMD_ModsOnly(param) then
return
end
local psurface = game.surfaces[1]
local pforce = game.forces["player"]
-- use mods's force and position if available.
if victim then
pforce = victim.force
new_pos_x = victim.position.x
new_pos_y = victim.position.y
end
-- Location supplied
if param.parameter then
local xytable = UTIL_SplitStr(param.parameter, ",")
if tonumber(xytable[1]) and tonumber(xytable[2]) then
new_pos_x = tonumber(xytable[1])
new_pos_y = tonumber(xytable[2])
else
UTIL_SmartPrint(victim, "Invalid argument. /cspawn x,y. No argument uses your current location.")
return
end
end
-- Set new spawn spot
if pforce and psurface and new_pos_x and new_pos_y then
pforce.set_spawn_position({ new_pos_x, new_pos_y }, psurface)
local newPos = UTIL_GetDefaultSpawn()
UTIL_SmartPrint(victim, string.format("New spawn point set: %d,%d", math.floor(newPos.x),
math.floor(newPos.y)))
UTIL_SmartPrint(victim, string.format("Force: %s", pforce.name))
LOGO_DrawLogo(false)
else
UTIL_SmartPrint(victim, "Couldn't find force...")
end
end)
-- Reveal map
CMD_AddCommand("reveal",
"Moderators only: <size> [x,y]|[gps=x,y]|[gps=x,y,surface] -- Reveals map from a given position or the center of map. Size is in tiles. Default size 1024. Min 128, Max 8192.",
function(param)
if CMD_ModsOnly(param) then
return
end
local victim = param.player_index and game.players[param.player_index] or nil
local psurface = game.surfaces[1]
local pforce = game.forces["player"]
local center = { x = 0, y = 0 }
local size = 1024
if victim then
psurface = victim.surface
pforce = victim.force
center = victim.position
end
if param.parameter then
local str = param.parameter
-- Attempt to extract gps format
local gx, gy, gsurf = str:match("%[gps=([-%d%.]+),([-%d%.]+),([%w_]+)%]")
if not gx then gx, gy = str:match("%[gps=([-%d%.]+),([-%d%.]+)%]") end
local x, y = str:match("([-%d%.]+),([-%d%.]+)")
local surfname = str:match("^%s*([%w_]+)%s*$")
local tokens = {}
for token in str:gmatch("[^%s,]+") do
table.insert(tokens, token)
end
-- First numeric token = size
local s = tonumber(tokens[1])
if s then
size = math.max(128, math.min(8192, s))
table.remove(tokens, 1)
end
-- Handle GPS
if gx and gy then
center = { x = tonumber(gx), y = tonumber(gy) }
if gsurf and game.surfaces[gsurf] then
psurface = game.surfaces[gsurf]
end
-- Handle x,y
elseif x and y then
center = { x = tonumber(x), y = tonumber(y) }
-- Handle surface name if valid
elseif surfname and game.surfaces[surfname] then
psurface = game.surfaces[surfname]
center = { x = 0, y = 0 }
end
end
if psurface and pforce and center then
local area = {
lefttop = { x = center.x - size / 2, y = center.y - size / 2 },
rightbottom = { x = center.x + size / 2, y = center.y + size / 2 }
}
pforce.chart(psurface, area)
UTIL_SmartPrint(victim, "Revealing " .. size .. "x" .. size ..
" area centered at (" ..
math.floor(center.x) .. "," .. math.floor(center.y) .. ") on surface '" .. psurface.name .. "'.")
else
UTIL_SmartPrint(victim, "Invalid force, surface, or center position.")
end
end)
CMD_AddCommand("rechart",
"Moderators only: Recharts known chunks. Usage: /rechart [surface] [force]",
function(param)
if CMD_ModsOnly(param) then return end
local victim = param.player_index and game.players[param.player_index] or nil
local psurface = game.surfaces[1]
local pforce = game.forces["player"]
if victim then
psurface = victim.surface
pforce = victim.force
end
if param.parameter then
local tokens = {}
for token in param.parameter:gmatch("[^%s]+") do
table.insert(tokens, token)
end
if #tokens >= 1 then
local surfname = tokens[1]
if game.surfaces[surfname] then
psurface = game.surfaces[surfname]
else
UTIL_SmartPrint(victim, "Invalid surface: " .. surfname)
return
end
end
if #tokens >= 2 then
local forcename = tokens[2]
if game.forces[forcename] then
pforce = game.forces[forcename]
else
UTIL_SmartPrint(victim, "Invalid force: " .. forcename)
return
end
end
end
if psurface and pforce then
pforce.clear_chart(psurface)
UTIL_SmartPrint(victim,
"Recharting surface '" .. psurface.name .. "' for force '" .. pforce.name .. "'.")
else
UTIL_SmartPrint(victim, "Invalid surface or force.")
end
end)
CMD_AddCommand("clean-surface",
"Moderators only: Uncharts and later deletes unused chunks. Optional: <surface> or <all>",
function(param)
if CMD_ModsOnly(param) then return end
local victim = param.player_index and game.players[param.player_index] or nil
local psurface = game.surfaces[1]
local pforce = game.forces["player"]
local doAllSurf = false
if victim then
psurface = victim.surface
pforce = victim.force
end
if param.parameter then
local surfname = param.parameter:match("^%s*([%w_]+)%s*$")
if surfname and game.surfaces[surfname] then
psurface = game.surfaces[surfname]
else
if param.parameter == "all" then
doAllSurf = true
else
UTIL_SmartPrint(victim, "Invalid surface: " .. param.parameter)
return
end
end
end
game.server_save()
if doAllSurf then
local x = 0
for _, surface in pairs(game.surfaces) do
if string.sub(surface.name, 1, 8) == "platform" or surface.name == "jail" then
UTIL_ConsolePrint("Skipped cleaning surface: " .. surface.name)
else
x = x + 1
cleanSurface(surface, pforce, (60 * 10) + (x*30), victim)
end
end
UTIL_MsgAll("Cleaning all surfaces (" .. x .. "), chunk deletion scheduled.")
return
else
cleanSurface(psurface, pforce, (60 * 10), victim)
UTIL_MsgAll("Unused chunk deletion for " .. psurface.name .. " scheduled for 10s from now.")
end
end)
-- Online
CMD_AddCommand("online", "See who is online", function(param)
local victim
if param and param.player_index then
victim = game.players[param.player_index]
end
-- Sends updated list of players to server
ONLINE_UpdatePlayerList()
-- Already sent if console
if victim then
UTIL_SendPlayers(victim)
end
end)
-- Game speed, without walk speed mod
CMD_AddCommand("aspeed", "Moderators only: <x.x> -- Set game UPS, and do not adjust walk speed.",
function(param)
local player
if param and param.player_index then
player = game.players[param.player_index]
end
if CMD_ModsOnly(param) then
return
end
-- Need argument
if (not param.parameter) then
UTIL_SmartPrint(player, "But what speed? 1 to 6000")
return
end
-- Decode arg
if tonumber(param.parameter) then
local value = tonumber(param.parameter)
-- Limit speed range
if (value >= 1 and value <= 6000) then
game.speed = (value / 60.0)
else
UTIL_SmartPrint(player, "That doesn't seem like a good idea...")
end
else
UTIL_SmartPrint(player, "Numbers only.")
end
end)
-- Game speed
CMD_AddCommand("gspeed",
"Moderators only: <x.x> -- Changes game speed. Default speed: 1.0 (60 UPS), Min 0.01 (0.6 UPS), Max 10.0 (600 UPS)",
function(param)
local player
if param and param.player_index then
player = game.players[param.player_index]
end
if CMD_ModsOnly(param) then
return
end
-- Need argument
if (not param.parameter) then
UTIL_SmartPrint(player, "But what speed? 0.01 to 10")
return
end
-- Decode arg
if tonumber(param.parameter) then
local value = tonumber(param.parameter)
-- Limit speed range
if (value >= 0.1 and value <= 100.0) then
game.speed = value
-- Get default force
local pforce = game.forces["player"]
-- Use admin's force
if player and player.valid then
pforce = player.force
end
-- If force found
if pforce then
-- Calculate walk speed for UPS
pforce.character_running_speed_modifier = ((1.0 / value) - 1.0)
UTIL_SmartPrint(player, "Game speed: " .. value .. " Walk speed: " ..
pforce.character_running_speed_modifier)
-- Don't show message if run via console (ChatWire)
if (player) then
UTIL_MsgAll("Game speed set to " .. (game.speed * 100.00) .. "%")
end
else
UTIL_SmartPrint(player, "Couldn't find a valid force")
end
else
UTIL_SmartPrint(player, "That doesn't seem like a good idea...")
end
else
UTIL_SmartPrint(player, "Numbers only.")
end
end)
-- Teleport to
CMD_AddCommand("goto", "Moderators only: goto to <player>", function(param)
local player
if param and param.player_index then
player = game.players[param.player_index]
end