Jump to content

How does export.lua work ?


Recommended Posts

Hey guys, i'm looking for information about export.lua and how it works but so far i don't really understand. Right now i know you put kinda include another file that you create and then put your code here, but how do i really get datas ? i couldn't find any up to date and complete enough doc :(

 

Hope someone can help

Link to comment
Share on other sites

i couldn't find any up to date and complete enough doc :(

 

There is no single document that will teach you everything you need to know about Export.lua. You will have to piece together information from several sources and do some trial and error.

 

Start with the developer blog post that introduced Export.lua (it is no longer online, but the Internet Archive has you covered):

https://web.archive.org/web/20141130081345/http://www.digitalcombatsimulator.com/en/dev_journal/lua-export/

 

To learn the Lua programming language (DCS uses version 5.1):

https://www.lua.org/manual/5.1/

 

To make trial and error easier, you can use the Lua Console in my "DCS Witchcraft" project (link in my sig). Open the comments in the "WitchcraftExport.lua" file to set it up for the Export.lua environment.

 

To manipulate controls and get data out of the sim, you will need to understand how a clickable cockpit works internally. To learn more about the concepts of device IDs, command IDs, and argument numbers, refer to the Beginners Guide to DCS World Aircraft Mods (chapter 10 IIRC).

 

To find out which argument numbers, device IDs, and command IDs your aircraft uses, look at the files under "mods/aircraft/YOUR_ACFT/Cockpit/Scripts", especially "clickabledata.lua", "mainpanel_init.lua" and "devices.lua".

 

To visually understand cockpit arguments, use the ED Model Viewer. It allows you to load a cockpit model and manipulate cockpit arguments to see their effect on the model.

 

To see how it all fits together, it helps to read other people's Export.lua files, for example the ones from Helios or DCS-BIOS.

 

Finally, here's a very quick guide to clickable cockpits as I understand it:

  • A device is a controller that handles a certain subsystem, such as the ILS or the Altimeter. Each device is identified by a device ID. You can get the device object from Export.lua with the "GetDevice" function.
  • You can send commands to a device by using the "performClickableAction" method of the device object. It expects two parameters. The first one is a command, which is usually looks like "device_commands.Button1" in clickabledata.lua. That translates to 3000 + button number. The second one is an "argument". Exactly how that second parameter is interpreted depends on which switch we are talking about, but often it corresponds to a cockpit argument value.
  • Most gauges and instruments are attached directly to the 3D cockpit model. Every moving element (for example, a gauge needle) has an animation attached to it in 3DS Max. A "cockpit argument" (which is a floating point number somewhere between -1 and 1) controls which frame of the animation is shown. Cockpit arguments are numbered. For example, cockpit argument 404 in the A-10C controls the Master Caution indicator light. If its value is 0, the light is off, if its value is 1, the light is on.
    You can get the value of a cockpit argument from Export.lua with "GetDevice(0):get_argument_value(number)".
  • Some displays in the cockpit are drawn to seperate textures and then plastered onto the cockpit wall. They can be exported to another monitor by editing some Lua files and using MonitorSetup.lua. For some of those displays, the list_indication function can be used to get their text contents.

 

If you tell me what you want to accomplish with Export.lua, I may be able to provide some more specific advice.

  • Like 3
  • Thanks 2
Link to comment
Share on other sites

If you tell me what you want to accomplish with Export.lua, I may be able to provide some more specific advice.

 

Ok i did'nt see that when i first read it.

So i want to export data like position, altitude,speed,heading of every aircraft that the player can see with his F10 menu (maybe even datalink datas from awacs would be great)

 

Right now, after seeing the old page you linked me, i'm pretty sure i can only get datas about my aircraft..

Am i right ?

Link to comment
Share on other sites

In that case, forget everything I said about clickable cockpits and cockpit arguments, you don't need those. All you need is the LoGetWorldObjects function. In multiplayer, the allow_object_export server setting needs to be on (or your Export.lua has to run on the server).

 

I don't think that you can access any datalink from Export.lua.

 

You might want to look at the Export.lua file that TacView installs.

Link to comment
Share on other sites

Or maybe i can, just found this

LoGetObjectById() -- (args - 1 (number), results - 1 (table))	
Returned object table structure:	
{ 
Name = 
Type =	
Subtype =	
Country = 
Coalition = 
LatLongAlt = { Lat = , Long = , Alt = }	
Heading =	
}

Coupled with

LoGetWorldObjects() -- (args - 0, results - 1 (table of object tables))	

 

Could be what i'm looking for

 

EDIT:Woops, didn't see you answered. I'm gonna check about the datalink data, thanks for the hint i'll get back to you with the results of my research :)

Link to comment
Share on other sites

Ian;3078935']There is no single document that will teach you everything you need to know about Export.lua. You will have to piece together information from several sources and do some trial and error.

 

Start with the developer blog post that introduced Export.lua (it is no longer online, but the Internet Archive has you covered):

https://web.archive.org/web/20141130081345/http://www.digitalcombatsimulator.com/en/dev_journal/lua-export/

 

To learn the Lua programming language (DCS uses version 5.1):

https://www.lua.org/manual/5.1/

 

To make trial and error easier, you can use the Lua Console in my "DCS Witchcraft" project (link in my sig). Open the comments in the "WitchcraftExport.lua" file to set it up for the Export.lua environment.

 

To manipulate controls and get data out of the sim, you will need to understand how a clickable cockpit works internally. To learn more about the concepts of device IDs, command IDs, and argument numbers, refer to the Beginners Guide to DCS World Aircraft Mods (chapter 10 IIRC).

 

To find out which argument numbers, device IDs, and command IDs your aircraft uses, look at the files under "mods/aircraft/YOUR_ACFT/Cockpit/Scripts", especially "clickabledata.lua", "mainpanel_init.lua" and "devices.lua".

 

To visually understand cockpit arguments, use the ED Model Viewer. It allows you to load a cockpit model and manipulate cockpit arguments to see their effect on the model.

 

To see how it all fits together, it helps to read other people's Export.lua files, for example the ones from Helios or DCS-BIOS.

 

Finally, here's a very quick guide to clickable cockpits as I understand it:

  • A device is a controller that handles a certain subsystem, such as the ILS or the Altimeter. Each device is identified by a device ID. You can get the device object from Export.lua with the "GetDevice" function.
  • You can send commands to a device by using the "performClickableAction" method of the device object. It expects two parameters. The first one is a command, which is usually looks like "device_commands.Button1" in clickabledata.lua. That translates to 3000 + button number. The second one is an "argument". Exactly how that second parameter is interpreted depends on which switch we are talking about, but often it corresponds to a cockpit argument value.
  • Most gauges and instruments are attached directly to the 3D cockpit model. Every moving element (for example, a gauge needle) has an animation attached to it in 3DS Max. A "cockpit argument" (which is a floating point number somewhere between -1 and 1) controls which frame of the animation is shown. Cockpit arguments are numbered. For example, cockpit argument 404 in the A-10C controls the Master Caution indicator light. If its value is 0, the light is off, if its value is 1, the light is on.
    You can get the value of a cockpit argument from Export.lua with "GetDevice(0):get_argument_value(number)".
  • Some displays in the cockpit are drawn to seperate textures and then plastered onto the cockpit wall. They can be exported to another monitor by editing some Lua files and using MonitorSetup.lua. For some of those displays, the list_indication function can be used to get their text contents.

If you tell me what you want to accomplish with Export.lua, I may be able to provide some more specific advice.

 

 

 

Great primer Ian, Thanks.

A Co, 229th AHB, 1st Cav Div

ASUS Prime Z370-A MB, Intel Core i7 8700K 5.0GHz OC'd, RTX 3090, 32GB DDR4, 1TB SSD, Win 10

Samsung 65" 4K Curved Display (Oculus Rift occaisionally), Track IR5, VoiceAttack, Baur's BRD-N Cyclic base/Virpil T-50CM Grip, UH-1h Collective by Microhelis & OE-XAM Pedals. JetSeat & SimShaker for Aviators.

JUST CHOPPERS

 

Link to comment
Share on other sites

  • 5 years later...
  • 1 month later...

Hi everyone,
I am trying to extract data from DCS.
The following code works perfectly... when I'm on a mission with a single aircraft in "player" mode:

function LuaExportActivityNextEvent(t)
    local tNext = t
    if default_output_file then
        local o = LoGetWorldObjects()
            for k,v in pairs(o) do
                default_output_file:write(string.format(
                "%.0f,%f,%f,%f,%f\n", 
                t, v.LatLongAlt.Lat, v.LatLongAlt.Long, v.LatLongAlt.Alt, v.Heading))
            end
                
        local aircraftPitch, aircraftBank, aircraftYawTrue = LoGetADIPitchBankYaw()
        aircraftPitch = aircraftPitch * 57.3
        aircraftBank = aircraftBank * 57.3
        aircraftYawTrue = aircraftYawTrue * 57.3 -- true heading
        default_output_file:write(string.format("aircraftYawTrue : %.2f\n", aircraftYawTrue))
        local aircraftYawMagnetic = LoGetMagneticYaw()
        aircraftYawMagnetic = aircraftYawMagnetic * 57.3 -- magnetic heading
        default_output_file:write(string.format("aircraftYawMagnetic : %f\n", aircraftYawMagnetic))
        local aircraftHeading = aircraftYawMagnetic -- this cound be negative
        if aircraftHeading < 0 then aircraftHeading = aircraftHeading + 360 end -- removes the negative
        local magneticVariance = aircraftYawTrue - aircraftYawMagnetic -- works for all maps
        default_output_file:write(string.format("%f\n", magneticVariance))
    end
    tNext = tNext + 2.0
    return tNext
end

The result of the log file then is:

Quote

ProductName: DCS
FileVersion: 2.7.14.24228
ProductVersion: 2.7.14.24228
0,13.583144,144.917323,159.160400,5.870764
aircraftYawTrue : 336.39
aircraftYawMagnetic : 335.543659
0.851118
2,13.583144,144.917323,159.210886,5.870629
aircraftYawTrue : 336.39
aircraftYawMagnetic : 335.533210
0.853836
4,13.583144,144.917323,159.211199,5.870757
aircraftYawTrue : 336.39
aircraftYawMagnetic : 335.540565
0.853836

 

The problem : 

On the other hand, when I switch the aircraft to "client mode" (in the mission editor), then this code no longer works. Nomore output after "ProductVersion: 2.7.14.24228".

Specifically, the first part alone works, but the second part below no longer works.

Thus, the code below (with the second part commented) works, with an aircraft in ""client" mode:

function LuaExportActivityNextEvent(t)
    local tNext = t
    if default_output_file then
        local o = LoGetWorldObjects()
            for k,v in pairs(o) do
                default_output_file:write(string.format(
                "%.0f,%f,%f,%f,%f\n", 
                t, v.LatLongAlt.Lat, v.LatLongAlt.Long, v.LatLongAlt.Alt, v.Heading))
            end
                
        -- local aircraftPitch, aircraftBank, aircraftYawTrue = LoGetADIPitchBankYaw()
        -- aircraftPitch = aircraftPitch * 57.3
        -- aircraftBank = aircraftBank * 57.3
        -- aircraftYawTrue = aircraftYawTrue * 57.3 -- true heading
        -- default_output_file:write(string.format("aircraftYawTrue : %.2f\n", aircraftYawTrue))
        -- local aircraftYawMagnetic = LoGetMagneticYaw()
        -- aircraftYawMagnetic = aircraftYawMagnetic * 57.3 -- magnetic heading
        -- default_output_file:write(string.format("aircraftYawMagnetic : %f\n", aircraftYawMagnetic))
        -- local aircraftHeading = aircraftYawMagnetic -- this cound be negative
        -- if aircraftHeading < 0 then aircraftHeading = aircraftHeading + 360 end -- removes the negative
        -- local magneticVariance = aircraftYawTrue - aircraftYawMagnetic -- works for all maps
        -- default_output_file:write(string.format("%f\n", magneticVariance))
    end
    tNext = tNext + 2.0
    return tNext
end

The result of the log file then is:

Quote

ProductName: DCS
FileVersion: 2.7.14.24228
ProductVersion: 2.7.14.24228
2,13.584188,144.919707,159.424525,5.870680
4,13.584188,144.919707,159.424858,5.870774
6,13.584188,144.919707,159.424842,5.870721
8,13.584188,144.919707,159.424842,5.870741

 

I spent several hours trying to figure out where the problem could come from.
I specify that the problem persists even after having commented all the other lines of the export.lua file (the lines SRS, SIMSHAKER, DCS-ExportScript, ...)

A solution ?
An idea ?

 

EDIT : 

OK, finally by multiplying the tests, I understood: I had to launch my mission on a server (and not launch it locally mono-player). When the mission is really on a server, the data export works. (Except perhaps if the mission editor has forbidden it...)

 


Edited by Fasu
  • Like 1
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...