Skip to content

Instantly share code, notes, and snippets.

@untodesu
Created December 19, 2018 13:16
Show Gist options
  • Save untodesu/8679dad494aa26d18cd4e603f9ed60aa to your computer and use it in GitHub Desktop.
Save untodesu/8679dad494aa26d18cd4e603f9ed60aa to your computer and use it in GitHub Desktop.
Space Engineers BAGBA1 Main GATE Controller
/*
* The BAGBA1 Gate Controller Script
* Made by UND85D/undbsd
* Fully(I think) auto
*
* Main Part of BAGBA1 Controller System
*
* btw BAGBA = BBA
*/
string timerName;
int workTime = 30;
List<IMyProgrammableBlock> ringControllers;
List<IMySoundBlock> alarm; //Just all sound blocks
IMyTimerBlock timer;
bool init = false;
public Program()
{
timerName = "BBA.Timer";
ringControllers = new List<IMyProgrammableBlock>();
List<IMyProgrammableBlock> cntAll = new List<IMyProgrammableBlock>();
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyProgrammableBlock>(blocks);
cntAll = blocks.ConvertAll<IMyProgrammableBlock>(x => (IMyProgrammableBlock)x);
foreach(IMyProgrammableBlock controller in cntAll) {
if(controller.TryRun("bba_getInfo")) {
string[] info = controller.CustomData.Split(' ');
if(info.Length == 3) {
if(info[0] == "BAGBA" && info[1] == "ring") {
if(!ringControllers.Contains(controller)) {
ringControllers.Add(controller);
}
}
}
}
}
alarm = new List<IMySoundBlock>();
blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMySoundBlock>(blocks);
alarm = blocks.ConvertAll<IMySoundBlock>(x => (IMySoundBlock)x);
timer = GridTerminalSystem.GetBlockWithName(timerName) as IMyTimerBlock;
if(timer == null) {
throw new Exception("Cannot find timer");
}
timer.TriggerDelay = workTime;
}
public void Main(string arg)
{
switch(arg) {
case "Start": {
timer.StartCountdown();
foreach(IMySoundBlock snd in alarm) {
snd.LoopPeriod = workTime;
snd.Play();
}
foreach(IMyProgrammableBlock controller in ringControllers) {
controller.TryRun("bba_ringInit");
controller.TryRun("bba_ringStart");
}
break;
};
case "Stop": {
timer.StopCountdown();
foreach (IMySoundBlock snd in alarm) {
snd.Stop();
}
foreach (IMyProgrammableBlock controller in ringControllers) {
controller.TryRun("bba_ringInit");
controller.TryRun("bba_ringStop");
}
break;
};
}
}
public void Save()
{ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment