Advertisement
NickNDS

Gravity Alarm

Dec 5th, 2020 (edited)
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. public string soundBlockKeyword = "gravity";
  2.  
  3. public bool inGravity = false;
  4. public List<IMyShipController> controllerList = new List<IMyShipController>();
  5. public List<IMySoundBlock> soundBlockList = new List<IMySoundBlock>();
  6.  
  7. public Program()
  8. {
  9.     Runtime.UpdateFrequency = UpdateFrequency.Update100;
  10. }
  11.  
  12. public void Main(string argument)
  13. {
  14.     if (argument.Length > 0)
  15.     {
  16.         Echo("Testing alarm");
  17.         SoundAlarm();
  18.     }
  19.     controllerList.Clear();
  20.     GridTerminalSystem.GetBlocksOfType<IMyShipController>(controllerList);
  21.     if (controllerList.Count > 0)
  22.     {
  23.         double gravity = controllerList[0].GetNaturalGravity().Length();
  24.         Echo($"Current Gravity: {(gravity / 9.81).ToString("N2")}%");
  25.         if (!inGravity && gravity > 0.0)
  26.         {
  27.             inGravity = true;
  28.             SoundAlarm();
  29.         }
  30.         else if (inGravity && gravity == 0.0)
  31.             inGravity = false;
  32.     }
  33. }
  34.  
  35. public void SoundAlarm()
  36. {
  37.     soundBlockList.Clear();
  38.     string lowerSoundKeyword = soundBlockKeyword.ToLower();
  39.     GridTerminalSystem.GetBlocksOfType<IMySoundBlock>(soundBlockList, b => b.CustomName.ToLower().Contains(lowerSoundKeyword));
  40.     for (int i = 0; i < soundBlockList.Count; i++)
  41.     {
  42.         if (soundBlockList[i].IsSoundSelected) soundBlockList[i].Play();
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement