Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Sherberts Warning Script
- /// Uses turrets with the tag in thier name to detect enemies, on enemy detection will trigger the timer block
- /// with timerLockName. Once it loses the enemy lock it triggers the Timer with the name matching timerNoLockName
- ///
- /// setup
- /// place turrets (oki targeters prefered with max range) on all sides of grid, Add the tag to the name. [warn] by default
- /// place 2 timer blocks and match thier names to the variables below, and setup thier actions to trigger your warning system
- /// Lights soundblocks whatever I dont care im righting this for kicks, do what you want.
- /// place a PB and add this program to it.
- ///
- /// </summary>
- string tag = "[warn]";
- string timerLockName = "Timer Locked";
- string timerNoLockName = "Timer NoLock";
- IMyTimerBlock timerLock;
- IMyTimerBlock timerNoLock;
- List<IMyTerminalBlock> turrets = new List<IMyTerminalBlock>();
- bool prevState = false;
- public Program()
- {
- timerLock = GridTerminalSystem.GetBlockWithName(timerLockName) as IMyTimerBlock;
- timerNoLock = GridTerminalSystem.GetBlockWithName(timerNoLockName) as IMyTimerBlock;
- if (timerLock == null || timerNoLock == null)
- Echo("Timer names are Invalid, Check Again");
- GridTerminalSystem.SearchBlocksOfName(tag, turrets);
- Runtime.UpdateFrequency = UpdateFrequency.Update100;
- timerNoLock.Trigger();
- }
- public void Main(string argument, UpdateType updateSource)
- {
- bool locked = false;
- foreach(var i in turrets)
- {
- IMyLargeTurretBase turret = i as IMyLargeTurretBase;
- if(turret.HasTarget)
- {
- locked = true;
- break;
- }
- }
- if(locked != prevState)
- {
- prevState = locked;
- if (locked)
- timerLock.Trigger();
- else
- timerNoLock.Trigger();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement