Ignoring throttle level control of main engines (Lua)

misha.physics

Well-known member
Joined
Dec 22, 2021
Messages
1,480
Reaction score
2,211
Points
128
Location
Lviv
Preferred Pronouns
he/him
Is there a way to disable (ignore) throttle level control of main engines on Lua? Is it possible to do on C++?

I have an airplane Lua script and I assigned a key for toggling propeller animation (together with custom engine sound), namely I am using a variable with true/false value. I would like the default keys for main engines (+/-,Ctrl +/Ctrl -) to be ignored when the propeller status is false.

For now, I have a script that reset main engine throttle to zero when I turn the propeller animation off, but I still can control throttle when the propeller animation is disabled.
 
What you can do is to 'force' the throttle to 0. Something like 'if inputThrottle > 0 then myThrottle = 0'.
 
Temporarily setting max thrust to "0" would at least disable the engines?
 
What you can do is to 'force' the throttle to 0. Something like 'if inputThrottle > 0 then myThrottle = 0'.
I tried to add to the function clbk_poststep() something like this:
Code:
if vi:get_thrustergrouplevel(THGROUP.MAIN) > 0 then
   vi:set_thrustergrouplevel(THGROUP.MAIN, 0)
end
And it works particularly, namely throttle is close to zero, but not exactly zero. Also, throttle is full when holding "+" key.
Temporarily setting max thrust to "0" would at least disable the engines?
I tried to plaece maxth0 = 0 in a condition, but is seems not to work, or I did it wrong.

Maybe we can block key action, namely pressing or/and holding "+", "-" on NumPad?
 
I don't know about Lua, but in C++ we have the DelThrusterGroup() function.

You can use it in an if conditional, so that when the condition is met (e.g. engineRunning = false) you can call DelThrusterGoup(nameofthrustergroup), and the ability to exert thrust with + is disabled.
 
clbk_poststep

Try with clbk_prestep(), it might work better for things such as input.

clbk_prestep() : is called before the simulation (step) is updated
clbk_postep() : is called after the simulation (step) is updated

I tried to plaece maxth0 = 0 in a condition, but is seems not to work, or I did it wrong.

I think to remember that setting max thrust to 0 doesn't work, because for a thruster to be a thruster it must obviously have some thrust (else the calculations the sim does make no sense). Even like 0,0001 N.

or I did it wrong.

You have to be sure of that. Be very liberal on oapiDebugString, and check everything you do.
 
I don't know about Lua, but in C++ we have the DelThrusterGroup() function.

You can use it in an if conditional, so that when the condition is met (e.g. engineRunning = false) you can call DelThrusterGoup(nameofthrustergroup), and the ability to exert thrust with + is disabled.
Yes, I just tried it a little before like:
Code:
function clbk_poststep(simt,simdt)
  if PropellerOn == true then

    main_engine = vi:create_thruster(main_thruster)
    main_engine_group = vi:create_thrustergroup({main_engine},THGROUP.MAIN)

    anim_propeller_level = (simt/T) % 1
    vi:set_animation(anim_propeller, anim_propeller_level)

    ThrottleLevel = vi:get_thrustergrouplevel(THGROUP.MAIN)
    vi:set_animation(ThrottleAnimation, ThrottleLevel)

  else

    vi:del_thrustergroup(THGROUP.MAIN)

    vi:set_animation(anim_propeller, 0)

    vi:set_animation(ThrottleAnimation, 0)

  end
It works good. But in this case my throttle animation in cockpit doesn't move at all. And the engine status shows zero in generic glass cockpit.
Try with clbk_prestep(), it might work better for things such as input.
I tried it too, but again I'm not sure if I did it correctly :(
 
Thanks to all. It looks now it works as I wanted. I need to think about it.
 
You could do what I do in my air-breathing engine models and make a dummy thruster group that takes the main engine throttle, and make another thruster that actually delivers the thrust:

Code:
th_dummy = vi:create_thruster({pos=rudder_pivot, dir={x=0, y=0, z=1}, maxth0=1, hprop=main_fuel_tank, isp0=math.huge})
thg_dummy = vi:create_thrustergroup({th_dummy}, THGROUP.MAIN)
th_actual = vi:create_thruster({pos=rudder_pivot, dir={x=0, y=0, z=1}, maxth0=actual_thrust, hprop=main_fuel_tank, isp0=actual_isp}

You can't define a thrust of 0, so I use 1 as that permits the main thrust indicator to work. The 1 Newton force is negligible, but if it is a problem you can just add a second dummy thruster to the group pointed in the opposite direction to cancel it out. Setting the isp0 to a large number ensures it doesn't use any fuel.

You can then just take the throttle level from the main engine group and use it to control the other thruster, or not, depending if you want it on or off.

Code:
throttle = vi:get_thrustergrouplevel(THGROUP.MAIN)

Code:
if engine_on then
    vi:set_thrusterlevel (th_actual, throttle)
elseif
    set_thrusterlevel (th_actual, 0)
end
 
Back
Top