Jump to content
Sign in to follow this  
Zach Decou

Failures!!!

Recommended Posts

So far, the community here has made my dreams a success by giving me the tools to write plugin functions that work. Now I want to write functions that fail!

I did the following:

Write a function that watches ITT. If it exceeds n a one shot timer kicks off. After x amount of time, a function is called that starts an engine fire. Problem is my failure fails to fail. The timer works as I can write to any other non-failure dataref. So it would appear that theres more to failing a dataref than simply writing a 1 to it. 

I looked at the G-21A lua script to gain some insights. It's syntax conventions are different from what I have become accustomed to- heads nor tails. 

The function that is called by the timer looks like this:


dr_sim_engine_fail1 =xp.getDataref("sim/operation/failures/rel_engfir0")

function failengine()

xp.setFloat(dr_sim_engine_fail1, 1)

end

It's that simple. I can plug in any other non-failure dataref and write to it. 

Any thoughts?

Share this post


Link to post
Share on other sites

Zach,

Not sure that it matters, but try....

xp.setInt(dr_sim_engine_fail1, 1)

as the Dataref you're writing to is an Integer.

Jim

Share this post


Link to post
Share on other sites

Dice!

I figured it out. Now no one has any excuse to not have custom failures in their aircraft!

Here is my code. Use it!


--list some things you want to trigger failures

dr_sim_ITT_c = xp.getDataref("sim/flightmodel/engine/ENGN_ITT_c")

--list what failure datarefs you want to fail

dr_sim_engine_fail1 = xp.getDataref("sim/operation/failures/rel_engfir1")


function engineOverStress()
--build a timer that begins when the limit is reached, but is destroyed if the limit is no longer reached before the timer goes off
local timer_overStress = nil
local ITT = xp.getFloatV(dr_sim_ITT_c, 1, 2) --either of my engines in this case


--start an argument
if ITT >600 then
if (timer_overStress == nil) then
 timer_overStress = timer.newOneShot("failEngine", 15) --calls failEngine() in 15 seconds unless the pilot reduces ITT!

 end

elseif ITT <600 then
if (timer_overStress ~= nil) then 
 timer.stop(timer_overStress) --stops the timer when pilot corrects his erroneous ways
end
end
end


------

function failEngine()
--the dirty work...
xp.setInt(dr_sim_engine_fail1, 6) --thanks Jim!

--[[
Ok, here is what I had wrong:
The failure method used in X-Plane has 7 modes-

1. always working [0 in lua]
2. mean time until failure [1]
3. exact time until failure [2]
4. fail at exact speed KIAS [3]
5. fail at exact altitude AGL [4]
6. fail if CTRL f or JOY [5]
7. inoperative [6]
]]--

end

Now go forth and fail!

  • Upvote 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×