Adjust options.lua file based on aircraft altitude above ground

Home > User Files > Adjust options.lua file based on aircraft altitude above ground
Alle Versionen
Sichten

Adjust options.lua file based on aircraft altitude above ground

Typ - Tool
Hochgeladen von - csbeau1969
Datum - 10.03.2024 05:23:54
AutoHotKey file which has the following function:
* Keeps DCS as the active window
* Adjustable altitude and sensitivity for swapping graphics setting (options.lua)
* Default is 5000 feet, and 4 consecutive readings above or below this altitude to change graphics options
* A few other keystrokes included to help manage options in VR, intended for use with VoiceAttack


You must download AutoHotKey (www.autohotkey.com, v2.0 and 1.1) for the script to work correctly; install v2.0 first and then 1.1 (which adds backward compatibility.)

Details are in this Mod post:
https://forum.dcs.world/topic/345129-dynamic-adjustment-of-lodmult-setting-based-on-mirrors-position-in-cockpit/#comment-5396064

-- Add this code to your existing Export.lua script

local outputFile = "C:\\Users\\YourUserName\\Saved Games\\DCS\\Config\\radarAltitude.txt"

function LuaExportAfterNextFrame()
    local radarAlt = LoGetAltitudeAboveGroundLevel()
    local altitudeString = string.format("%.2f", radarAlt)
    local file = io.open(outputFile, "w")
    file:write(altitudeString)
    file:close()
end

This is the script within the AutoHotKey file, which you can use/modify to create your own version of the script:

#NoEnv
#SingleInstance Force
#UseHook
SetTitleMatchMode, 2

optionsGroundPath := "C:\Users\chris\Saved Games\DCS\Config\options-ground.lua"
optionsAirPath := "C:\Users\chris\Saved Games\DCS\Config\options-air.lua"
optionsLuaPath := "C:\Users\chris\Saved Games\DCS\Config\options.lua"
radarAltitudeFile := "C:\Users\chris\Saved Games\DCS\Config\radarAltitude.txt"
altitudeThreshold := 1524.0 ; 5000 feet = 1524 meters

global currentGraphicsSettings := "ground"
global consistentReadings := 0
global requiredReadings := 4

; Reset the radarAltitude.txt file to zero
FileDelete, %radarAltitudeFile%
FileAppend, 0`n, %radarAltitudeFile%

SendKeyWithDelay(key) {
    Send %key%
    Sleep, 25
}

OpenCloseGraphicsSettings() {
    SendKeyWithDelay("{Esc}")
    Sleep, 50
    Loop, 10 {
        SendKeyWithDelay("{Down}")
    }
    Loop, 2 {
        SendKeyWithDelay("{Up}")
    }
    SendKeyWithDelay("{Space}")
    Sleep, 50
    SendKeyWithDelay("{Esc}")
    SendKeyWithDelay("{Esc}")
}

OpenGraphicsSettings() {
    SendKeyWithDelay("{Esc}")
    Sleep, 50
    Loop, 10 {
        SendKeyWithDelay("{Down}")
    }
    Loop, 2 {
        SendKeyWithDelay("{Up}")
    }
    SendKeyWithDelay("{Space}")
    Sleep, 50
}

ExitMission() {
    SendKeyWithDelay("{Esc}")
    Sleep, 50
    Loop, 10 {
        SendKeyWithDelay("{Down}")
    }
    Loop, 0 {
        SendKeyWithDelay("{Up}")
    }
    SendKeyWithDelay("{Space}")
    SendKeyWithDelay("{Space}")
    Sleep, 50
}

ExitGame() {
    SendKeyWithDelay("{Esc}")
    Sleep, 50
    Loop, 10 {
        SendKeyWithDelay("{Down}")
    }
    Loop, 1 {
        SendKeyWithDelay("{Up}")
    }
    SendKeyWithDelay("{Space}")
    SendKeyWithDelay("{Space}")
    Sleep, 50
}

; Set initial graphics settings to ground
FileCopy, %optionsGroundPath%, %optionsLuaPath%, 1

Loop
{
    if WinExist("ahk_exe DCS.exe")
    {
        FileRead, radarAltitude, %radarAltitudeFile%
        if ErrorLevel = 0
        {
            radarAltitude := RegExReplace(radarAltitude, "[^0-9.-]", "")
            radarAltitude := radarAltitude + 0.0

            if (radarAltitude > altitudeThreshold && currentGraphicsSettings != "air")
            {
                consistentReadings++
                if (consistentReadings >= requiredReadings)
                {
                    FileCopy, %optionsAirPath%, %optionsLuaPath%, 1
                    OpenCloseGraphicsSettings()
                    SoundBeep, 750, 150
                    currentGraphicsSettings := "air"
                    consistentReadings := 0
                }
            }
            else if (radarAltitude <= altitudeThreshold && currentGraphicsSettings != "ground")
            {
                consistentReadings++
                if (consistentReadings >= requiredReadings)
                {
                    FileCopy, %optionsGroundPath%, %optionsLuaPath%, 1
                    OpenCloseGraphicsSettings()
                    SoundBeep, 500, 150
                    currentGraphicsSettings := "ground"
                    consistentReadings := 0
                }
            }
            else
            {
                consistentReadings := 0
            }
        }
    }

    ; Hotkey to open the options menu
    if GetKeyState("LShift") && GetKeyState("LWin") && GetKeyState("O")
    {
        OpenGraphicsSettings()
    }

    ; Hotkey to exit the mission
    if GetKeyState("LAlt") && GetKeyState("LShift") && GetKeyState("LWin") && GetKeyState("E")
    {
        ExitMission()
    }

    ; Hotkey to exit the game
    if GetKeyState("LAlt") && GetKeyState("LShift") && GetKeyState("LWin") && GetKeyState("Q")
    {
        ExitGame()
    }

    Sleep, 250
}

ExitApp

You will need to adjust the export.lau addendum and AHK script (use NotePad++ or Notepad) to reflect your SavedGame directory location). See post in forum for more details.

The included zip includes examples of my Export.lua, the AutoHotKey script (KeepAppActiveLoop.ahk) and my options-air and options-ground.lua files). Note that my computer is a 13th gen i7 and an RTX 4090, so you may or may not want to use these settings. I primarily fly in VR and get 72-90 fps on the Quest Pro using these settings and the file swap. I also use the quad-foveated-rendering by mbucchia (google search and follow his wiki.)

Note: to exit the script, right-click the icon in the system tray icon area (far right) and sel ect exit or pause script. Pressing Ctrl & Space simultaneously will stop DCS fr om being the active window, so you can tab out, select another window, etc.

After exiting or pressing Ctrl & Space, you will want to re-run the script for it to keep DCS as the active window and swap graphics files based on altitude.
  • Lizenz: Freeware - Kostenlose Version, Freie Weitergabe
  • Sprache: Englisch
  • Größe: 10.95 Kb
  • Geladen: 19
  • Kommentare: 6
FOLLOW US