Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Set each of these 4 tags to the apropriate blocks in the menu
- // Select the looping sound you wish to use for the reverse warning (in the block)
- //
- // If things arent working right set DEBUG to true then recompile.
- //
- public string CockpitTag = "[Seat]";
- public string BrakeLightTag = "[Brake]";
- public string ReverseLightTag = "[Reverse]";
- public string ReverseSoundBlockTag = "[Warning]";
- public bool DEBUG = false;
- public IMyCockpit cockpit = null;
- public IMyRemoteControl altCockpit = null;
- public List<IMyTerminalBlock> brakeLights = null;
- public List<IMyTerminalBlock> reverseLights = null;
- public IMySoundBlock warning = null;
- public bool brake = false;
- public bool brakeSet = false;
- public bool reverse = false;
- public bool reverseSet = false;
- public Program()
- {
- Runtime.UpdateFrequency = UpdateFrequency.Update1;
- List<IMyTerminalBlock> temp = new List<IMyTerminalBlock>();
- GridTerminalSystem.SearchBlocksOfName(CockpitTag, temp);
- foreach (var tb in temp)
- {
- if (tb.GetType().ToString() == "Sandbox.Game.Entities.MyCockpit")
- {
- cockpit = (IMyCockpit)tb;
- break;
- }
- if (tb.GetType().ToString() == "Sandbox.Game.Entities.MyRemoteControl")
- {
- altCockpit = (IMyRemoteControl)tb;
- break;
- }
- }
- temp.Clear();
- GridTerminalSystem.SearchBlocksOfName(ReverseSoundBlockTag, temp);
- foreach (var tb in temp)
- {
- try
- {
- warning = (IMySoundBlock)tb;
- break;
- }
- catch (InvalidCastException e)
- {
- }
- }
- temp.Clear();
- if (warning != null)
- {
- warning.LoopPeriod = 1800f;
- }
- brakeLights = new List<IMyTerminalBlock>();
- reverseLights = new List<IMyTerminalBlock>();
- GridTerminalSystem.SearchBlocksOfName(BrakeLightTag, brakeLights);
- GridTerminalSystem.SearchBlocksOfName(ReverseLightTag, reverseLights);
- debug("=DEBUG MODE=");
- debug((cockpit != null) ? "Controled through cockpit." : "Controled through control block.");
- debug(string.Format("Found {0} brake lights.", brakeLights.Count));
- debug(string.Format("Found {0} reverse lights.", reverseLights.Count));
- debug((warning != null) ? "Found the sound block." : "No sound block found.");
- }
- public void Main(string arg)
- {
- if (cockpit != null)
- {
- if (cockpit.MoveIndicator.Y > .2f)
- {
- brake = true;
- }
- else
- {
- brake = false;
- }
- if (cockpit.MoveIndicator.Z > .2f)
- {
- reverse = true;
- }
- else
- {
- reverse = false;
- }
- }
- else if (altCockpit != null)
- {
- if (altCockpit.MoveIndicator.Y > .2f)
- {
- brake = true;
- }
- else
- {
- brake = false;
- }
- if (altCockpit.MoveIndicator.Z > .2f)
- {
- reverse = true;
- }
- else
- {
- reverse = false;
- }
- }
- if (brake && !brakeSet)
- {
- brakeSet = true;
- foreach (IMyTerminalBlock light in brakeLights)
- {
- if (light != null)
- {
- if (light.HasAction("OnOff_On"))
- {
- light.ApplyAction("OnOff_On");
- }
- }
- }
- }
- if (!brake && brakeSet)
- {
- brakeSet = false;
- foreach (IMyTerminalBlock light in brakeLights)
- {
- if (light != null)
- {
- if (light.HasAction("OnOff_Off"))
- {
- light.ApplyAction("OnOff_Off");
- }
- }
- }
- }
- if (reverse && !reverseSet)
- {
- reverseSet = true;
- if (warning != null)
- {
- warning.Play();
- }
- foreach (IMyTerminalBlock light in reverseLights)
- {
- if (light != null)
- {
- if (light.HasAction("OnOff_On"))
- {
- light.ApplyAction("OnOff_On");
- }
- }
- }
- }
- if (!reverse && reverseSet)
- {
- reverseSet = false;
- if (warning != null)
- {
- warning.Stop();
- }
- foreach (IMyTerminalBlock light in reverseLights)
- {
- if (light != null)
- {
- if (light.HasAction("OnOff_Off"))
- {
- light.ApplyAction("OnOff_Off");
- }
- }
- }
- }
- }
- void debug(string s)
- {
- if (DEBUG)
- {
- Echo(s);
- }
- }
- // Written by etopsirhc
Advertisement
Add Comment
Please, Sign In to add comment