WhamyKaBlamy

Pistons Mining Rig Script

Dec 1st, 2017
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.20 KB | None | 0 0
  1. //Notes:  
  2.     //Good settings are:  
  3.     //Pistons & Rotor Force of 22.8kn
  4.     //Rotor 1.07 RPM
  5.     //Rotor Torque and Breaking Torque maxed out
  6.     //Timer set to 30 seconds
  7.  
  8.  
  9. string Go_Timer_Name = "Pistons_Timer_Go"; //Change this to the name of the timer used to control everything
  10.                                         //The timer should be set to 30 seconds and to pass an argument of "Go"  
  11.                                         //to the progammable block
  12.  
  13. string Rotor_Name = "Pistons_Rotor"; //Name of the rotor that the drills are attached to  
  14.  
  15.  
  16. void Main(string Argument)
  17. {
  18.     List<IMyPistonBase> Pistons = new List<IMyPistonBase>();
  19.     GridTerminalSystem.GetBlocksOfType<IMyPistonBase>(Pistons);
  20.     bool Active = false;
  21.     if(Argument == "Go")
  22.     {
  23.         for(int i = 0; i < Pistons.Count ; i++)
  24.         {
  25.             if(Active == false)
  26.             {
  27.                 if(Pistons[i].Velocity < 0.0)
  28.                 {
  29.                     Pistons[i].GetActionWithName("IncreaseVelocity").Apply(Pistons[i]);
  30.                 }
  31.                 if(Pistons[i].Velocity > 0.0)
  32.                 {
  33.                     List <String>Pistons_Info = new List<String>(Pistons[i].DetailedInfo.Split(new string[] {" ","\n","\r","m"}, StringSplitOptions.None));    
  34.                     decimal Extension = Math.Round(Convert.ToDecimal(Pistons_Info[4]),1);
  35.                     decimal Max_Limit = Math.Round((decimal)Pistons[i].MaxLimit,1);
  36.                     if( Max_Limit < 10 &&  Extension == Max_Limit)
  37.                     {
  38.                         Pistons[i].GetActionWithName("IncreaseUpperLimit").Apply(Pistons[i]);
  39.                         Active = true;
  40.                     }
  41.                     else if( Max_Limit < 10 || Extension < 10)  
  42.                     {  
  43.                         Active = true;  
  44.                     }
  45.                 }              
  46.             }            
  47.         }        
  48.         if(Active == true)
  49.         {
  50.             GoTimer();
  51.         }
  52.     }
  53.     if(Argument == "Stop" || Active == false)
  54.     {
  55.  
  56.         IMyTimerBlock Timer = GridTerminalSystem.GetBlockWithName(Go_Timer_Name) as IMyTimerBlock;    
  57.         Timer.GetActionWithName("Stop").Apply(Timer);
  58.          
  59.         IMyMotorStator Rotor = GridTerminalSystem.GetBlockWithName(Rotor_Name) as IMyMotorStator;    
  60.         Rotor.GetActionWithName("OnOff_Off").Apply(Rotor);  
  61.  
  62.         List<IMyShipDrill> Drills = new List<IMyShipDrill>();  
  63.         GridTerminalSystem.GetBlocksOfType<IMyShipDrill>(Drills);  
  64.         for( int d = 0; d<Drills.Count ; d++)  
  65.         {  
  66.             Drills[d].GetActionWithName("OnOff_Off").Apply(Drills[d]);  
  67.         }  
  68.          
  69.         for(int i = 0; i<Pistons.Count; i++)  
  70.         {  
  71.             if(Pistons[i].Velocity > 0.0)  
  72.             {  
  73.                 Pistons[i].GetActionWithName("DecreaseVelocity").Apply(Pistons[i]);  
  74.             }  
  75.             for(int x=0; x<20; x++)  
  76.             {  
  77.                 Pistons[i].GetActionWithName("DecreaseUpperLimit").Apply(Pistons[i]);  
  78.             }
  79.         }        
  80.     }
  81.    
  82. }
  83.  
  84. void GoTimer()
  85. {
  86.     IMyTimerBlock Timer = GridTerminalSystem.GetBlockWithName(Go_Timer_Name) as IMyTimerBlock;  
  87.     Timer.GetActionWithName("Start").Apply(Timer);
  88. }
Add Comment
Please, Sign In to add comment