-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathconsolecommands.lua
2076 lines (1774 loc) · 60.4 KB
/
consolecommands.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
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
-- not local - debugkeys use it too
function ConsoleCommandPlayer()
return (c_sel() ~= nil and c_sel():HasTag("player") and c_sel()) or ThePlayer or AllPlayers[1]
end
function ConsoleWorldPosition()
return TheInput.overridepos or TheInput:GetWorldPosition()
end
function ConsoleWorldEntityUnderMouse()
if TheInput.overridepos == nil then
return TheInput:GetWorldEntityUnderMouse()
else
local x, y, z = TheInput.overridepos:Get()
local ents = TheSim:FindEntities(x, y, z, 1)
for i, v in ipairs(ents) do
if v.entity:IsVisible() then
return v
end
end
end
end
local function ListingOrConsolePlayer(input)
if type(input) == "string" or type(input) == "number" then
return UserToPlayer(input)
end
return input or ConsoleCommandPlayer()
end
local function Spawn(prefab)
--TheSim:LoadPrefabs({prefab})
return SpawnPrefab(prefab)
end
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
-- Console Functions -- These are simple helpers made to be typed at the console.
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
-- Show server announcements:
-- To send a one time announcement: c_announce(msg)
-- To repeat a periodic announcement: c_announce(msg, interval)
-- To cancel a periodic announcement: c_announce()
function c_announce(msg, interval, category)
msg = type(msg) == "string" and msg or tostring(msg)
interval = type(interval) == "number" and interval or nil
category = type(category) == "string" and category or nil
if msg == nil then
if TheWorld.__announcementtask ~= nil then
TheWorld.__announcementtask:Cancel()
TheWorld.__announcementtask = nil
end
elseif interval == nil or interval <= 0 then
if category == "system" then
TheNet:SystemMessage(msg)
else
TheNet:Announce(msg, nil, nil, category)
end
else
if TheWorld.__announcementtask ~= nil then
TheWorld.__announcementtask:Cancel()
end
TheWorld.__announcementtask =
TheWorld:DoPeriodicTask(
interval,
category == "system" and
function() TheNet:SystemMessage(msg) end or
function() TheNet:Announce(msg, nil, nil, category) end,
0
)
end
end
local function doreset()
StartNextInstance({
reset_action = RESET_ACTION.LOAD_SLOT,
save_slot = ShardGameIndex:GetSlot()
})
end
function c_mermking()
c_spawn("mermthrone")
c_spawn("mermking")
end
function c_mermthrone()
c_spawn("mermthrone_construction")
c_give("kelp", 20)
c_give("beefalowool", 15)
c_give("pigskin", 10)
c_give("carrot", 4)
c_spawn("merm")
end
function c_allbooks()
local books =
{
"book_birds", "book_horticulture", "book_silviculture", "book_sleep",
"book_brimstone", "book_tentacles", "book_fish", "book_fire", "book_web",
"book_temperature", "book_light", "book_rain", "book_moon", "book_bees",
"book_research_station", "book_horticulture_upgraded",
"book_light_upgraded"
}
for _,v in ipairs(books) do
c_give(v)
end
end
-- * Roll back *count* number of saves (default 1)
-- * c_rollback() or c_rollback(1) will roll back to the
-- last save file, if it's been longer than 30 seconds
-- * c_rollback(0) is the same as c_reset()
function c_rollback(count)
if TheWorld ~= nil and TheWorld.ismastersim then
TheNet:SendWorldRollbackRequestToServer(count)
end
end
-- Restart the server to the last save file (same as c_rollback(0))
function c_reset()
if TheWorld ~= nil and not TheWorld.ismastersim then
c_remote("c_reset()")
return
end
if not InGamePlay() then
StartNextInstance()
elseif TheWorld ~= nil and TheWorld.ismastersim then
TheNet:SendWorldRollbackRequestToServer(0)
end
end
-- Permanently delete the game world, regenerates a new world afterwards
-- NOTE: It is not recommended to use this instead of c_regenerateworld,
-- unless you need to regenerate only one shard in a cluster
function c_regenerateshard(wipesettings)
if TheWorld ~= nil and not TheWorld.ismastersim then
c_remote("c_regenerateshard()")
return
end
local shouldpreserve = not wipesettings
if TheWorld ~= nil and TheWorld.ismastersim then
ShardGameIndex:Delete(
doreset,
shouldpreserve
)
end
end
-- Permanently delete all game worlds in a server cluster, regenerates new worlds afterwards
-- NOTE: This will not work properly for any shard that is offline or in a loading state
function c_regenerateworld()
if TheWorld ~= nil and not TheWorld.ismastersim then
c_remote("c_regenerateworld()")
return
end
if TheWorld ~= nil and TheWorld.ismastersim then
TheNet:SendWorldResetRequestToServer()
end
end
function c_save()
if TheWorld ~= nil and not TheWorld.ismastersim then
c_remote("c_save()")
return
end
if TheWorld ~= nil and TheWorld.ismastersim then
TheWorld:PushEvent("ms_save")
end
end
-- Shutdown the application, optionally close with out saving (saves by default)
function c_shutdown(save)
if TheWorld ~= nil and not TheWorld.ismastersim then
c_remote("c_shutdown()")
return
end
print("c_shutdown", save)
if save == false or TheWorld == nil then
Shutdown()
elseif TheWorld.ismastersim then
for i, v in ipairs(AllPlayers) do
v:OnDespawn()
end
TheSystemService:EnableStorage(true)
ShardGameIndex:SaveCurrent(Shutdown, true)
else
SerializeUserSession(ThePlayer)
Shutdown()
end
end
-- Remotely execute a lua string
function c_remote( fnstr )
local x, y, z = TheSim:ProjectScreenPos(TheSim:GetPosition())
TheNet:SendRemoteExecute(fnstr, x, z)
end
-- Spawn At Cursor and select the new ent
-- Has a gimpy short name so it's easier to type from the console
function c_spawn(prefab, count, dontselect)
count = count or 1
local inst = nil
prefab = string.lower(prefab)
for i = 1, count do
inst = DebugSpawn(prefab)
if inst and inst.components.skinner ~= nil and IsRestrictedCharacter(prefab) then
inst.components.skinner:SetSkinMode("normal_skin")
end
end
if not dontselect then
SetDebugEntity(inst)
end
SuUsed("c_spawn_"..prefab, true)
return inst
end
-- c_despawn helper
local function dodespawn(player)
if TheWorld ~= nil and TheWorld.ismastersim then
--V2C: #spawn #despawn
-- This was where we used to announce player left.
-- Now we announce it when you actually disconnect
-- but not during a shard migration disconnection.
--TheNet:Announce(string.format(STRINGS.UI.NOTIFICATION.LEFTGAME, player:GetDisplayName()), player.entity, true, "leave_game")
--Delete must happen when the player is actually removed
--This is currently handled in playerspawner listening to ms_playerdespawnanddelete
TheWorld:PushEvent("ms_playerdespawnanddelete", player)
end
end
-- Despawn a player, returning to character select screen
function c_despawn(player)
if TheWorld ~= nil and not TheWorld.ismastersim then
c_remote("c_despawn()")
return
end
if TheWorld ~= nil and TheWorld.ismastersim then
--V2C: need to avoid targeting c_spawned player entities
--player = ListingOrConsolePlayer(player)
if type(player) == "string" or type(player) == "number" then
player = UserToPlayer(player)
end
if player == nil then
player = c_sel() ~= nil and c_sel():HasTag("player") and c_sel() or nil
end
if player == nil or player.components.playercontroller == nil then
player = ThePlayer or AllPlayers[1]
end
-------------------------------------------------------------------
if player ~= nil and player:IsValid() then
--Queue it because remote command may currently be overriding
--ThePlayer, which will get stomped during delete
player:DoTaskInTime(0, dodespawn)
end
end
end
function c_getnumplayers()
print(#AllPlayers)
end
function c_getmaxplayers()
print(TheNet:GetDefaultMaxPlayers())
end
-- Return a listing of currently active players
function c_listplayers()
local isdedicated = not TheNet:GetServerIsClientHosted()
local index = 1
for i, v in ipairs(TheNet:GetClientTable() or {}) do
if not isdedicated or v.performance == nil then
print(string.format("%s[%d] (%s) %s <%s>", v.admin and "*" or " ", index, v.userid, v.name, v.prefab))
index = index + 1
end
end
end
-- Return a listing of AllPlayers table
function c_listallplayers()
for i, v in ipairs(AllPlayers) do
print(string.format("[%d] (%s) %s <%s>", i, v.userid, v.name, v.prefab))
end
end
-- Get the currently selected entity, so it can be modified etc.
-- Has a gimpy short name so it's easier to type from the console
function c_sel()
return GetDebugEntity()
end
function c_select(inst)
if not inst then
inst = ConsoleWorldEntityUnderMouse()
end
print("Selected "..tostring(inst or "<nil>") )
SetDebugEntity(inst)
return inst
end
-- Print the (visual) tile under the cursor
function c_tile()
local s = ""
local map = TheWorld.Map
local mx, my, mz = ConsoleWorldPosition():Get()
local tx, ty = map:GetTileCoordsAtPoint(mx,my,mz)
s = s..string.format("world[%f,%f,%f] tile[%d,%d] ", mx,my,mz, tx,ty)
local tile = map:GetTileAtPoint(ConsoleWorldPosition():Get())
for k, v in pairs(WORLD_TILES) do
if v == tile then
s = s..string.format("world_tiles[%s] ", k)
break
end
end
print(s)
end
-- Apply a scenario script to the selection and run it.
function c_doscenario(scenario)
local inst = GetDebugEntity()
if not inst then
print("Need to select an entity to apply the scenario to.")
return
end
if inst.components.scenariorunner then
inst.components.scenariorunner:ClearScenario()
end
-- force reload the script -- this is for testing after all!
package.loaded["scenarios/"..scenario] = nil
inst:AddComponent("scenariorunner")
inst.components.scenariorunner:SetScript(scenario)
inst.components.scenariorunner:Run()
SuUsed("c_doscenario_"..scenario, true)
end
-- Some helper shortcut functions
function c_freecrafting(player)
if TheWorld ~= nil and not TheWorld.ismastersim then
c_remote("c_freecrafting()")
return
end
player = ListingOrConsolePlayer(player)
player.components.builder:GiveAllRecipes()
player:PushEvent("techlevelchange")
end
function c_sel_health()
if c_sel() then
local health = c_sel().components.health
if health then
return health
else
print("Gah! Selection doesn't have a health component!")
return
end
else
print("Gah! Need to select something to access it's components!")
end
end
function c_setinspiration(n)
local player = ConsoleCommandPlayer()
if player ~= nil and player.components.singinginspiration ~= nil and not player:HasTag("playerghost") then
SuUsed("c_setinspiration", true)
player.components.singinginspiration:SetPercent(math.min(n, 1))
end
end
function c_sethealth(n)
local player = ConsoleCommandPlayer()
if player ~= nil and player.components.health ~= nil and not player:HasTag("playerghost") then
SuUsed("c_sethealth", true)
player.components.health:SetPercent(math.min(n, 1))
end
end
function c_setminhealth(n)
local player = ConsoleCommandPlayer()
if player ~= nil and player.components.health ~= nil and not player:HasTag("playerghost") then
SuUsed("c_minhealth", true)
player.components.health:SetMinHealth(n)
end
end
function c_setsanity(n)
local player = ConsoleCommandPlayer()
if player ~= nil and player.components.sanity ~= nil and not player:HasTag("playerghost") then
SuUsed("c_setsanity", true)
player.components.sanity:SetPercent(math.min(n, 1))
end
end
function c_sethunger(n)
local player = ConsoleCommandPlayer()
if player ~= nil and player.components.hunger ~= nil and not player:HasTag("playerghost") then
SuUsed("c_sethunger", true)
player.components.hunger:SetPercent(math.min(n, 1))
end
end
function c_setmightiness(n)
local player = ConsoleCommandPlayer()
if player ~= nil and player.components.mightiness then
player.components.mightiness:SetPercent(n)
end
end
function c_addelectricity(n)
local player = ConsoleCommandPlayer()
if player ~= nil and player.components.upgrademoduleowner ~= nil then
player.components.upgrademoduleowner:AddCharge(n)
end
end
function c_setwereness(n)
local player = ConsoleCommandPlayer()
if player ~= nil and player.components.wereness ~= nil and not player:HasTag("playerghost") then
SuUsed("c_setwereness", true)
if type(n) == "number" then
player.components.wereness:SetPercent(math.min(n, 1))
else
player.components.wereness:SetWereMode(n)
player.components.wereness:SetPercent(1, true)
end
end
end
function c_setmoisture(n)
local player = ConsoleCommandPlayer()
if player ~= nil and player.components.moisture ~= nil and not player:HasTag("playerghost") then
SuUsed("c_setmoisture", true)
player.components.moisture:SetPercent(math.min(n, 1))
end
end
function c_settemperature(n)
if type(n) ~= "number" then
print("c_settemperature expects a number value for its argument:", n)
return
end
local player = ConsoleCommandPlayer()
if player ~= nil and player.components.temperature ~= nil and not player:HasTag("playerghost") then
SuUsed("c_settemperature", true)
player.components.temperature:SetTemperature(n)
end
end
-- Work in progress direct connect code.
-- Currently, to join an online server you must authenticate first.
-- In the future this authentication will be taken care of for you.
function c_connect(ip, port, password)
if not InGamePlay() and TheNet:StartClient(ip, port, 0, password) then
DisableAllDLC()
return true
end
return false
end
-- Put an item(s) in the player's inventory
function c_give(prefab, count, dontselect)
local MainCharacter = ConsoleCommandPlayer()
prefab = string.lower(prefab)
if MainCharacter ~= nil then
local first_inst = nil
for i = 1, count or 1 do
local inst = DebugSpawn(prefab)
if inst ~= nil then
if first_inst == nil then first_inst = inst end
print("giving ", inst)
MainCharacter.components.inventory:GiveItem(inst)
if not dontselect then
SetDebugEntity(inst)
end
SuUsed("c_give_"..inst.prefab)
end
end
return first_inst
end
end
-- Put item(s) into the player's inventory; equip the first one if it is equippable.
function c_equip(prefab, count, dontselect)
local MainCharacter = ConsoleCommandPlayer()
if not MainCharacter then
return nil
end
prefab = string.lower(prefab)
local first = nil
local equip_result = false
for i = 1, count or 1 do
local inst = DebugSpawn(prefab)
if inst ~= nil then
if not first then
first = inst
print("equipping", inst)
equip_result = MainCharacter.components.inventory:Equip(inst)
if not equip_result then
MainCharacter.components.inventory:GiveItem(inst)
elseif not dontselect then
SetDebugEntity(inst)
end
else
print("giving ", inst)
MainCharacter.components.inventory:GiveItem(inst)
end
-- We want to have our equipped one selected; if we failed to equip,
-- we want to select the last thing we spawn, because of stackable.
if not equip_result and not dontselect then
SetDebugEntity(inst)
end
SuUsed("c_equip_"..inst.prefab)
end
end
return first
end
-- Receives a prefab and gives the player all ingredients to craft that prefab
-- Nothing happens if there's no recipe
function c_giveingredients(prefab)
local recipe = AllRecipes[prefab]
if recipe == nil then
print ("No recipe found for prefab ", prefab)
return
end
for i, v in ipairs(recipe.ingredients) do
c_give(v.type, v.amount)
end
end
function c_mat(recname)
local player = ConsoleCommandPlayer()
local recipe = AllRecipes[recname]
if player.components.inventory and recipe then
for ik, iv in pairs(recipe.ingredients) do
for i = 1, iv.amount do
local item = SpawnPrefab(iv.type)
player.components.inventory:GiveItem(item)
SuUsed("c_mat_" .. iv.type , true)
end
end
end
end
function c_pos(inst)
return inst ~= nil and inst:GetPosition() or nil
end
function c_printpos(inst)
print(c_pos(inst))
end
function c_teleport(x, y, z, inst)
inst = ListingOrConsolePlayer(inst)
if inst ~= nil then
if x == nil then
x, y, z = ConsoleWorldPosition():Get()
end
inst.Transform:SetPosition(x, y, z)
SuUsed("c_teleport", true)
end
end
function c_move(inst)
inst = inst or c_sel()
if inst ~= nil then
inst.Transform:SetPosition(ConsoleWorldPosition():Get())
SuUsed("c_move", true)
end
end
function c_goto(dest, inst)
if type(dest) == "string" or type(dest) == "number" then
dest = UserToPlayer(dest)
end
if dest ~= nil then
inst = ListingOrConsolePlayer(inst)
if inst ~= nil then
if inst.Physics ~= nil then
inst.Physics:Teleport(dest.Transform:GetWorldPosition())
else
inst.Transform:SetPosition(dest.Transform:GetWorldPosition())
end
inst:SnapCamera()
SuUsed("c_goto", true)
return dest
end
end
end
function c_inst(guid)
return Ents[guid]
end
function c_list(prefab)
local x,y,z = ConsoleCommandPlayer().Transform:GetWorldPosition()
local ents = TheSim:FindEntities(x,y,z, 9001)
for k,v in pairs(ents) do
if v.prefab == prefab then
print(string.format("%s {%2.2f, %2.2f, %2.2f}", tostring(v), v.Transform:GetWorldPosition()))
end
end
end
function c_listtag(tag)
local tags = {tag}
local x,y,z = ConsoleCommandPlayer().Transform:GetWorldPosition()
local ents = TheSim:FindEntities(x,y,z, 9001, tags)
for k,v in pairs(ents) do
print(string.format("%s {%2.2f, %2.2f, %2.2f}", tostring(v), v.Transform:GetWorldPosition()))
end
end
function c_kitcoon(name, age, build)
-- NOTES(JBK): This is for players who for outside forces or otherwise lost their kitcoon pet and want a way for it back.
-- The hope is that this function is easier to use and can be used by the community.
if type(name) ~= "string" or type(age) ~= "number" or type(build) ~= "string" or not table.contains(VALID_KITCOON_BUILDS, build) then
print("Invalid c_kitcoon use. c_kitcoon(\"name here\", #, \"build_name_here\")")
print("Example: c_kitcoon(\"kitty the IV\", 42, \"kitcoon_deciduous_build\")")
print("Age is how many days old it is. Valid build names are:")
for _, build in ipairs(VALID_KITCOON_BUILDS) do
print(build)
end
return
end
local now = os.time()
Profile:SetKitName(name)
Profile:SetKitLastTime(now)
Profile:SetKitBirthTime(now - age * 60 * 60 * 24)
Profile:SetKitBuild(build)
Profile:SetKitSize(1) -- Just make it large.
Profile:SetKitHunger(0.5)
Profile:SetKitHappiness(0.7)
Profile:SetKitPoops(0)
Profile:SetKitAbandonedMessage(false)
Profile:Save()
end
local lastroom = -1
function c_gotoroom(roomname, inst)
inst = ListingOrConsolePlayer(inst)
if inst == nil then
return
end
local found = nil
local foundid = nil
local reallowest = nil
local reallowestid = nil
local count = 0
print("Finding room containing",roomname)
roomname = string.lower(roomname)
for i, node in ipairs(TheWorld.topology.nodes) do
if string.lower(TheWorld.topology.ids[i]):find(roomname) then
if reallowest == nil then
reallowest = node
reallowestid = i
end
count = count + 1
if i > lastroom then
found = node
foundid = i
break
end
end
end
if found == nil and reallowest ~= nil then
found = reallowest
foundid = reallowestid
end
if found ~= nil then
print("Going to ", TheWorld.topology.ids[foundid], "("..count..")")
c_teleport(found.cent[1],0,found.cent[2],inst)
lastroom = foundid
else
print("Couldn't find a matching room.")
end
end
local lastfound = -1
local lastprefab = nil
function c_findnext(prefab, radius, inst)
if type(inst) == "string" or type(inst) == "number" then
inst = UserToPlayer(inst)
if inst == nil then
return
end
end
inst = inst or ConsoleCommandPlayer() or TheWorld
if inst == nil then
return
end
prefab = prefab or lastprefab
lastprefab = prefab
local trans = inst.Transform
local found = nil
local foundlowestid = nil
local reallowest = nil
local reallowestid = nil
local reallowestidx = -1
print("Finding a ",prefab)
local x,y,z = trans:GetWorldPosition()
local ents = {}
if radius == nil then
ents = Ents
else
-- note: this excludes CLASSIFIED
ents = TheSim:FindEntities(x,y,z, radius)
end
local total = 0
local idx = -1
for k,v in pairs(ents) do
if v ~= inst and v.prefab == prefab then
total = total+1
if v.GUID > lastfound and (foundlowestid == nil or v.GUID < foundlowestid) then
idx = total
found = v
foundlowestid = v.GUID
end
if not reallowestid or v.GUID < reallowestid then
reallowest = v
reallowestid = v.GUID
reallowestidx = total
end
end
end
if not found then
found = reallowest
idx = reallowestidx
end
if not found then
print("Could not find any objects matching '"..prefab.."'.")
lastfound = -1
else
print(string.format("Found %s (%d/%d)", found.GUID, idx, total ))
lastfound = found.GUID
end
return found
end
function c_godmode(player)
if TheWorld ~= nil and not TheWorld.ismastersim then
c_remote("c_godmode()")
return
end
player = ListingOrConsolePlayer(player)
if player ~= nil then
SuUsed("c_godmode", true)
if player:HasTag("playerghost") then
player:PushEvent("respawnfromghost")
print("Reviving "..player.name.." from ghost.")
return
elseif player:HasTag("corpse") then
player:PushEvent("respawnfromcorpse")
print("Reviving "..player.name.." from corpse.")
return
elseif player.components.health ~= nil then
local godmode = player.components.health.invincible
player.components.health:SetInvincible(not godmode)
print("God mode: "..tostring(not godmode))
end
end
end
function c_supergodmode(player)
if TheWorld ~= nil and not TheWorld.ismastersim then
c_remote("c_supergodmode()")
return
end
player = ListingOrConsolePlayer(player)
if player ~= nil then
SuUsed("c_supergodmode", true)
if player:HasTag("playerghost") then
player:PushEvent("respawnfromghost")
print("Reviving "..player.name.." from ghost.")
return
elseif player.components.health ~= nil then
local godmode = player.components.health.invincible
player.components.health:SetInvincible(not godmode)
c_sethealth(1)
c_setsanity(1)
c_sethunger(1)
c_settemperature(25)
c_setmoisture(0)
print("God mode: "..tostring(not godmode))
end
end
end
function c_armor(player)
player = ListingOrConsolePlayer(player)
if player ~= nil and player.components.health ~= nil then
SuUsed("c_armor", true)
player.components.health:SetAbsorptionAmount(1)
print("Enabled full absorption on " .. tostring(player.userid))
end
end
function c_armour(player)
c_armor(player)
end
function c_find(prefab, radius, inst)
inst = ListingOrConsolePlayer(inst)
if inst == nil then
return
end
radius = radius or 9001
local trans = inst.Transform
local found = nil
local founddistsq = nil
local x,y,z = trans:GetWorldPosition()
local ents = TheSim:FindEntities(x,y,z, radius)
for k,v in pairs(ents) do
if v ~= inst and v.prefab == prefab then
if not founddistsq or inst:GetDistanceSqToInst(v) < founddistsq then
found = v
founddistsq = inst:GetDistanceSqToInst(v)
end
end
end
return found
end
function c_findtag(tag, radius, inst)
inst = ListingOrConsolePlayer(inst)
return inst ~= nil and GetClosestInstWithTag(tag, inst, radius or 1000) or nil
end
function c_gonext(name)
if name ~= nil then
local next = c_findnext(string.lower(name))
if next ~= nil and next.Transform ~= nil then
return c_goto(next)
end
end
return nil
end
function c_printtextureinfo( filename )
TheSim:PrintTextureInfo( filename )
end
function c_simphase(phase)
TheWorld:PushEvent("phasechange", {newphase = phase})
end
function c_countprefabs(prefab, noprint)
local count = 0
for k,v in pairs(Ents) do
if v.prefab == prefab then
count = count + 1
end
end
if not noprint then
print("There are ", count, prefab.."s in the world.")
end
return count
end
function c_counttagged(tag, noprint)
local count = 0
for k,v in pairs(Ents) do
if v:HasTag(tag) then
count = count + 1
end
end
if not noprint then
print("There are ", count, tag.."-tagged ents in the world.")
end
return count
end
function c_countallprefabs()
local total = 0
local unk = 0
local counted = {}
for k,v in pairs(Ents) do
if v.prefab ~= nil then
if counted[v.prefab] == nil then
counted[v.prefab] = 1
else
counted[v.prefab] = counted[v.prefab] + 1
end
total = total + 1
else
unk = unk + 1
end
end
local function pairsByKeys (t, f)
local a = {}
for n in pairs(t) do table.insert(a, n) end
table.sort(a, f)
local i = 0 -- iterator variable
local iter = function () -- iterator function
i = i + 1
if a[i] == nil then return nil
else return a[i], t[a[i]]
end
end
return iter
end
for k,v in pairsByKeys(counted) do
print(k, v)
end
print(string.format("There are %d different prefabs in the world, %d total (and %d unknown)", GetTableSize(counted), total, unk))
end
function c_speedmult(multiplier)
local inst = ConsoleCommandPlayer()
if inst ~= nil then
inst.components.locomotor:SetExternalSpeedMultiplier(inst, "c_speedmult", multiplier)
end
end
function c_dump()
local ent = GetDebugEntity()
if not ent then
ent = ConsoleWorldEntityUnderMouse()
end
DumpEntity(ent)
end
function c_dumpseasons()
local str = TheWorld.net.components.seasons:GetDebugString()
print(str)
end
function c_dumpworldstate()
print("")
print("//======================== DUMPING WORLD STATE ========================\\\\")
print("\n"..TheWorld.components.worldstate:Dump())
print("\\\\=====================================================================//")
print("")
end
function c_worldstatedebug()
WORLDSTATEDEBUG_ENABLED = not WORLDSTATEDEBUG_ENABLED
end
function c_makeinvisible()
local player = ConsoleCommandPlayer()
player:AddTag("debugnoattack")
print("Has debugnoattack tag?", player, player:HasTag("debugnoattack"))
end
function c_selectnext(name)
return c_select(c_findnext(name))
end
function c_selectnear(prefab, rad)
local player = ConsoleCommandPlayer()
local x,y,z = player.Transform:GetWorldPosition()
local ents = TheSim:FindEntities(x,y,z, rad or 30)
local closest = nil
local closeness = nil
for k,v in pairs(ents) do