Docking “manager” 0/5 (1)

posted in: Scripts | 0

This is a script I wrote in response to a Reddit thread:

For everyone having problems with ships breaking loose… from spaceengineers

 

What this script does is:

If you set it to run constantly on a programming block (via a timer triggering/starting itself), it will check all gyros and thrusters that it can access. If it finds any gyros or thrusters that are not on the same grid as the programming block, it turns them off.

So…

If you have a capital ship, set this program to run on that ship. Whenever you dock a smaller ship to your capital ship, it will automatically turn the gyros and thrusters on the smaller ship off. This avoids problems where if you were to forget to do that manually, and then try to move the capital ship, the smaller ship keeps trying to “dampen” the movement and eventually breaks the connector connection.

void Main() 
{ 
    List<IMyTerminalBlock> work = new List<IMyTerminalBlock>(); 
    List<IMyTerminalBlock> gyrosAndThrusters = new List<IMyTerminalBlock>(); 
 
    IMyCubeGrid myGrid = Me.CubeGrid;
    GridTerminalSystem.GetBlocksOfType<IMyGyro>(work); gyrosAndThrusters.AddRange(work); work.Clear();
    GridTerminalSystem.GetBlocksOfType<IMyThrust>(work); gyrosAndThrusters.AddRange(work); work.Clear();
    for (int i = 0; i < gyrosAndThrusters.Count; i++) 
    { 
       if (gyrosAndThrusters[i].CubeGrid != myGrid) {
          gyrosAndThrusters[i].GetActionWithName("OnOff_Off").Apply(gyrosAndThrusters[i]);
       }
    } 
} 

Please rate this post

Leave a Reply