Whiplash141

Whip's Decoy Alternator

Oct 21st, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. /*
  2. Whip's Decoy Alternator v4 - 10/21/15
  3.  
  4. */
  5.  
  6. List<IMyTerminalBlock> decoys = new List<IMyTerminalBlock>();
  7. string decoyName = "Decoy";
  8. int currentTick = 1;
  9. int tickLimit = 15;
  10. int currentCount = 0;
  11. bool toggleOn = true; //default state of the alternator
  12. bool defaultOn = false; //change this if you want the decoys to default to on when not being alternated
  13.  
  14. void Main (string arg)
  15. {
  16.     switch(arg.ToLower())
  17.     {
  18.         case "on":
  19.             toggleOn = true;
  20.             break;
  21.          
  22.         case "off":
  23.             toggleOn = false;
  24.             break;
  25.              
  26.         case "toggle":
  27.             if (toggleOn)
  28.             {
  29.                 toggleOn = false;
  30.             }    
  31.             else
  32.             {
  33.                 toggleOn = true;
  34.             }
  35.             break;
  36.         default:
  37.             break;
  38.     }
  39.      
  40.     GridTerminalSystem.SearchBlocksOfName(decoyName,decoys);
  41.    
  42.      
  43.     if (currentTick % tickLimit == 0)
  44.     {
  45.         for (int i=0 ; i < decoys.Count ; i++)
  46.         {
  47.             var thisDecoy = decoys[i] as IMyTerminalBlock;
  48.             thisDecoy.ApplyAction("OnOff_Off");        
  49.             if (!toggleOn)
  50.             {
  51.                 if(defaultOn)
  52.                 {
  53.                     thisDecoy.ApplyAction("OnOff_On");
  54.                 }  
  55.             }
  56.         }
  57.        
  58.         if(currentCount < decoys.Count-1)
  59.         {
  60.             currentCount++;
  61.         }
  62.         else
  63.         {
  64.             currentCount = 0;
  65.         }
  66.        
  67.         currentTick = 0;
  68.         if(toggleOn)
  69.         {
  70.             decoys[currentCount].ApplyAction("OnOff_On");
  71.         }
  72.     }
  73.  
  74.     currentTick++;
  75.  
  76.     if(toggleOn)
  77.     {
  78.         Echo("--Alternator On--");
  79.     }
  80.     else
  81.     {
  82.         Echo("--Alternator Off--");
  83.     }
  84.    
  85.     Echo("Current Tick: " + currentTick);
  86.     Echo("Tick Limit: " + tickLimit);
  87.     Echo("No. Decoys: " + decoys.Count);
  88.     Echo("Current Decoy: " + (currentCount + 1));
  89. }
Advertisement
Add Comment
Please, Sign In to add comment