Advertisement
NickNDS

Turret Monitor

Jan 30th, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. public string
  2. timerDangerName = "alert",
  3. timerSafeName = "safe";
  4.  
  5. public bool active = false;
  6.  
  7. public Program()
  8. {
  9.     Runtime.UpdateFrequency = UpdateFrequency.Update100;
  10. }
  11.  
  12. public void Save() { }
  13.  
  14. public void Main(string argument, UpdateType updateSource)
  15. {
  16.     List<IMyTerminalBlock> blockList = new List<IMyTerminalBlock>();
  17.     GridTerminalSystem.GetBlocksOfType<IMyLargeTurretBase>(blockList, b => ((IMyLargeTurretBase)b).HasTarget);
  18.     bool tempActive = blockList.Count > 0;
  19.     if (tempActive != active)
  20.     {
  21.         active = tempActive;
  22.         if (active) TriggerTimers(timerDangerName);
  23.         else TriggerTimers(timerSafeName);
  24.     }
  25. }
  26.  
  27. public void TriggerTimers(string timerKeyword)
  28. {
  29.     List<IMyTerminalBlock> blockList = new List<IMyTerminalBlock>();
  30.     GridTerminalSystem.GetBlocksOfType<IMyTimerBlock>(blockList, b => b.CustomName.ToLower().Contains(timerKeyword.ToLower()));
  31.     for (int i = 0; i < blockList.Count; i++)
  32.         ((IMyTimerBlock)blockList[i]).Trigger();
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement