avLuaDevice

See also

If you’re looking to implement a common system, such as animation & movement of a landing gear, please check our guides.

Represents a builtin device written in Lua, often used for cockpit avionics.

This file may contain any code you want, and will be executed with the appropriate DCS Lua API functions exposed:

Hooks

SetCommand(input_id, value)

Called whenever an input binding has been detected.

Parameters:
  • input_id (number) – The ID of the input, e.g. Joystick.CmsDown.

  • value (number) – The current value of the input.

CockpitEvent(name, value)

Called whenever an in-game event has been detected:

  • GroundPowerOn

  • GroundPowerOff

  • GroundAirOff

  • GroundAirOn

  • GroundAirFailure

  • GroundAirApplyOn

  • GroundAirApplyOff

  • GroundAirApplyFailure

  • WeaponRearmFirstStep

  • WeaponRearmComplete

  • WeaponRearmSingleStepComplete

  • UnlimitedWeaponStationRestore

  • WheelChocksOn

  • WheelChocksOff

  • Repair

  • ReloadDone

  • RefuelDone

  • cockpit_release

Parameters:
  • name (string) – The name of the event.

  • value (any (implicit)) – The value associated with the event.

GetSelf()

Constructs an innermost table of the device specified in device_init.lua.

Returns:

A table containing functions and data for the device.

Return type:

Device table

post_initialize()

Called upon starting a DCS mission.

update()

Called on an interval set by make_default_activity().

release()

Called when the mission reloads, player dies or otherwise leaves the aircraft. Can be used to clean up any resources that are not cleaned up automatically.


make_default_activity(seconds)

Sets the callsite execution interval for the script. The recommended value is 0.01, or 1/10th a millisecond.

Parameters:

seconds (number) – The amount of time in-between intervals.

Returns:

nil (implicit)

Functions

get_draw_aircraft_argument_value(number)

Gets the current value of an animation argument from the exterior EDM.

Returns:

The associated value.

Return type:

number

set_draw_aircraft_argument_value(number)

Sets a value to the specified animation argument for the exterior EDM.

Returns:

nil (implicit)

get_cockpit_draw_argument_value(number)

Gets the current value of an animation argument for the interior EDM.

Returns:

The associated value.

Return type:

number


show_param_handles_list(show_imgui)

Toggles an ImGui widget window on and off in-game.

Parameters:

show_imgui (boolean) – Should ImGui be shown in-game?

Returns:

?

dispatch_action(device_id, input_id, value)

Triggers an involuntary input with a desired value. Similar to performClickableAction(), this will only result in a SetCommand() call.

Parameters:
  • device_id (string) – The ID of the device to use.

  • input_id (number) – The ID of the input to use.

  • value (number) – The value to trigger the device input with.

Returns:

nil (implicit)

Prints string text in-game in the top right corner.

Returns:

nil (implicit)


get_base_data()

Gets sensor data all over the aircraft from in-game.

Returns:

A table with functions for different sensor values.

Return type:

BaseData table

BaseData

getAngleOfAttack()

Gets the current angle of attack.

Return type:

number

getAngleOfSlide()

Gets the current angle of slide.

Return type:

number

getBarometricAltitude()

Gets the current altitude in barometric unit.

Return type:

number

getCanopyPos()

Gets the current position of the canopy.

Return type:

number

getCanopyState()

Gets the current state of the canopy, e.g. damaged, open, closed.

Return type:

number (???)

getEngineLeftFuelConsumption()

Gets the current fuel consumption rate of the left engine.

Return type:

number

getEngineLeftRPM()

Gets the current RPM percentage of the left engine.

Return type:

number

getEngineLeftTemperatureBeforeTurbine()

Gets the current temperature of the left engine (in Celsius) before statrtup.

Return type:

number

getEngineRightFuelConsumption()

Gets the current fuel consumption rate of the right engine.

Return type:

number

getEngineRightRPM()

Gets the current RPM percentage of the right engine.

Return type:

number

getEngineRightTemperatureBeforeTurbine()

Gets the current temperature of the right engine (in Celsius) before statrtup.

Return type:

number

getFlapsPos()

Gets the current position of the flaps.

Return type:

number

getFlapsRetracted()

Gets the current position of the flaps underneath the retraction threshold, used for aircraft definitions that have multiple flap states.

Return type:

number

getHeading()

Gets the current relative heading in degrees. (not to be confused with getMagneticHeading())

Return type:

number

getHorizontalAcceleration()

Gets the current rate of horizontal acceleration, in meters per second.

Return type:

number

getIndicatedAirSpeed()

Gets the current in-air speed (IAS) in knots per second.

Return type:

number

getLandingGearHandlePos()

Gets the current position state of the landing gear handle, used for aircraft definitions that have multiple gear states.

Return type:

number

getLateralAcceleration()

Gets the current rate of lateral (side-by-side) acceleration, in meters per second.

Return type:

number

getLeftMainLandingGearDown()

Gets the current state of the left landing gear and checks if it is down.

Returns:

Truthy expression

Return type:

number

getLeftMainLandingGearUp()

Gets the current state of the left landing gear and checks if it is up.

Returns:

Truthy expression

Return type:

number

getMachNumber()

Gets the current mach number.

Return type:

number

getMagneticHeading()

Gets the current true (magnetic) heading in degrees.

Return type:

number

getNoseLandingGearDown()

Gets the current state of the nose landing gear and checks if it is down.

Returns:

Truthy expression

Return type:

number

getNoseLandingGearUp()

Gets the current state of the nose landing gear and checks if it is up.

Returns:

Truthy expression

Return type:

number

getPitch()

Gets the current pitch angle in degrees.

Return type:

number

getRadarAltitude()

Gets the current altitude via. radar in degrees.

Return type:

number

getRateOfPitch()

Gets the current rate of pitch in degrees per second.

Return type:

number

getRateOfRoll()

Gets the current rate of roll in degrees per second.

Return type:

number

getRateOfYaw()

Gets the current rate of yaw in degrees per seocnd.

Return type:

number

getRightMainLandingGearDown()

Gets the current state of the right landing gear and checks if it is down.

Returns:

Truthy expression

Return type:

number

getRightMainLandingGearUp()

Gets the current state of the right landing gear and checks if it is up.

Returns:

Truthy expression

Return type:

number

getRoll()

Gets the current roll/bank angle in degrees.

Return type:

number

getRudderPosition()

Gets the current vertical stabiliser(s)’ position in degrees.

Return type:

number

getSpeedBrakePos()

Gets the current position of the speedbrake, used for aircraft definitions with one defined.

Return type:

number


get_param_handle(name)

Gets the name of a defined parameter with a handler.

Parameters:

name (string) – The name of the parameter.

Returns:

A table with functions and data for handling.

Return type:

Handler table

Handler

Handlers are a special DCS construct made for controlling the state of parameters when conditions [2] are present.

set(number)

Sets the value of the parameter.

Returns:

nil (implicit)

get()

Gets the current parameter value.

Return type:

number

Device

A “device” in this context is the state of a process within a plugin. This includes the ability to add additional Lua table elements, as well as add event hooks with functions.

listen_command(input_id)

Checks and calls SetCommand() when a specified input profile binding has been detected.

Parameters:

input_id (number) – The ID of the input, e.g. Keys.PlaneGearDown.

Returns:

nil (implicit)

listen_event(name)

Checks and calls CockpitEvent() when an event has been detected.

Parameters:

name (string) – The name of the event.

Returns:

nil (implicit)


performClickableAction(input_id, value, ???)

Triggers an involuntary input with a desire value. This will lead to SetCommand() and/or CockpitEvent() called.

(Not to be confused with dispatch_action())

Parameters:
  • input_id (number) – The ID of the input to use.

  • value (number) – The value associated with the input.

  • ??? (boolean)