Skip to content

Instantly share code, notes, and snippets.

@TIMcre
Last active August 22, 2023 07:35
Show Gist options
  • Save TIMcre/524fe063184c163417bb10b16bbd7b12 to your computer and use it in GitHub Desktop.
Save TIMcre/524fe063184c163417bb10b16bbd7b12 to your computer and use it in GitHub Desktop.
You are abel to Control Pistons in Space Engeniers in a better way
//start
//any questions or it isnt working? just contact me and i will try to help you :)
//The argument you pass in throught the button needs to be a valid Group name in the grid
//Idealy with only pistons in it. Like this you will only need this script only once per grid.
//velo stands for the velocity of the piston. Needs to be positive.
//for numbers that use an , put an f behind it.
//Varibels to edit
float velo = 3;
float fontsizedebug = 1,2f;
float fontsizenormal = 1,7f;
//variabels to not touch
int button = 1;
bool stop = false;
public Program(){}
//code start
public void Main(string argument, UpdateType updateSource)
{
IMyTextSurface diplay0 = Me.GetSurface(0);
diplay0.ContentType = ContentType.TEXT_AND_IMAGE;
diplay0.Alignment = VRage.Game.GUI.TextPanel.TextAlignment.CENTER;
IMyBlockGroup group = GridTerminalSystem.GetBlockGroupWithName(argument);
if (group == null)
{
diplay0.FontSize = fontsizedebug;
diplay0.WriteText("Error: No Group found with that name");
Echo("Error: No Group found with that name");
return;
}
List<IMyTerminalBlock> pistons = new List<IMyTerminalBlock>();
group.GetBlocksOfType<IMyPistonBase>(pistons);
Echo("Blocks found:");
foreach (var block in pistons)
{
Echo($"- {block.CustomName}");
}
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
IMyPistonBase pistonsingel = null;
foreach (var block in pistons)
{
var id = block.EntityId;
var piston = (IMyPistonBase)GridTerminalSystem.GetBlockWithId(id);
blocks.Add(piston);
pistonsingel = piston;
piston.Enabled = true;
}
var info = pistonsingel.CurrentPosition;
diplay0.WriteText("Current State of Pistons:\n");
if (info < 9 && info > 1 && stop == false)
{
foreach (IMyPistonBase piston in blocks)
{
piston.Enabled = false;
}
stop = true;
diplay0.WriteText("Current State of Pistons:\nStoping");
Echo("Current State of Pistons:\nStoping");
}
else if (button == 0)
{
foreach (IMyPistonBase piston in blocks)
{
piston.Velocity = velo;
}
button = 1;
stop = false;
diplay0.WriteText("Current State of Pistons:\nExtending");
Echo("Current State of Pistons:\nExtending");
}
else if (button == 1)
{
foreach (IMyPistonBase piston in blocks)
{
piston.Velocity = velo * -1;
}
button = 0;
stop = false;
diplay0.WriteText("Current State of Pistons:\nRetrecating");
Echo("Current State of Pistons:\nRetrecating");
}
}
//end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment