Skip to content

Commit 80fdd2e

Browse files
committed
Add some entity commands for testing
1 parent 03232ed commit 80fdd2e

4 files changed

Lines changed: 177 additions & 0 deletions

File tree

Essentials/EntityCommands.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Torch.Commands;
7+
using VRage.ModAPI;
8+
using VRageMath;
9+
10+
namespace Essentials
11+
{
12+
[Category("entity")]
13+
public class EntityCommands : CommandModule
14+
{
15+
[Command("stop", "Stops an entity from moving")]
16+
public void Stop()
17+
{
18+
if (!Utilities.TryGetEntityByNameOrId(Context.Args.FirstOrDefault(), out IMyEntity entity))
19+
{
20+
Context.Respond("Entity not found.");
21+
return;
22+
}
23+
24+
entity?.Physics.ClearSpeed();
25+
Context.Respond($"Entity '{entity.DisplayName}' stopped");
26+
}
27+
28+
[Command("delete", "Delete an entity.")]
29+
public void Delete()
30+
{
31+
if (!Utilities.TryGetEntityByNameOrId(Context.Args.FirstOrDefault(), out IMyEntity entity))
32+
{
33+
Context.Respond("Entity not found.");
34+
return;
35+
}
36+
37+
entity.Close();
38+
Context.Respond($"Entity '{entity.DisplayName}' deleted");
39+
}
40+
}
41+
}

Essentials/Essentials.csproj

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@
3030
<WarningLevel>4</WarningLevel>
3131
</PropertyGroup>
3232
<ItemGroup>
33+
<Reference Include="Sandbox.Common">
34+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\Sandbox.Common.dll</HintPath>
35+
</Reference>
36+
<Reference Include="Sandbox.Game">
37+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\Sandbox.Game.dll</HintPath>
38+
</Reference>
39+
<Reference Include="Sandbox.Graphics">
40+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\Sandbox.Graphics.dll</HintPath>
41+
</Reference>
42+
<Reference Include="SpaceEngineers.Game">
43+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\SpaceEngineers.Game.dll</HintPath>
44+
</Reference>
45+
<Reference Include="SpaceEngineers.ObjectBuilders">
46+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\SpaceEngineers.ObjectBuilders.dll</HintPath>
47+
</Reference>
48+
<Reference Include="SpaceEngineers.ObjectBuilders.XmlSerializers">
49+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\SpaceEngineers.ObjectBuilders.XmlSerializers.dll</HintPath>
50+
</Reference>
3351
<Reference Include="System" />
3452
<Reference Include="System.Core" />
3553
<Reference Include="System.Xml.Linq" />
@@ -47,10 +65,52 @@
4765
<Reference Include="Torch.Server">
4866
<HintPath>..\..\Torch\Torch.Server\bin\x64\Release\Torch.Server.exe</HintPath>
4967
</Reference>
68+
<Reference Include="VRage">
69+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.dll</HintPath>
70+
</Reference>
71+
<Reference Include="VRage.Audio">
72+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Audio.dll</HintPath>
73+
</Reference>
74+
<Reference Include="VRage.Dedicated">
75+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Dedicated.dll</HintPath>
76+
</Reference>
77+
<Reference Include="VRage.Game">
78+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Game.dll</HintPath>
79+
</Reference>
80+
<Reference Include="VRage.Game.XmlSerializers">
81+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Game.XmlSerializers.dll</HintPath>
82+
</Reference>
83+
<Reference Include="VRage.Input">
84+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Input.dll</HintPath>
85+
</Reference>
86+
<Reference Include="VRage.Library">
87+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Library.dll</HintPath>
88+
</Reference>
89+
<Reference Include="VRage.Math">
90+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Math.dll</HintPath>
91+
</Reference>
92+
<Reference Include="VRage.Native">
93+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Native.dll</HintPath>
94+
</Reference>
95+
<Reference Include="VRage.OpenVRWrapper">
96+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.OpenVRWrapper.dll</HintPath>
97+
</Reference>
98+
<Reference Include="VRage.Render">
99+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Render.dll</HintPath>
100+
</Reference>
101+
<Reference Include="VRage.Render11">
102+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Render11.dll</HintPath>
103+
</Reference>
104+
<Reference Include="VRage.Scripting">
105+
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Scripting.dll</HintPath>
106+
</Reference>
50107
</ItemGroup>
51108
<ItemGroup>
109+
<Compile Include="EntityCommands.cs" />
52110
<Compile Include="EssentialsPlugin.cs" />
111+
<Compile Include="GridCommands.cs" />
53112
<Compile Include="Properties\AssemblyInfo.cs" />
113+
<Compile Include="Utilities.cs" />
54114
</ItemGroup>
55115
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
56116
</Project>

Essentials/GridCommands.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Sandbox.Game.Entities;
7+
using Sandbox.ModAPI;
8+
using Torch.Commands;
9+
using VRage.Game.Entity.EntityComponents;
10+
using VRage.Game.ModAPI;
11+
using VRage.ModAPI;
12+
13+
namespace Essentials
14+
{
15+
[Category("grid")]
16+
public class GridCommands : CommandModule
17+
{
18+
[Command("setowner", "Sets grid ownership to the given player or ID.", "Usage: setowner <grid> <newowner>")]
19+
public void SetOwner()
20+
{
21+
var firstArg = Context.Args.FirstOrDefault();
22+
Utilities.TryGetEntityByNameOrId(firstArg, out IMyEntity entity);
23+
24+
if (!(entity is IMyCubeGrid grid))
25+
{
26+
Context.Respond($"Grid {firstArg} not found.");
27+
return;
28+
}
29+
30+
var secondArg = Context.Args.ElementAtOrDefault(1);
31+
long identityId;
32+
if (!long.TryParse(secondArg, out identityId))
33+
{
34+
var player = Context.Torch.Multiplayer.GetPlayerByName(secondArg);
35+
if (player == null)
36+
{
37+
Context.Respond($"Player {secondArg} not found.");
38+
return;
39+
}
40+
identityId = player.IdentityId;
41+
}
42+
43+
grid.GetBlocks(new List<IMySlimBlock>(), block =>
44+
{
45+
var cubeBlock = block.FatBlock as MyCubeBlock;
46+
var ownerComp = cubeBlock?.Components.Get<MyEntityOwnershipComponent>();
47+
if (ownerComp == null)
48+
return false;
49+
50+
cubeBlock?.ChangeOwner(identityId, ownerComp.ShareMode);
51+
return false;
52+
});
53+
}
54+
}
55+
}

Essentials/Utilities.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Sandbox.ModAPI;
7+
using VRage.ModAPI;
8+
9+
namespace Essentials
10+
{
11+
public static class Utilities
12+
{
13+
public static bool TryGetEntityByNameOrId(string nameOrId, out IMyEntity entity)
14+
{
15+
if (long.TryParse(nameOrId, out long id))
16+
return MyAPIGateway.Entities.TryGetEntityById(id, out entity);
17+
18+
return MyAPIGateway.Entities.TryGetEntityByName(nameOrId, out entity);
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)