Repository navigation
Expand file tree
/
Copy pathcommands.lua
More file actions
956 lines (826 loc) · 36.5 KB
/
Copy pathcommands.lua
File metadata and controls
956 lines (826 loc) · 36.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
-- 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
function CMD_GetPlayer(param)
if param and param.player_index then
return game.players[param.player_index]
end
return nil
end
function CMD_GetActorName(player)
if player and player.valid then
return player.name
end
return "Console"
end
function CMD_RejectConsole(message)
UTIL_SmartPrint(nil, message or "This command can only be used in-game.")
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()
-- 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 ONELIFE_IsRevivable(victim) 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)
-- register command
CMD_AddCommand("register", "<code> (Requires a registration code from discord)", function(param)
local player = CMD_GetPlayer(param)
if CMD_NoSys(param) then
return
end
if not player then
CMD_RejectConsole("The console can't register this way.")
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
CW_EmitEvent("registration", { type = ptype, name = player.name, code = param.parameter })
UTIL_SmartPrint(player, "Sending registration code...")
return
end
UTIL_SmartPrint(player, "You need to provide a registration code!")
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)
-- 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 = {
left_top = { x = center.x - size / 2, y = center.y - size / 2 },
right_bottom = { 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 = CMD_GetPlayer(param)
if CMD_NoSys(param) or CMD_ModsOnly(param) then
return
end
if not player then
CMD_RejectConsole("The console can't use /goto. This command requires an in-game player.")
return
end
-- Argument required
if param.parameter then
local victim = game.players[param.parameter]
if victim == player then
UTIL_SmartPrint(player, "You can't goto yourself, are you having an identity crisis?")
return
end
if (victim) then
local newpos = victim.physical_surface.find_non_colliding_position("character",
victim.physical_position, 1024,
1, false)
if (newpos) then
UTIL_ExitRemoteView(player)
player.teleport(newpos, victim.physical_surface)
if player and victim then
UTIL_SmartPrint(player, "You goto " .. victim.name)
UTIL_SmartPrint(victim, player.name .. " suddenly appears.")
end
else
UTIL_SmartPrint(player, "Area appears to be full.")
UTIL_ConsolePrint("[ERROR] goto: unable to find non_colliding_position.")
end
return
else
UTIL_SmartPrint(player, "There isn't a player with that name.")
end
else
UTIL_SmartPrint(player, "Goto to who?")
end
end)
CMD_AddCommand("tp", "Moderators only: teleport to <x,y>, <surface>, or [gps=x,y] or [gps=x,y,surface]",
function(param)
local player = CMD_GetPlayer(param)
if CMD_NoSys(param) or CMD_ModsOnly(param) then
return
end
if not player then
CMD_RejectConsole("The console can't use /tp. This command requires an in-game player.")
return
end
if not param.parameter then
UTIL_SmartPrint(player, "Teleport to where?")
return
end
local str = param.parameter
local surface = player.surface -- default surface
local xpos, ypos
-- Try [gps=x,y] or [gps=x,y,surface]
local gx, gy, gsurf = str:match("%[gps=([-%d%.]+),([-%d%.]+),([%w_]+)%]")
if not gx then
gx, gy = str:match("%[gps=([-%d%.]+),([-%d%.]+)%]")
end
if gx and gy then
xpos = tonumber(gx)
ypos = tonumber(gy)
if gsurf and game.surfaces[gsurf] then
surface = game.surfaces[gsurf]
end
else
-- Try x,y format
local x, y = str:match("([-%d%.]+),([-%d%.]+)")
if x and y then
xpos = tonumber(x)
ypos = tonumber(y)
else
-- Try surface name
local named_surface = game.surfaces[str]
if named_surface then
surface = named_surface
xpos = 0
ypos = 0
end
end
end
if xpos and ypos then
local position = { x = xpos, y = ypos }
local newpos = surface.find_non_colliding_position("character", position, 1024, 1, false)
UTIL_ExitRemoteView(player)
if newpos then
player.teleport(newpos, surface)
UTIL_SmartPrint(player,
"You teleport to (" .. xpos .. "," .. ypos .. ") on surface '" .. surface.name .. "'.")
else
player.teleport(position, surface)
UTIL_SmartPrint(player, "Area appears to be full.")
UTIL_ConsolePrint("[ERROR] tp: unable to find non_colliding_position.")
end
elseif surface then
local position = { x = 0, y = 0 }
local newpos = surface.find_non_colliding_position("character", position, 1024, 1, false)
UTIL_ExitRemoteView(player)
player.teleport(newpos or position, surface)
UTIL_SmartPrint(player, "You teleport to spawn of surface '" .. surface.name .. "'.")
else
UTIL_SmartPrint(player, "Invalid location or surface.")
end
end)
-- Teleport player to me
CMD_AddCommand("summon", "Moderators only: summon <player> to me", function(param)
local player = CMD_GetPlayer(param)
if CMD_NoSys(param) or CMD_ModsOnly(param) then
return
end
if not player then
CMD_RejectConsole("The console can't use /summon. This command requires an in-game player.")
return
end
-- Argument required
if param.parameter then
local victim = game.players[param.parameter]
if UTIL_Is_Banished(victim) then
UTIL_SmartPrint(player, "They are in jail, use /unjail <name>")
return
end
if victim == player then
UTIL_SmartPrint(player, "You can't summon yourself, are you having an identity crisis?")
return
end
if (victim) then
local newpos = player.physical_surface.find_non_colliding_position("character",
player.physical_position, 1024,
1, false)
if (newpos) then
UTIL_ExitRemoteView(victim)
victim.teleport(newpos, player.physical_surface)
if player and victim then
UTIL_SmartPrint(player, victim.name .. " suddenly appears before you.")
UTIL_SmartPrint(victim, player.name .. " has summoned you.")
end
else
UTIL_SmartPrint(player, "Area appears to be full.")
UTIL_ConsolePrint("[ERROR] summon: unable to find non_colliding_position.")
end
else
UTIL_SmartPrint(player, "There isn't a player with that name.")
end
end
end)
-- Teleport victim to x,y
CMD_AddCommand("transport",
"Moderators only: transport <player> <x,y>, <surface>, or [gps=x,y] or [gps=x,y,surface]", function(param)
if CMD_ModsOnly(param) then
return
end
local player = CMD_GetPlayer(param)
local actor_name = CMD_GetActorName(player)
if not param.parameter then
UTIL_SmartPrint(player, "Transport who to where?")
return
end
local args = UTIL_SplitStr(param.parameter, " ")
local victim_name = args[1]
local target = args[2]
if not victim_name or not target then
UTIL_SmartPrint(player, "Usage: /transport <player> <x,y>, <surface>, or [gps=x,y,surface]")
return
end
local victim = game.players[victim_name]
if not victim then
UTIL_SmartPrint(player, "There isn't a player with that name.")
return
elseif UTIL_Is_Banished(victim) then
UTIL_SmartPrint(player, "They are in jail, use /unjail <name>")
return
end
local surface = victim.surface
local xpos, ypos
-- Try GPS tag [gps=x,y,surface]
local gx, gy, gsurf = target:match("%[gps=([-%d%.]+),([-%d%.]+),([%w_]+)%]")
if not gx then
gx, gy = target:match("%[gps=([-%d%.]+),([-%d%.]+)%]")
end
if gx and gy then
xpos = tonumber(gx)
ypos = tonumber(gy)
if gsurf and game.surfaces[gsurf] then
surface = game.surfaces[gsurf]
end
else
-- Try x,y format
local x, y = target:match("([-%d%.]+),([-%d%.]+)")
if x and y then
xpos = tonumber(x)
ypos = tonumber(y)
else
-- Try surface name
local named_surface = game.surfaces[target]
if named_surface and named_surface.valid then
surface = named_surface
xpos = 0
ypos = 0
end
end
end
if xpos and ypos then
local position = { x = xpos, y = ypos }
local newpos = surface.find_non_colliding_position("character", position, 1024, 1, false)
if not newpos then
newpos = position
UTIL_ConsolePrint("[ERROR] transport: unable to find non_colliding_position.")
end
UTIL_ExitRemoteView(victim)
victim.teleport(newpos, surface)
UTIL_SmartPrint(player,
"You transported " ..
victim.name .. " to (" .. xpos .. "," .. ypos .. ") on '" .. surface.name .. "'.")
UTIL_SmartPrint(victim, actor_name .. " has transported you.")
elseif surface then
local position = { x = 0, y = 0 }
local newpos = surface.find_non_colliding_position("character", position, 1024, 1, false)
UTIL_ExitRemoteView(victim)
victim.teleport(newpos or position, surface)
UTIL_SmartPrint(player,
"You transported " .. victim.name .. " to the spawn of '" .. surface.name .. "'.")
UTIL_SmartPrint(victim, actor_name .. " has transported you.")
else
UTIL_SmartPrint(player, "Transport target location invalid.")
end
end)
-- List surfaces
CMD_AddCommand("surfaces", "Moderators only, list game surfaces and players on them.",
function(param)
local player
if CMD_ModsOnly(param) then
return
end
if param and param.player_index then
player = game.players[param.player_index]
end
UTIL_SmartPrint(player, "Surfaces and players: ")
local buf = ""
for _, surface in pairs(game.surfaces) do
if buf ~= "" then
buf = buf .. "\n"
end
buf = buf .. surface.name .. ": "
local pbuf = ""
for _, victim in pairs(game.players) do
if victim.physical_surface == surface then
if pbuf ~= "" then
pbuf = pbuf .. ", "
else
pbuf = "Players: "
end
pbuf = pbuf .. victim.name
end
end
if pbuf == "" then
pbuf = "(None)"
end
buf = buf .. pbuf
end
UTIL_SmartPrint(player, buf)
end)
end
CMD_RegisterCommands()