Skip to content

Commit 6aafed3

Browse files
committed
Added delete offtype command to cleanup to remove by isWorking==false
1 parent 911b610 commit 6aafed3

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

‎Essentials/Commands/CleanupModule.cs‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,30 @@ public void Delete()
5959
Log.Info($"Cleanup deleted {count} grids matching conditions {string.Join(", ", Context.Args)}");
6060
}
6161

62+
[Command("delete offtype", "Deletes grids with specified blocks toggled off.")]
63+
public void OffType(string type)
64+
{
65+
var count = 0;
66+
foreach (var grid in MyEntities.GetEntities().OfType<MyCubeGrid>().Where(x => x.Projector == null))
67+
{
68+
foreach (var block in grid.GetFatBlocks().OfType<IMyFunctionalBlock>())
69+
{
70+
var blockType = block.BlockDefinition.TypeId.ToString().Substring(16);
71+
if (block != null && string.Compare(type, blockType, StringComparison.InvariantCultureIgnoreCase) == 0)
72+
{
73+
if (block.IsWorking == false)
74+
{
75+
Log.Info($"Deleting grid: {grid.EntityId}: {grid.DisplayName}");
76+
EjectPilots(grid);
77+
grid.Close();
78+
count++;
79+
}
80+
}
81+
}
82+
}
83+
Context.Respond($"grid delete {count} with off blocks of type {type}.");
84+
}
85+
6286
[Command("delete floatingobjects", "deletes floating objects")]
6387
public void FlObjDelete()
6488
{
@@ -331,7 +355,7 @@ public bool OwnedBy(MyCubeGrid grid, string str)
331355
return grid.BigOwners.Count > 0 &&
332356
MySession.Static.Factions.IsNpcFaction(grid.BigOwners.FirstOrDefault());
333357
}
334-
358+
335359

336360
if (string.Compare(str, "pirates", StringComparison.InvariantCultureIgnoreCase) == 0)
337361
{
@@ -356,7 +380,7 @@ public bool OwnedBy(MyCubeGrid grid, string str)
356380

357381
return grid.BigOwners.Contains(identityId);
358382
}
359-
383+
360384

361385
[Condition("hastype", "notype", "Finds grids containing blocks of the given type.")]
362386
public bool BlockType(MyCubeGrid grid, string str)

0 commit comments

Comments
 (0)