Intruder Detection No rating results yet

posted in: Control, Operations, Scripts | 1

This script can be used as intruder detection. To use it, you also need the companion script: Intruder Detection Reset.

Install each script on a programming block and set all of your intruder sensors to run this script on detect and the Intruder Detection Reset script on not detection.

To make this work, the following changes should be made to both of the scripts:

  1. Change the “lightsName” constant (line 1) to match the name of all the interior lights that you want the system to control (if you are using a naming convention to group your lights)
  2. If you are using actual groupings (within the interface), change the “lightGroupName” constant (line 2) to the name of the group that contains the lights you want the system to control
  3. You can only use option #1 or #2 above, not both
  4. If you selected option #1 above, change the “lightGroupOrName” constant (line 3) to “Name”
  5. If you selected option #2 above, change the “lightGroupOrName” constant (line 3) to “Group”
  6. Change the “turretsName” constant (line 5) to match the name of all the interior turrets that you want the system to control (if you are using a naming convention to group your turrets)
  7. If you are using actual groupings (within the interface), change the “turretGroupName” constant (line 6) to the name of the group that contains the turrets you want the system to control
  8. You can only use option #6 or #7 above, not both
  9. If you selected option #6 above, change the “turretGroupOrName” constant (line 3) to “Name”
  10. If you selected option #7 above, change the “turretGroupOrName” constant (line 3) to “Group”
  11. You can change the color of the lights when in “alert” mode by changing line 16.
  12. You can change the blink length and interval by changing lines 22 & 23. Please note that “Lenght” is spelled incorrectly on line 22. This is because the developers actually spelled it wrong in the API, so don’t “fix” it.

Don’t forget that you need to make similar changes to the other script: Intruder Detection Reset

  1. const String lightsName = "Interior Light";
  2. const String lightGroupName = "Intruder Lights";
  3. const String lightGroupOrName = "Group";
  4.  
  5. const String turretsName = "Interior Turret";
  6. const String turretGroupName = "Defensive Turrets";
  7. const String turretGroupOrName = "Group";
  8. void Main()      
  9. {  
  10.     List<IMyTerminalBlock> lights = new List<IMyTerminalBlock>();
  11.     if (lightGroupOrName.Equals("Group")) {
  12.         lights = getBlockGroup(GridTerminalSystem, lightGroupName);
  13.     } else {
  14.         GridTerminalSystem.SearchBlocksOfName(lightsName, lights);
  15.     }
  16.     Color red = new Color(255, 0, 0);
  17.     for (int i = 0; i < lights.Count; i++)  
  18.     {  
  19.         var l = (IMyInteriorLight)lights&#91;i];    
  20.         l.GetActionWithName("OnOff_Off").Apply(l);
  21.         l.SetValue("Color", red);
  22.         l.SetValue("Blink Lenght", 50.0f);
  23.         l.SetValue("Blink Interval", 1.0f);
  24.         l.GetActionWithName("OnOff_On").Apply(l);
  25.     }  
  26.     List<IMyTerminalBlock> turrets = new List<IMyTerminalBlock>();
  27.     if (turretGroupOrName.Equals("Group")) {
  28.         turrets = getBlockGroup(GridTerminalSystem, turretGroupName);
  29.     } else {
  30.         GridTerminalSystem.SearchBlocksOfName(turretsName, turrets);
  31.     }
  32.    
  33.     for (int i = 0; i < turrets.Count; i++)  
  34.     {  
  35.         var t = (IMyLargeTurretBase)turrets&#91;i];    
  36.         t.EnableIdleRotation = true;
  37.     }  
  38.  
  39. }
  40.  
  41. public static List<IMyTerminalBlock> getBlockGroup(IMyGridTerminalSystem searchGrid, String groupName) {        
  42.   for(int g=0; g<searchGrid.BlockGroups.Count; g++) {        
  43.     if( searchGrid.BlockGroups&#91;g].Name == groupName) {        
  44.       return searchGrid.BlockGroups&#91;g].Blocks;        
  45.     }          
  46.   }        
  47.   return new List<IMyTerminalBlock>();        
  48. }

Please rate this post

One Response

  1. […] Please see the companion script to this one for instructions on how to use it: Intruder Detection. […]

Leave a Reply