1. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  2. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  3. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

Please help with DCS export lua

Discussion in 'Digital Combat Simulators (DCS)' started by gianlu320, Sep 24, 2019.

  1. gianlu320

    gianlu320 Member Gold Contributor

    Joined:
    Feb 9, 2018
    Messages:
    65
    Location:
    Crawley
    Balance:
    488Coins
    Ratings:
    +14 / 0 / -0
    Hello everybody

    I would need some help
    I've been using simtools for about one year now and let's say I know the basics of it.
    I am familiar with the game patching procedure via the export.lua file.
    Few months ago I bought the Simracingstudio SRS wind.
    If you are not familiar with it, it's a system that makes fans spin simulating wind.
    My goal is to have wind blowing when taxying when the canopy is open.
    This SRS wind patches DCS export.lua file similarly to simtools.
    My problem is....
    When I patch the Export.lua with simtools my motion platform works perfectly.
    When I patch the Export.lua with SRS wind app, the fans work perfectly and they react to airspeed increase as they are supposed to do.
    My problem is that when I create my export.lua that includes the code lines from simtools and SRS wind, things don't work properly.
    Here is my export.lua.
    On top there is simtools part and after that there is SRS wind part.
    On a note....
    If I put simtools lines on top nothing works, not the motion platform nor the fans.
    If I do the opposite, SRS wind on top and simtools after, the fans work but the motion platform doesn't work.
    Can anybody help?
    And sorry for my english


    ---------------------------------------------------------------------------------------------------
    -- Export plugin for SimTools V3
    -- Version 1.0
    -- Export start
    ---------------------------------------------------------------------------------------------------

    Myfunction =

    {
    Start=function(self)
    package.path = package.path..";.\\LuaSocket\\?.lua"
    package.cpath = package.cpath..";.\\LuaSocket\\?.dll"
    socket = require("socket")

    my_init = socket.protect(function()
    -- export telemetry to SimTools
    host1 = host1 or "127.0.0.1"
    port1 = port1 or 41230
    c = socket.udp ( )
    c:settimeout ( 0 )
    c:setpeername ( host1, port1 )
    -- c:send ( "Hello Wolrd!" )
    -- c1 = socket.try(socket.connect(host1, port1)) -- connect to the listener socket
    -- c1:setoption("tcp-nodelay",true) -- set immediate transmission mode
    -- c1:settimeout(.01)
    end)
    my_init()
    end,


    AfterNextFrame=function(self)

    local altRad = LoGetAltitudeAboveGroundLevel()
    local pitch, bank, yaw = LoGetADIPitchBankYaw()
    local accel = LoGetAccelerationUnits()


    -- reduce forces on ground
    -- if altRad < 3 then
    -- accel.x = accel.x * 0.25
    -- accel.y = accel.y * 0.25
    -- accel.z = accel.z * 0.25
    -- end

    my_send = socket.protect(function()
    if c then
    -- socket.try(c1:send(string.format("%.3f; %.3f; %.3f; %.3f; %.3f; %.3f;\n", pitch*1000.0, bank*1000.0, yaw*1000.0, accel.x*1000.0, accel.y*1000.0, accel.z*1000.0)))
    socket.try(c:send(string.format("%.4f; %.4f; %.4f; %.4f; %.4f; %.4f;\n", pitch, bank, yaw, accel.x, accel.y, accel.z)))

    end
    end)
    my_send()

    end,


    Stop=function(self)
    my_close = socket.protect(function()
    if c then
    c:close()
    end
    end)
    my_close()
    end
    }


    -- =============
    -- Overload
    -- =============

    -- Works once just before mission start.
    do
    local PrevLuaExportStart=LuaExportStart
    LuaExportStart=function()
    Myfunction:Start()
    if PrevLuaExportStart then
    PrevLuaExportStart()
    end
    end
    end

    -- Works just after every simulation frame.
    do
    local PrevLuaExportAfterNextFrame=LuaExportAfterNextFrame
    LuaExportAfterNextFrame=function()
    Myfunction:AfterNextFrame()
    if PrevLuaExportAfterNextFrame then
    PrevLuaExportAfterNextFrame()
    end
    end
    end

    -- Works once just after mission stop.
    do
    local PrevLuaExportStop=LuaExportStop
    LuaExportStop=function()
    Myfunction:Stop()
    if PrevLuaExportStop then
    PrevLuaExportStop()
    end
    end
    end

    -- This is the SimRacingStudio Export.lua Script for Digital Combat Simulator
    -- Please place this file in "C:\Users\YOUR_USER_NAME\Saved Games\DCS\Scripts\Export.lua

    -- Data export script for DCS, version 1.2.
    -- Copyright (C) 2006-2014, Eagle Dynamics.
    -- See http://www.lua.org for Lua script system info
    -- We recommend to use the LuaSocket addon (http://www.tecgraf.puc-rio.br/luasocket)
    -- to use standard network protocols in Lua scripts.
    -- LuaSocket 2.0 files (*.dll and *.lua) are supplied in the Scripts/LuaSocket folder
    -- and in the installation folder of the DCS.

    function LuaExportStart()
    package.path = package.path..";"..lfs.currentdir().."/LuaSocket/?.lua"
    package.cpath = package.cpath..";"..lfs.currentdir().."/LuaSocket/?.dll"
    socket = require("socket")
    host = "127.0.0.1"
    port = 9800
    c = socket.udp() -- socket.try(socket.connect(host, port)) -- connect to the listener socket
    -- c.settimeout(0)
    end

    function LuaExportBeforeNextFrame()
    local before = Nil
    end

    function LuaExportAfterNextFrame()
    local protocol = 1
    local engine = LoGetEngineInfo()
    local rpm = 0
    local ay = 0
    local az = 0
    local ax = 0
    local airSpeed = LoGetIndicatedAirSpeed() -- (args - 0, results - 1 (m/s))
    local trueAirSpeed = LoGetTrueAirSpeed() -- (args - 0, results - 1 (m/s))
    local acceleration = LoGetAccelerationUnits() -- (args - 0, results - table {x = Nx,y = NY,z = NZ} 1 (G))
    local pitch, bank, yaw = LoGetADIPitchBankYaw()


    if acceleration == nil then
    ay = 0
    az = 0
    ax = 0
    else
    ay = acceleration.y
    az = acceleration.z
    ax = acceleration.x
    end

    if engine == nil then
    rpm = 0
    else
    rpm = engine.RPM.left
    end

    socket.try(c:sendto(string.format("%.2f,%.2f,%.2f,%.5f,%.5f,%.5f,%.5f,%.5f,%.5f", protocol, rpm, trueAirSpeed, ax, ay, az, pitch, bank, yaw), host, port))
    end

    function LuaExportStop()
    c:close()
    end

    function LuaExportActivityNextEvent(t)
    local tNext = t
    return tNext
    end
  2. Ads Master

    Ads Master

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
  3. Dirty

    Dirty Well-Known Member Gold Contributor

    Joined:
    Oct 15, 2017
    Messages:
    471
    Occupation:
    All the way up front.
    Location:
    Germany
    Balance:
    5,184Coins
    Ratings:
    +582 / 1 / -0
    Hey :)

    I am by no means an expert on Lua, but if you simply copy those two files into one, you will run into problems unless you copy every line to the correct place and then remove redundant lines.

    Option 1:
    Use the SRS file as master and try to incorporate the content of the plugin export scrip into it. In the SRS script you have there are five functions:

    function LuaExportStart()
    function LuaExportBeforeNextFrame()
    function LuaExportAfterNextFrame()
    function LuaExportStop()
    function LuaExportActivityNextEvent(t)

    ...while in the plugin script you have only three.
    Start=function(self)
    AfterNextFrame=function(self)
    Stop=function(self)

    see here:
    Screenshot 2020-10-08 at 16.32.36.png

    Now put the content of...
    Start=function(self) --> LuaExportStart()
    AfterNextFrame=function(self)
    --> function LuaExportAfterNextFrame()
    Stop=function(self)
    --> function LuaExportStop()

    ...and then see if there are redundant lines. With a little bit of Lua this is easy, but if you have never programmed at all before, it will be almost certain to go wrong somewhere.

    Option 2:
    @value1 changes his script so that it uses the callbacks from within the hooks folder. I'd do it myself, but I won't find the time to do that for at least another few weeks.

    Option3:
    You can use the script that I use for my plugin. It should still work with the original. I have added an option to use Eulerangles in the script for those who want to use those like in the original plugin. If you copy the script into SavedGames/DCS/Scripts/Hooks (create that folder if it does not exist yet) you will get all the functionality without interfering with other scripts. In fact this scenario was exactly the reason I started using the Hooks folder for my own plugin.

    This is the script:
    Code:
    ---------------------------------------------------------------------------------------------------
    -- Data export script for SimTools V2.4
    -- Version 0.09
    -- created by @Dirty, find me here: https://www.xsimulator.net/community/members/dirty.27556/
    -- Discussions here: https://www.xsimulator.net/community/threads/experimental-dcs-plugin-ready-for-testing.13560/
    --
    -- Changes:
    -- GameVibe & DashBoard support
    ---------------------------------------------------------------------------------------------------
    version = "v0.09"
    
    --Don't change theses values!!!
    r2d = 57.295779513082323        --converts Rad into Degrees
    m2k = 1.94384                    --converts m/s into Knots
    
    --Change those accordigng to your preference
    YouPreferDegreesOverRadians = true
    YouPreferKnotsOverMetersPerSecond = true
    YouAbsolutelyInsistOnUsingEulerAnglesOnYawEvenThoughThatMakesNoFuckinSense = false
    YouAbsolutelyInsistOnUsingEulerAnglesOnPitchEvenThoughThatMakesNoFuckinSense = false
    YouAbsolutelyInsistOnUsingEulerAnglesOnRollEvenThoughThatMakesNoFuckinSense = false
    
    --The callbacks to be registered with DCS
    local SimTools_Callbacks = {}
    
    function SimTools_Callbacks.onSimulationStart()
    
        log.write('SimTools', log.INFO, "Starting motion data export. Export script " .. version)
       
        package.path = package.path..";.\\LuaSocket\\?.lua"
        package.cpath = package.cpath..";.\\LuaSocket\\?.dll"
        socket = require("socket")
    
        IP = "127.0.0.1"
        Port = 41230
        MySocket = socket.udp ( )
        MySocket:settimeout ( 0 )
        MySocket:setpeername ( IP, Port )
    end
    
    function SimTools_Callbacks.onSimulationFrame()
    
        --Accelerations:
        accel = Export.LoGetAccelerationUnits()
            accel_longitudinal    = accel.x
            accel_vertical        = accel.y
            accel_lateral        = accel.z
           
        --Euler Angles:
        pitch, bank, yaw = Export.LoGetADIPitchBankYaw()
    
        --Angular rates:
        omega = Export.LoGetAngularVelocity()
            omega_longitudinal    = omega.x
            omega_vertical        = omega.y
            omega_lateral        = omega.z
    
    
    
        --Weight On Wheels?
        LeftGear = Export.LoGetAircraftDrawArgumentValue(6)
        NoseGear = Export.LoGetAircraftDrawArgumentValue(1)
        RightGear = Export.LoGetAircraftDrawArgumentValue(4)
       
        --OnGround status is determined by the compression of ANY gear strut
        if (LeftGear > 0 or NoseGear > 0 or RightGear > 0)
            then
                OnGround = 1
            else
                OnGround = 0
        end
    
        --Groundspeed:
        vv = Export.LoGetVectorVelocity()
        GS = math.sqrt( math.pow(vv.x,2) + math.pow(vv.z,2))
       
        --Air Data
        AOA = Export.LoGetAngleOfAttack()
        IAS = Export.LoGetIndicatedAirSpeed()
    
        if (YouPreferKnotsOverMetersPerSecond) then
            IAS = IAS * m2k
        end
    
       
        --Euler angles? Anyone?
        if (YouAbsolutelyInsistOnUsingEulerAnglesOnYawEvenThoughThatMakesNoFuckinSense == true) then
            Yaw_Output = yaw
        else
            Yaw_Output = omega_vertical
        end
           
           
        if (YouAbsolutelyInsistOnUsingEulerAnglesOnPitchEvenThoughThatMakesNoFuckinSense == true) then
            Pitch_Output = pitch
        else
            Pitch_Output = omega_lateral
        end  
       
       
        if (YouAbsolutelyInsistOnUsingEulerAnglesOnRollEvenThoughThatMakesNoFuckinSense == true) then
            Roll_Output = bank
        else
            Roll_Output = omega_longitudinal
        end  
       
       
        --Any unit conversions necessary?
        if (YouPreferDegreesOverRadians) then
            Roll_Output            = Roll_Output            * r2d
            Yaw_Output            = Yaw_Output            * r2d
            Pitch_Output        = Pitch_Output            * r2d
        end
       
        --Change exported values when on ground (optional)
        if (OnGround == 1) then
            accel_longitudinal    = accel_longitudinal    * 1.00
            accel_vertical        = accel_vertical        * 1.00
            accel_lateral        = accel_lateral            * 1.00
            Roll_Output            = Roll_Output            * 1.00
            Yaw_Output            = Yaw_Output            * 1.00
            Pitch_Output        = Pitch_Output            * 1.00
        end  
    
    
        --Put data to be exported into these slots. You can put any data you like in there :-)
        --GameEngine:
        local slot_GE_01 = Roll_Output
        local slot_GE_02 = Yaw_Output
        local slot_GE_03 = Pitch_Output
        local slot_GE_04 = accel_longitudinal
        local slot_GE_05 = accel_vertical
        local slot_GE_06 = accel_lateral
        local slot_GE_07 = 0
        local slot_GE_08 = 0
        local slot_GE_09 = 0
        --GameVibe:
        local slot_GV_01 = 0
        local slot_GV_02 = 0
        local slot_GV_03 = 0
        local slot_GV_04 = 0
        local slot_GV_05 = 0
        local slot_GV_06 = 0
        local slot_GV_07 = 0
        local slot_GV_08 = 0
        --GameDash:
        local slot_GD_01 = 0
        local slot_GD_02 = 0
        local slot_GD_03 = 0
        local slot_GD_04 = 0
        local slot_GD_05 = 0
        local slot_GD_06 = 0
        local slot_GD_07 = 0
        local slot_GD_08 = 0
        local slot_GD_09 = 0
        local slot_GD_10 = 0
        local slot_GD_11 = 0
        local slot_GD_12 = 0
        local slot_GD_13 = 0
        local slot_GD_14 = 0
        local slot_GD_15 = 0
        local slot_GD_16 = 0
        local slot_GD_17 = 0
        local slot_GD_18 = 0
        local slot_GD_19 = 0
        local slot_GD_20 = 0
       
        --Send data via UDP
        if MySocket then
        --                                Slots:      GE01  GE02  GE03  GE04  GE05  GE06  GE07  GE08  GE09  GV01  GV02  GV03  GV04  GV05  GV06  GV07  GV08  GD01  GD02  GD03  GD04  GD05  GD06  GD07  GD08  GD09  GD10  GD11  GD12  GD13  GD14  GD15  GD16  GD17  GD18  GD19  GD20
            socket.try(MySocket:send(string.format("%.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; %.4f; \n",
                                                    slot_GE_01,
                                                    slot_GE_02,
                                                    slot_GE_03,
                                                    slot_GE_04,
                                                    slot_GE_05,
                                                    slot_GE_06,
                                                    slot_GE_07,
                                                    slot_GE_08,
                                                    slot_GE_09,
                                                    slot_GV_01,
                                                    slot_GV_02,
                                                    slot_GV_03,
                                                    slot_GV_04,
                                                    slot_GV_05,
                                                    slot_GV_06,
                                                    slot_GV_07,
                                                    slot_GV_08,
                                                    slot_GD_01,
                                                    slot_GD_02,
                                                    slot_GD_03,
                                                    slot_GD_04,
                                                    slot_GD_05,
                                                    slot_GD_06,
                                                    slot_GD_07,
                                                    slot_GD_08,
                                                    slot_GD_09,
                                                    slot_GD_10,
                                                    slot_GD_11,
                                                    slot_GD_12,
                                                    slot_GD_13,
                                                    slot_GD_14,
                                                    slot_GD_15,
                                                    slot_GD_16,
                                                    slot_GD_17,
                                                    slot_GD_18,
                                                    slot_GD_19,
                                                    slot_GD_20
                                                    )))
        end
    end
    
    function SimTools_Callbacks.onSimulationStop()
       
        log.write('SimTools', log.INFO, "Motion data export stopped")
    
        if MySocket then
            MySocket:close()
        end
    end
    
    --register these callbacks with DCS to be called at the appropriate moment.
    DCS.setUserCallbacks(SimTools_Callbacks)
    
    
    
    
    ------------------------------------------------------------------------------------
    -----------------------------   HELPER FUNCTIONS   ---------------------------------
    ------------------------------------------------------------------------------------
    
    
    function WheelSpin()
        if (OnGround == 1)
            then
                return GS
            else
                return 0
        end  
       
    end
    
    function Windiness()
        return IAS        --I'm sure someone will be able to come up with an even more sophisticated formula :-)
    end
    I haven't tested it, but I think it should work right out of the box.

    Dirty :)
    • Useful Useful x 1