Advertisement
Sherbert

Warning timer system

Jul 11th, 2020
1,070
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.31 KB | None | 0 0
  1.  
  2.         /// <summary>
  3.         /// Sherberts Warning Script
  4.         /// Uses turrets with the tag in thier name to detect enemies, on enemy detection will trigger the timer block
  5.         /// with timerLockName. Once it loses the enemy lock it triggers the Timer with the name matching timerNoLockName
  6.         ///
  7.         /// setup
  8.         /// place turrets (oki targeters prefered with max range) on all sides of grid, Add the tag to the name. [warn] by default
  9.         /// place 2 timer blocks and match thier names to the variables below, and setup thier actions to trigger your warning system
  10.         ///     Lights soundblocks whatever I dont care im righting this for kicks, do what you want.
  11.         /// place a PB and add this program to it.
  12.         ///
  13.         /// </summary>
  14.  
  15.  
  16.         string tag = "[warn]";
  17.         string timerLockName = "Timer Locked";
  18.         string timerNoLockName = "Timer NoLock";
  19.        
  20.         IMyTimerBlock timerLock;
  21.         IMyTimerBlock timerNoLock;
  22.  
  23.         List<IMyTerminalBlock> turrets = new List<IMyTerminalBlock>();
  24.  
  25.         bool prevState = false;
  26.  
  27.         public Program()
  28.         {
  29.             timerLock = GridTerminalSystem.GetBlockWithName(timerLockName) as IMyTimerBlock;
  30.             timerNoLock = GridTerminalSystem.GetBlockWithName(timerNoLockName) as IMyTimerBlock;
  31.             if (timerLock == null || timerNoLock == null)
  32.                 Echo("Timer names are Invalid, Check Again");
  33.  
  34.             GridTerminalSystem.SearchBlocksOfName(tag, turrets);
  35.  
  36.             Runtime.UpdateFrequency = UpdateFrequency.Update100;
  37.  
  38.             timerNoLock.Trigger();
  39.            
  40.         }
  41.                              
  42.         public void Main(string argument, UpdateType updateSource)
  43.         {
  44.             bool locked = false;
  45.            foreach(var i in turrets)
  46.             {
  47.                 IMyLargeTurretBase turret = i as IMyLargeTurretBase;
  48.  
  49.                 if(turret.HasTarget)
  50.                 {
  51.                     locked = true;
  52.                     break;
  53.                 }
  54.  
  55.             }
  56.  
  57.            if(locked != prevState)
  58.             {
  59.                 prevState = locked;
  60.                 if (locked)
  61.                     timerLock.Trigger();
  62.                 else
  63.                     timerNoLock.Trigger();
  64.             }
  65.        
  66.  
  67.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement