Whiplash141

Whip's Battery Toggle Script

Jun 17th, 2015
1,180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.75 KB | None | 0 0
  1. /*
  2. ==============================================
  3. Whip's Battery Recharge Toggler v3 - 12/23/15
  4. ==============================================
  5.  
  6. INSTRUCTIONS:
  7.     Enter the following into the programs argument then run it:
  8.    
  9.     <command>;<block name>
  10.    
  11.         <command> can be either "toggle", "recharge", or "discharge" (without quotes)
  12.         <bock name> is the name of the battery that you wish to mess with
  13.    
  14. EXAMPLES:
  15.     Say I wanted to make a battery named "Battery - Torpedo" recharge.
  16.     We would enter:
  17.         recharge;Battery - Torpedo
  18.        
  19.     if we want to discharge we would put:
  20.         discharge;Battery - Torpedo
  21.        
  22.     if we wanted to just toggle the current state we would put:
  23.         toggle;Battery - Torpedo
  24.  
  25. OTHER:        
  26.     Feel free to shoot me any questions
  27.     - Whiplash141 - https://steamcommunity.com/id/Whiplash141/
  28. */
  29.  
  30. /*
  31. ===================================
  32. Don't touch anything below this <3
  33. ===================================
  34. */
  35.  
  36. List<IMyTerminalBlock> torpB = new List<IMyTerminalBlock>();    
  37.  
  38. void Main(string cmd)
  39. {
  40.     string[] cmd_split = cmd.Split(';');
  41.      
  42.     if (cmd_split.Length > 1)
  43.     {
  44.         GridTerminalSystem.SearchBlocksOfName(cmd_split[1],torpB);  
  45.        
  46.         switch(cmd_split[0].ToLower())
  47.         {
  48.             case "toggle":
  49.                 BattsToggle();
  50.                 Echo("Toggling batteries with name: " + cmd_split[1]);
  51.                 break;
  52.            
  53.             case "recharge":
  54.                 BattsRecharge();
  55.                 Echo("Recharging batteries with name: " + cmd_split[1]);
  56.                 break;
  57.                
  58.             case "discharge":
  59.                 BattsDischarge();
  60.                 Echo("Discharging batteries with name: " + cmd_split[1]);
  61.                 break;
  62.                
  63.             case default:
  64.                 Echo("No valid command entered");
  65.                 break;
  66.         }
  67.     }
  68. }
  69.  
  70. void BattsToggle()
  71. {  
  72.     for(int j = 0; j < torpB.Count; j++)  
  73.     {  
  74.         if(torpB[j] is IMyBatteryBlock)
  75.         {
  76.             var torpBat = torpB[j] as IMyBatteryBlock;  
  77.             torpBat.GetActionWithName("Recharge").Apply(torpBat);
  78.         }
  79.     }  
  80. }  
  81.  
  82.  
  83. void BattsRecharge()
  84. {
  85.     for(int j = 0; j < torpB.Count; j++)  
  86.     {  
  87.         if(torpB[j] is IMyBatteryBlock)
  88.         {
  89.             var torpBat = torpB[j] as IMyBatteryBlock;  
  90.             torpBat.SetValue("Recharge", true);
  91.         }        
  92.     }  
  93. }
  94.  
  95. void BattsDischarge()
  96. {
  97.     for(int j = 0; j < torpB.Count; j++)  
  98.     {  
  99.         if(torpB[j] is IMyBatteryBlock)
  100.         {
  101.             var torpBat = torpB[j] as IMyBatteryBlock;  
  102.             torpBat.SetValue("Recharge", false);
  103.         }        
  104.     }  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment