Whiplash141

Whip's Battle Light Script v1

Mar 10th, 2016
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.25 KB | None | 0 0
  1. /*
  2. /// Whip's Battle Light Script v1 - revision 3/10/16 ///
  3.  
  4. /////INSTRUCTIONS/////
  5.      
  6. =====ARGUMENTS=====
  7.  
  8.     Run this program with the following arguments to do the described functions
  9.      
  10.     alarm on: switches light colors to alarm state
  11.     alarm off: switches light colors to default state
  12.     alarm toggle: toggles alarm state
  13.      
  14. =====NAMING=====
  15.  
  16.     Name alarm lights like the following:
  17.      
  18.         <your light name> <standard color> [Alarm] <alarm state>
  19.          
  20.         Accepted <colors>:
  21.             [Brown] and [Purple]
  22.              
  23.         Accepted <alarm states>:
  24.             [Off] and empty
  25.          
  26.     Examples: To make a light named "Swag Light 4" change its color from purple the alarm
  27.             state color you'd name it:
  28.                 Swag Light 4 [Purple] [Alarm]
  29.          
  30.             To make the alarm light turn off when in alarmed state you'd instead name it:
  31.                 Swag Light 4 [Purple] [Alarm] [Off]
  32.              
  33. /////NOTES/////
  34.  
  35. Script by Whiplash141 at the request of WTFFSwan :)
  36. */
  37.  
  38. //Name tag to denote all alarm lights
  39.     const string strAlarmTag = "[Alarm]";
  40.      
  41. //-----------------------------------------------------
  42. //pick one of these to put in the name of the light
  43.     const string strStandardColor1 = "[Purple]";
  44.     const string strStandardColor2 = "[Brown]";
  45. //-----------------------------------------------------
  46.      
  47.     const string strLightOff = "[Off]";     //only add this into the block name if you want to  
  48.                                                             //switch it off in alarm state
  49.  
  50. //make our colors
  51.     Color colorStandard1 = new Color( 29, 22, 35 ); //purple
  52.     Color colorStandard2 = new Color( 178, 131, 86 ); //brownish
  53.     Color colorAlarm = new Color( 200, 50, 50 );
  54.      
  55. //======================================
  56. //Don't touch anything below this!
  57. //======================================
  58.  
  59. bool alarmIsOn = false;
  60. List <IMyTerminalBlock> listAlarmLights = new List<IMyTerminalBlock>();
  61.  
  62.  
  63. void Main( string arg )
  64. {
  65.     Echo( "WMI Battle Light Script" );
  66.      
  67.     switch( arg.ToLower() )
  68.     {
  69.         case "alarm on":
  70.             alarmIsOn = true;
  71.             Echo( "Alarm state toggled on" );
  72.             break;
  73.              
  74.         case "alarm off":
  75.             alarmIsOn = false;
  76.             Echo( "Alarm state toggled off" );
  77.             break;
  78.              
  79.         case "alarm toggle":
  80.             if( alarmIsOn )
  81.             {
  82.                 alarmIsOn = false;
  83.                 Echo( "Alarm state toggled off" );
  84.             }else{
  85.                 alarmIsOn = true;
  86.                 Echo( "Alarm state toggled on" );
  87.             }
  88.             break;
  89.              
  90.         default:
  91.             Echo("No valid arguments detected, see top of code for accepted arguments");
  92.             break;
  93.     }
  94.      
  95. //get our alarm lights
  96.     GridTerminalSystem.SearchBlocksOfName( strAlarmTag, listAlarmLights, isLight );
  97.      
  98. //go through each light and apply colors
  99.     for( int i = 0; i < listAlarmLights.Count; i++ )
  100.     {
  101.         var thisLight = listAlarmLights[i] as IMyLightingBlock;
  102.         if( alarmIsOn )
  103.         {
  104.             if( !thisLight.CustomName.Contains( strLightOff ) )
  105.             {
  106.                 thisLight.SetValue( "Color", colorAlarm );
  107.             }else{
  108.                 if( thisLight.GetValue<bool>( "OnOff" ) == true )
  109.                 {
  110.                     thisLight.ApplyAction( "OnOff_Off" );
  111.                 }
  112.             }
  113.         }else{
  114.             if( thisLight.CustomName.Contains( strStandardColor1 ) )
  115.             {
  116.                 thisLight.SetValue( "Color", colorStandard1 );
  117.             }
  118.             else if( thisLight.CustomName.Contains( strStandardColor2 ) )
  119.             {
  120.                 thisLight.SetValue( "Color", colorStandard2 );
  121.             }
  122.              
  123.             if( thisLight.GetValue<bool>( "OnOff" ) == false )
  124.             {
  125.                 thisLight.ApplyAction( "OnOff_On" );
  126.             }
  127.         }
  128.     }
  129. }
  130.  
  131. bool isLight( IMyTerminalBlock block )
  132. {
  133.     var lightTest = block as IMyLightingBlock;
  134.     return lightTest != null;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment