Jump to content

DCS-BIOS v0.10.0 "Hub Scripts" example


FSFIan

Recommended Posts

Here is the script that I have been running over the last week or so to test the new "Hub Scripts" feature. It implements the following:

 

  • Makes my Harrier UFC, ODU and MPCD panels work in the Hornet (Harrier TMR = Hornet A/P, Harrier ALT = Hornet D/L)
  • In the Harrier, whenever the UFC would be blank otherwise, it displays the status of the AFC and ALT HOLD switches and allows to toggle them via the option select buttons. You can also enter or leave this display mode by pressing the (non-functional in DCS) "I/P" button on a physical Harrier panel.

 

How to use:

 

  • Save anywhere on your hard drive with a .lua extension (e.g. My Documents/remap.lua)
  • Shift+Right Click the file in Windows Explorer and choose "Copy as path"
  • Use the new "Hook Scripts" section on the Dashboard in the web interface to add the path to the script
  • Click the "Reload Scripts" button

 

If you want to play around with your own hub scripts: unfortunately, at the moment there is no way to view the output of Lua's print() function yet. The best way to debug your scripts is to use the Lua Console and select the "hub" environment (see the documentation on how to use enterEnv() to execute Lua code in the environment of your script).

 

Here is the code:

 

acftName = "NONE"

local setPanelString = hub.setPanelString
local getSimString = hub.getSimString

function remapOutput(a, b)
   setPanelString(b, getSimString(a))
end

function remapExportData()
   acftName = getSimString("MetadataStart/_ACFT_NAME")
   if acftName == "AV8BNA" then

   end
   if acftName == "FA-18C_hornet" then
       remapOutput("FA-18C_hornet/UFC_COMM1_DISPLAY", "AV8BNA/UFC_COMM1_DISPLAY")
       remapOutput("FA-18C_hornet/UFC_COMM2_DISPLAY", "AV8BNA/UFC_COMM2_DISPLAY")
       local scratchpad = getSimString("FA-18C_hornet/UFC_SCRATCHPAD_STRING_1_DISPLAY")
       scratchpad = scratchpad .. getSimString("FA-18C_hornet/UFC_SCRATCHPAD_STRING_2_DISPLAY")
       scratchpad = scratchpad .. getSimString("FA-18C_hornet/UFC_SCRATCHPAD_NUMBER_DISPLAY")
       setPanelString("AV8BNA/UFC_SCRATCHPAD", scratchpad)

       remapOutput("FA-18C_hornet/UFC_OPTION_CUEING_1", "AV8BNA/AV8BNA_ODU_1_SELECT")
       remapOutput("FA-18C_hornet/UFC_OPTION_DISPLAY_1", "AV8BNA/AV8BNA_ODU_1_Text")
       remapOutput("FA-18C_hornet/UFC_OPTION_CUEING_2", "AV8BNA/AV8BNA_ODU_2_SELECT")
       remapOutput("FA-18C_hornet/UFC_OPTION_DISPLAY_2", "AV8BNA/AV8BNA_ODU_2_Text")
       remapOutput("FA-18C_hornet/UFC_OPTION_CUEING_3", "AV8BNA/AV8BNA_ODU_3_SELECT")
       remapOutput("FA-18C_hornet/UFC_OPTION_DISPLAY_3", "AV8BNA/AV8BNA_ODU_3_Text")
       remapOutput("FA-18C_hornet/UFC_OPTION_CUEING_4", "AV8BNA/AV8BNA_ODU_4_SELECT")
       remapOutput("FA-18C_hornet/UFC_OPTION_DISPLAY_4", "AV8BNA/AV8BNA_ODU_4_Text")
       remapOutput("FA-18C_hornet/UFC_OPTION_CUEING_5", "AV8BNA/AV8BNA_ODU_5_SELECT")
       remapOutput("FA-18C_hornet/UFC_OPTION_DISPLAY_5", "AV8BNA/AV8BNA_ODU_5_Text")
   end
end
hub.registerOutputCallback(remapExportData)

inputMap = {
   ["FA-18C_hornet"] = {
       ["UFC_B1"] = "UFC_1",
       ["UFC_B2"] = "UFC_2",
       ["UFC_B3"] = "UFC_3",
       ["UFC_B4"] = "UFC_4",
       ["UFC_B5"] = "UFC_5",
       ["UFC_B6"] = "UFC_6",
       ["UFC_B7"] = "UFC_7",
       ["UFC_B8"] = "UFC_8",
       ["UFC_B9"] = "UFC_9",
       ["UFC_B0"] = "UFC_0",
       ["UFC_COM1_SEL"] = "UFC_COMM1_CHANNEL_SELECT",
       ["UFC_COM2_SEL"] = "UFC_COMM2_CHANNEL_SELECT",
       ["UFC_CLEAR"] = "UFC_CLR",
       ["UFC_ENTER"] = "UFC_ENT",
       ["UFC_TIMER"] = "UFC_AP",
       ["UFC_IFF"] = "UFC_IFF",
       ["UFC_TACAN"] = "UFC_TCN",
       ["UFC_WEATHER"] = "UFC_ILS",
       ["UFC_ALT"] = "UFC_DL",
       ["UFC_BEACON"] = "UFC_BCN",
       ["UFC_ONOFF"] = "UFC_ONOFF",
       ["UFC_COM1_VOL"] = "UFC_COMM1_VOL",
       ["UFC_COM2_VOL"] = "UFC_COMM2_VOL",
	["UFC_COM1_PULL"] = "UFC_COMM1_PULL",
	["UFC_COM2_PULL"] = "UFC_COMM2_PULL",
       ["UFC_BRIGHT"] = "UFC_BRT",
       ["UFC_EMCOM"] = "UFC_EMCON",


       ["ODU_OPT1"] = "UFC_OS1",
       ["ODU_OPT2"] = "UFC_OS2",
       ["ODU_OPT3"] = "UFC_OS3",
       ["ODU_OPT4"] = "UFC_OS4",
       ["ODU_OPT5"] = "UFC_OS5",
   }
}

local resetCrsSwitchCountdown = -1
hub.registerOutputCallback(function()
if resetCrsSwitchCountdown > 0 then
	resetCrsSwitchCountdown = resetCrsSwitchCountdown - 1
	if resetCrsSwitchCountdown == 0 then
		hub.sendSimCommand("LEFT_DDI_CRS_SW", "1")
		resetCrsSwitchCountdown = -1
	end
end
end)

function remapCommand(cmd, arg)
   mapping = inputMap[acftName]
   if mapping == nil then return cmd, arg end
   replacementCmd = mapping[cmd]
   if replacementCmd ~= nil then
       cmd = replacementCmd
   end

if acftName == "FA-18C_hornet" then
	cmd = cmd:gsub("^MPCD_L_(%d)$", "LEFT_DDI_PB_0%1")
	cmd = cmd:gsub("^MPCD_L_(%d%d)$", "LEFT_DDI_PB_%1")
	cmd = cmd:gsub("^MPCD_R_(%d)$", "RIGHT_DDI_PB_0%1")
	cmd = cmd:gsub("^MPCD_R_(%d%d)$", "RIGHT_DDI_PB_%1")
   end

if acftName == "FA-18C_hornet" then
	if cmd == "NAV_CRS" then
		if arg == "INC" then
			hub.sendSimCommand("LEFT_DDI_CRS_SW", "2")
			resetCrsSwitchCountdown = 3
		end
		if arg == "DEC" then
			hub.sendSimCommand("LEFT_DDI_CRS_SW", "0")
			resetCrsSwitchCountdown = 3
		end
	end
end

   return cmd, arg
end

hub.registerInputCallback(function(cmd, arg)
newCmd, newArg = remapCommand(cmd, arg)
if newCmd == cmd and newArg == arg then
	return
end
hub.sendSimCommand(newCmd, newArg)
return true
end)

local ufcMenuMode = false
local idleMode = false
hub.registerInputCallback(function(cmd, arg)
if hub.getSimString("MetadataStart/_ACFT_NAME") ~= "AV8BNA" then return end

if cmd == "UFC_IP" then
	if arg == "1" then ufcMenuMode = not ufcMenuMode end
	return true
end

if not (ufcMenuMode or idleMode) then return end

if cmd == "ODU_OPT1" then
	if arg == "1" then
		if hub.getSimInteger("AV8BNA/AFC_SW") == 2 then
			hub.sendSimCommand("AFC_SW", "1")
		else
			hub.sendSimCommand("AFC_SW", "2")
		end
	end
	return true
end
if cmd == "ODU_OPT2" then
	if arg == "1" then
		if hub.getSimInteger("AV8BNA/ALT_HOLD_SW") == 1 then
			hub.sendSimCommand("ALT_HOLD_SW", "0")
		else
			hub.sendSimCommand("ALT_HOLD_SW", "1")
		end
	end
	return true
end
if cmd == "ODU_OPT3" then
	return true
end
if cmd == "ODU_OPT4" then
	return true
end
if cmd == "ODU_OPT5" then
	return true
end
end)
hub.registerOutputCallback(function()
if hub.getSimString("MetadataStart/_ACFT_NAME") ~= "AV8BNA" then return end

idleMode = true
if hub.getSimString("AV8BNA/UFC_SCRATCHPAD"):gsub(" ", "") ~= "" then idleMode = false end
if hub.getSimString("AV8BNA/AV8BNA_ODU_1_Text"):gsub(" ", "") ~= "" then idleMode = false end
if hub.getSimString("AV8BNA/AV8BNA_ODU_2_Text"):gsub(" ", "") ~= "" then idleMode = false end
if hub.getSimString("AV8BNA/AV8BNA_ODU_3_Text"):gsub(" ", "") ~= "" then idleMode = false end
if hub.getSimString("AV8BNA/AV8BNA_ODU_4_Text"):gsub(" ", "") ~= "" then idleMode = false end
if hub.getSimString("AV8BNA/AV8BNA_ODU_5_Text"):gsub(" ", "") ~= "" then idleMode = false end

if not (ufcMenuMode or idleMode) then return end

local afcEnabled = (hub.getSimInteger("AV8BNA/AFC_SW") == 2)
local altHoldEnabled = (hub.getSimInteger("AV8BNA/ALT_HOLD_SW") == 1)

local afcMode = "    "
if afcEnabled and (not altHoldEnabled) then
	afcMode = "Path"
end
if afcEnabled and altHoldEnabled then
	afcMode = "Alt "
end

hub.setPanelString("AV8BNA/AV8BNA_ODU_1_Text", "AFC")
hub.setPanelString("AV8BNA/AV8BNA_ODU_1_SELECT", afcEnabled and ":" or " ")
hub.setPanelString("AV8BNA/AV8BNA_ODU_2_Text", "ALTH")
hub.setPanelString("AV8BNA/AV8BNA_ODU_2_SELECT", altHoldEnabled and ":" or " ")

hub.setPanelString("AV8BNA/AV8BNA_ODU_3_Text", afcEnabled and afcMode or "OFF!")
hub.setPanelString("AV8BNA/AV8BNA_ODU_3_SELECT", " ")
hub.setPanelString("AV8BNA/AV8BNA_ODU_4_Text", ufcMenuMode and "MENU" or "   ")
hub.setPanelString("AV8BNA/AV8BNA_ODU_4_SELECT", " ")
hub.setPanelString("AV8BNA/AV8BNA_ODU_5_Text",  afcEnabled and "    " or " AFC")
hub.setPanelString("AV8BNA/AV8BNA_ODU_5_SELECT", " ")
end)

Link to comment
Share on other sites

  • Recently Browsing   0 members

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