Advertisement
Meridius_IX

Altitude Timer Trigger 1.1

Jun 26th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 KB | None | 0 0
  1. //Meridius_IX's Altitude Timer Trigger V.1.1
  2.  
  3. //Script will trigger named timer once ship altitude is less than specified value.
  4.  
  5. string timer_name = "Timer Block"; //Must be exact name of timer block to trigger
  6. string cockpit_name = "Cockpit"; //Must be exact name of cockpit used for measuring altitude
  7. double altitudeTrigger = 500; //If Ship is lower than this altitude, Timer will Trigger
  8.  
  9. //////////////////////////////////////////////////////
  10. //Do Not Touch Anything Below Here
  11. //////////////////////////////////////////////////////
  12.  
  13. IMyShipController cockpit;
  14. IMyTimerBlock timer;
  15.  
  16. void Main(string argument){
  17.    
  18.     cockpit = null;
  19.     List<IMyTerminalBlock> cockpit_list = new List<IMyTerminalBlock>();
  20.     GridTerminalSystem.GetBlocksOfType<IMyShipController>(cockpit_list);
  21.     timer = GridTerminalSystem.GetBlockWithName(timer_name) as IMyTimerBlock;
  22.    
  23.     if(cockpit_list.Count != 0){
  24.        
  25.         for(int i = 0; i < cockpit_list.Count; i++){
  26.            
  27.             if(cockpit_list[i].IsFunctional == true && cockpit_list[i].CustomName == cockpit_name){
  28.                
  29.                 cockpit = cockpit_list[i] as IMyShipController;
  30.                 break;
  31.                
  32.             }
  33.            
  34.         }
  35.        
  36.     }
  37.    
  38.     if(cockpit == null){
  39.    
  40.         Echo("No Cockpit with name " + cockpit_name + " was found. Script Cannot Execute.");
  41.         return;
  42.    
  43.     }
  44.    
  45.     if(timer == null){
  46.    
  47.         Echo("No Timer Block with name " + timer_name + " was found. Script Cannot Execute.");
  48.         return;
  49.    
  50.     }
  51.    
  52.     double altitude = 0;
  53.     bool gotElevation = cockpit.TryGetPlanetElevation(MyPlanetElevation.Surface, out altitude);
  54.     if(altitude < altitudeTrigger && gotElevation == true){
  55.    
  56.         timer.ApplyAction("TriggerNow");
  57.    
  58.     }
  59.            
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement