Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions Essentials/AutoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ public class AutoCommand : ViewModel
private DateTime _nextRun = DateTime.MinValue;
private DayOfWeek _day = DayOfWeek.All;
private int _currentStep;
private int _votepercentage;
private TimeSpan _voteDuration = TimeSpan.Zero;
private string _name;
private bool _enabled;
private bool _votable;

[Display(Description = "Enables or disables this command. NOTE: !admin runauto does NOT respect this setting!")]
public bool Enabled
Expand All @@ -31,6 +34,7 @@ public bool Enabled
set => SetValue(ref _enabled, value);
}


[Display(Description = "Sets the name of this command. Use this name in conjunction with !admin runauto to trigger the command from ingame or from other auto commands.")]
public string Name
{
Expand Down Expand Up @@ -72,6 +76,27 @@ public string Interval
}
}

[Display(Description = "Adds voting option to this command. NOTE: A successful vote will activate this command")]
public bool Votable
{
get => _votable;
set => SetValue(ref _votable, value);
}

[Display(Name = "Vote Duration", Description = "Sets the duration for the vote. NOTE: Make sure to check the votable box to activate. Format is HH:MM:SS.")]
public string VoteDuration
{
get => _voteDuration.ToString();
set => SetValue(ref _voteDuration, TimeSpan.Parse(value));
}

[Display(Name = "Vote Percentage", Description = "Sets the percentage Yes vote needed for the command to activate. NOTE: This only works if the votable box is checked")]
public int Percentage
{
get => _votepercentage;
set => SetValue(ref _votepercentage, value);
}

[Display(Name = "Day of week", GroupName = "Schedule", Description = "Combined with Scheduled Time, will run the command on the given day of the week at the set time.")]
public DayOfWeek DayOfWeek
{
Expand Down Expand Up @@ -166,13 +191,13 @@ public override string ToString()
internal void RunNow()
{
Task.Run(() =>
{
foreach (var step in Steps)
{
step.RunStep();
Thread.Sleep(step.DelaySpan);
}
});
{
foreach (var step in Steps)
{
step.RunStep();
Thread.Sleep(step.DelaySpan);
}
});
}

public override string ToString()
Expand Down
2 changes: 1 addition & 1 deletion Essentials/Commands/AdminModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void PlayerCount(int count = -1)
{
if (count == -1)
{
Context.Respond($"Nax player count: {MyMultiplayer.Static.MemberLimit}. Current online players: {MyMultiplayer.Static.MemberCount - 1}");
Context.Respond($"Max player count: {MyMultiplayer.Static.MemberLimit}. Current online players: {MyMultiplayer.Static.MemberCount - 1}");
Comment thread
N1Ran marked this conversation as resolved.
return;
}

Expand Down
121 changes: 121 additions & 0 deletions Essentials/Commands/BlocksModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sandbox.Common.ObjectBuilders;
using Sandbox.Game.Entities;
using VRage.Game.ModAPI;
using Sandbox.Game.Entities.Cube;
using Sandbox.ModAPI;
using Torch.Commands;
Expand Down Expand Up @@ -136,5 +138,124 @@ public void OffSubtype(string subtype)

Context.Respond($"Disabled {count} blocks of subtype {subtype}.");
}

[Command("on general", "Turn on all blocks of the specified general")]
Comment thread
N1Ran marked this conversation as resolved.
Outdated
public void OnGeneral(string general)
{
var count = 0;
string status = "?";
foreach (var entity in MyEntities.GetEntities().OfType<MyCubeGrid>())
{
IMyCubeGrid grid = entity as MyCubeGrid;
if (general.Contains("pow"))
Comment thread
N1Ran marked this conversation as resolved.
Outdated
{
status = "Power";
var blocks = new List<IMySlimBlock>();
grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock is IMyFunctionalBlock
&& (f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Reactor) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_BatteryBlock) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_SolarPanel)));
var list = blocks.Select(f => (IMyFunctionalBlock)f.FatBlock).Where(f => !f.Enabled).ToArray();
foreach (var item in list)
{
item.Enabled = true;
}
count++;
}
if (general.Contains("prod"))
{
status = "Production";
var blocks = new List<IMySlimBlock>();
grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock is IMyFunctionalBlock
&& (f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Refinery) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Assembler) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_OxygenGenerator)));
var list = blocks.Select(f => (IMyFunctionalBlock)f.FatBlock).Where(f => !f.Enabled).ToArray();
foreach (var item in list)
{
item.Enabled = true;
}
count++;

}
if (general.Contains("wea"))
{
status = "Weapon";
var blocks = new List<IMySlimBlock>();
grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock is IMyFunctionalBlock
&& (f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_InteriorTurret) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_TurretBase) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_LargeMissileTurret)));
var list = blocks.Select(f => (IMyFunctionalBlock)f.FatBlock).Where(f => !f.Enabled).ToArray();
foreach (var item in list)
{
item.Enabled = true;
}
count++;

}
}

Context.Respond($"Enabled {count} {status} blocks.");
}
[Command("off general", "Turn off all blocks of the specified general")]
public void OffGeneral(string general)
{
var count = 0;
string status = "?";
foreach (var entity in MyEntities.GetEntities().OfType<MyCubeGrid>())
{
IMyCubeGrid grid = entity as MyCubeGrid;
if (general.Contains("pow"))
{
status = "Power";
var blocks = new List<IMySlimBlock>();
grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock is IMyFunctionalBlock
&& (f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Reactor) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_BatteryBlock) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_SolarPanel)));
var list = blocks.Select(f => (IMyFunctionalBlock)f.FatBlock).Where(f => f.Enabled).ToArray();
foreach (var item in list)
{
item.Enabled = false;
}
count++;
}
if (general.Contains("prod"))
{
status = "Production";
var blocks = new List<IMySlimBlock>();
grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock is IMyFunctionalBlock
&& (f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Refinery) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Assembler) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_OxygenGenerator)));
var list = blocks.Select(f => (IMyFunctionalBlock)f.FatBlock).Where(f => f.Enabled).ToArray();
foreach (var item in list)
{
item.Enabled = false;
}
count++;

}
if (general.Contains("wea"))
{
status = "Weapon";
var blocks = new List<IMySlimBlock>();
grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock is IMyFunctionalBlock
&& (f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_InteriorTurret) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_TurretBase) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_LargeMissileTurret)));
var list = blocks.Select(f => (IMyFunctionalBlock)f.FatBlock).Where(f => f.Enabled).ToArray();
foreach (var item in list)
{
item.Enabled = false;
}
count++;

}
}

Context.Respond($"Disabled {count} {status} blocks.");
}
}
}
12 changes: 12 additions & 0 deletions Essentials/Commands/CleanupModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ public void List()
public void Delete()
{
var count = 0;
if (Context.Args.Contains("float"))
Comment thread
N1Ran marked this conversation as resolved.
Outdated
{
foreach (var floater in MyEntities.GetEntities().OfType<MyFloatingObject>())
{
Log.Info($"Deleted floating object: {floater.DisplayName}");
floater.Close();
count++;
}
Context.Respond($"Deleted {count} floating objects.");
Log.Info($"Cleanup deleted {count} floating objects");
return;
}
foreach (var grid in ScanConditions(Context.Args))
{
Log.Info($"Deleting grid: {grid.EntityId}: {grid.DisplayName}");
Expand Down
113 changes: 102 additions & 11 deletions Essentials/Commands/EntityModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Sandbox;
using Sandbox.Engine.Multiplayer;
using Sandbox.Game.Entities;
using Sandbox.Game.World;
using Sandbox.Common.ObjectBuilders;
using Sandbox.ModAPI;
using Torch.Commands;
using Torch.Commands.Permissions;
using Torch.Utils;
using Torch.API.Managers;
using VRage.Collections;
using VRage.Game.Entity;
using VRage.Game.ModAPI;
using VRage.ModAPI;
using VRage.Game;
using VRage.Network;
using VRage.Replication;
using VRageMath;
using IMyDestroyableObject = VRage.Game.ModAPI.Interfaces.IMyDestroyableObject;



namespace Essentials
{
Expand All @@ -41,7 +41,7 @@ public class EntityModule : CommandModule
private static Action<MyReplicationServer, IMyReplicable, Endpoint> _forceReplicable;
#pragma warning restore 649

private static Dictionary<ulong,DateTime> _commandtimeout = new Dictionary<ulong,DateTime>();
private static Dictionary<ulong, DateTime> _commandtimeout = new Dictionary<ulong, DateTime>();

[Command("refresh", "Resyncs all entities for the player running the command.")]
[Permission(MyPromoteLevel.None)]
Expand All @@ -56,16 +56,16 @@ public void Refresh()
TimeSpan difference = DateTime.Now - lastcommand;
if (difference.TotalMinutes < 1)
{
Context.Respond($"Cooldown active. You can use this command again in {difference.TotalSeconds:N0} seconds");
return;
Context.Respond($"Cooldown active. You can use this command again in {difference.TotalSeconds:N0} seconds");
return;
}
else
{
_commandtimeout[steamid] = DateTime.Now;
_commandtimeout[steamid] = DateTime.Now;
}
}
else
{
{
_commandtimeout.Add(steamid, DateTime.Now);
}

Expand Down Expand Up @@ -135,6 +135,29 @@ public void Delete(string entityName)
Context.Respond($"Entity '{entity.DisplayName}' deleted");
}

[Command("kill", "kill a player.")]
[Permission(MyPromoteLevel.SpaceMaster)]
public void Kill(string name)
{
if (string.IsNullOrEmpty(name))
return;
Comment thread
N1Ran marked this conversation as resolved.

if (!Utilities.TryGetEntityByNameOrId(name, out IMyEntity entity))
{
Context.Respond($"Entity '{name}' not found.");
return;
}

if (entity is IMyCharacter)
{
var destroyable = entity as IMyDestroyableObject;
destroyable.DoDamage(1000f, MyDamageType.Radioactivity, true);
Context.Torch.CurrentSession?.Managers?.GetManager<IChatManagerServer>()?.SendMessageAsSelf
($"{entity.DisplayName} was killed by an admin");
}
}


[Command("find", "Find entities with the given text in their name.")]
[Permission(MyPromoteLevel.SpaceMaster)]
public void Find(string name)
Expand All @@ -154,5 +177,73 @@ public void Find(string name)

Context.Respond(sb.ToString());
}

[Command("poweroff", "Power off entities with the given text in their name.")]
[Permission(MyPromoteLevel.SpaceMaster)]
public void PowerOff(string name)
{

if (string.IsNullOrEmpty(name))
return;

if (!Utilities.TryGetEntityByNameOrId(name, out IMyEntity entity))
{
Context.Respond($"Entity '{name}' not found.");
return;
}

if (entity is IMyCharacter)
{
Context.Respond("Command do not work on characters.");
return;
}
IMyCubeGrid grid = entity as MyCubeGrid;
var blocks = new List<IMySlimBlock>();
grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock is IMyFunctionalBlock
&& (f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Reactor) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_BatteryBlock) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_SolarPanel)));
var list = blocks.Select(f => (IMyFunctionalBlock)f.FatBlock).Where(f => f.Enabled).ToArray();
foreach (var item in list)
{
item.Enabled = false;
}
Context.Respond($"Entity '{entity.DisplayName}' powered off");

}

[Command("poweron", "Power on entities with the given text in their name.")]
[Permission(MyPromoteLevel.SpaceMaster)]
public void PowerOn(string name)
{

if (string.IsNullOrEmpty(name))
return;

if (!Utilities.TryGetEntityByNameOrId(name, out IMyEntity entity))
{
Context.Respond($"Entity '{name}' not found.");
return;
}

if (entity is IMyCharacter)
{
Context.Respond("Command do not work on characters.");
return;
}
IMyCubeGrid grid = entity as MyCubeGrid;
var blocks = new List<IMySlimBlock>();
grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock is IMyFunctionalBlock
&& (f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Reactor) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_BatteryBlock) ||
f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_SolarPanel)));
var list = blocks.Select(f => (IMyFunctionalBlock)f.FatBlock).Where(f => !f.Enabled).ToArray();
foreach (var item in list)
{
item.Enabled = true;
}
Context.Respond($"Entity '{entity.DisplayName}' powered on");

}
}
}
Loading