The following Lua script turns off the engines in a twin prop.
- Open the Lua Console.
- Create a new Lua script and call it engines_off
- A text editor should have opened with a blank Lua script file. Copy and paste the following into the text editor and then save the file:
if (getdref("sim/flightmodel/engine/ENGN_running[1]") == 1) then
sendcmd("sim/starters/shut_down_1")
end
if (getdref("sim/flightmodel/engine/ENGN_running[2]") == 1) then
sendcmd("sim/starters/shut_down_2")
end
-- Allow time for the Commands to complete before querying engine states
sleep(75)
setbvar("Bespoke Var 0", getdref("sim/flightmodel/engine/ENGN_running[1]") & getdref("sim/flightmodel/engine/ENGN_running[2]"))
If error messages appear when running the above script in the Lua console, then its likely that your text editor understands HTML and has accepted the HTML code used to build this web page as well as the text above. To fix, simply copy and paste the above Lua code into Notepad (which will strip away any HTML code) and then copy and paste the Lua code from Notepad over the top of your previous pasted Lua Code from step 3.
The "if (getdref( ...." statements read the state of the engine and if they are running (equal one), then the sendcmd functions are executed which turn the engines off (fuel cut and mags off)
The sleep function allows time for X-Plane to process the Events.
Finally the setbvar function sets the Bespoke variable Bespoke Var 0 to the state of both engines. The state uses a bitwise And operator (&) to determine if they are both on. E.g. both the getdref functions would have to return 1 for Bespoke Var 0 to equal 1 (ON), otherwise it will be set to 0 (OFF) since at least one of the engines is still running.
The Bespoke variable Bespoke Var 0 could then be assigned to Light Data within GIT so that state of the engine could be indicated on some GoFlight module. The Light Action should be set to ON and the Light Value should be set to 1.
If Bespoke variables are used for LED's or displays, it is recommend that you add the relevant code to global_aircraft.lua to get the current state of the switches or aircraft when the aircraft first loads. It only needs to run once and in the example above this would be:
setbvar("Bespoke Var 0", getdref("sim/flightmodel/engine/ENGN_running[1]") & getdref("sim/flightmodel/engine/ENGN_running[2]"))