Cockpit from scratch
what you need to make cockpit package : 3d model of cockpit (we will not discuss about aspects of creation 3d models here), lua skills , C/C++ skills (optionally ),patience !
Each time when you take control over aircraft ,DCS will try to load package from HumanCockpitPath entry of database for this aircraft type, it can be added for existed aircraft (ie F-16 in DCS )
by calling
make_flyable("F-16",current_mod_path..'/Cockpit/Scripts') -- for example
if such path exist DCS will start loading it by executing two files at the root of this folder
clickabledata.lua
device_init.lua
clickabledata contain info about clickable elements of your cockpit 3d model and commands which will be raised to targeted device on click.
devices are declared in file device_init
first device which you always need is MainPanel
it is always declared in form of
MainPanel = {"ccMainPanel",LockOn_Options.script_path.."mainpanel_init.lua"}
where ccMainPanel is command to factory to create object of type ccMaiPanel
next is init script for your device
MainPanel will hold and render your 3d model and animate gauges by "arguments"
after main panel declaration
you are can declare up to 255 devices for different purposes
creators = {}
creators[devices.TEST] = {"avLuaDevice" ,LockOn_Options.script_path.."test_device.lua"}
creators[devices.WEAPON_SYSTEM] = {"avSimpleWeaponSystem" ,LockOn_Options.script_path.."Systems/weapon_system.lua"}
creators[devices.CLOCK] = {"avAChS_1" ,LockOn_Options.script_path.."clock.lua"}
creators[devices.ADI] = {"avBaseIKP" ,LockOn_Options.script_path.."adi.lua"}
creators[devices.ELECTRIC_SYSTEM]= {"avSimpleElectricSystem",LockOn_Options.script_path.."Systems/electric_system.lua"}
creators[devices.RADAR] = {"avSimpleRadar" ,LockOn_Options.script_path.."RADAR/Device/init.lua"}
table devices is just named index
local count = 0
local function counter()
count = count + 1
return count
end
-------DEVICE ID-------
devices = {}
devices["TEST"] = counter()--1
devices["WEAPON_SYSTEM"] = counter()--2
devices["ELECTRIC_SYSTEM"] = counter()--3
devices["CLOCK"] = counter()--4
devices["ADI"] = counter()--5
devices["RADAR"] = counter()--6
all devices except TEST store their base functionality inside our libraries and used just as entry point to core data of FM and other objects
avLuaDevice is device which functionality completely driven by lua
for example content of test_device.lua
local dev = GetSelf()
local my_param = get_param_handle("TEST_PARAM") -- obtain shared parameter (created if not exist ), i.e. databus
my_param:set(0.1) -- set to 0.1
local update_time_step = 0.1
make_default_activity(update_time_step)
--update will be called 10 times per second
local sensor_data = get_base_data()
local DC_BUS_V = get_param_handle("DC_BUS_V")
DC_BUS_V:set(0)
function post_initialize()
electric_system = GetDevice(3) --devices["ELECTRIC_SYSTEM"]
print("post_initialize called")
end
function update()
local v = my_param:get()
print(v)
my_param:set(sensor_data.getMachNumber())
if electric_system ~= nil then
local DC_V = electric_system:get_DC_Bus_1_voltage()
local prev_val = DC_BUS_V:get()
-- add some dynamic:
DC_V = prev_val + (DC_V - prev_val) * update_time_step
DC_BUS_V:set(DC_V)
end
end
function SetCommand(command,value)
if command == 3001 then
print("user click")
end
end
most important thing of that is
local my_param = get_param_handle("TEST_PARAM")
get_param_handle create named databus entry which can be accessed by any other device, indication element , panel gauge , trigger event by name
this code inside mainpanel_init.lua will animate value of TEST_PARAM as argument 113 of 3d model
TEST_PARAM_GAUGE = CreateGauge("parameter")
TEST_PARAM_GAUGE.parameter_name = "TEST_PARAM"
TEST_PARAM_GAUGE.arg_number = 113
TEST_PARAM_GAUGE.input = {0,100}
TEST_PARAM_GAUGE.output = {0,1}
this code inside indicator's script will add text to HUD with this value
local test_output = CreateElement "ceStringPoly"
test_output.name = create_guid_string()
test_output.material = FONT_
test_output.init_pos = {0,-1}
test_output.alignment = "CenterCenter"
test_output.stringdefs = {0.01,0.75 * 0.01, 0, 0}
test_output.formats = {"%.2f","%s"}
test_output.element_params = {"TEST_PARAM"}
test_output.controllers = {{"text_using_parameter",0,0}} --first index is for element_params (starting with 0) , second for formats ( starting with 0)
test_output.additive_alpha = true
test_output.collimated = true
AddElement(test_output)
as more usefull sample
gun_sight_mark = create_textured_box(0,0,32,32) -- this is create_textured_box function call with parameters
gun_sight_mark.material = PIPER_
gun_sight_mark.name = BASE_COLOR_MAT
gun_sight_mark.collimated = true
gun_sight_mark.element_params = {"WS_GUN_PIPER_AVAILABLE",
"WS_GUN_PIPER_AZIMUTH",
"WS_GUN_PIPER_ELEVATION"}
gun_sight_mark.controllers = {{"parameter_in_range" ,0,0.9,1.1},--check that piper available using WS_GUN_PIPER_AVAILABLE
{"move_left_right_using_parameter",1, 0.73 }, --azimuth move by WS_GUN_PIPER_AZIMUTH , 0.73 is default collimator distance (from eye to HUD plane)
{"move_up_down_using_parameter" ,2, 0.73 }, --elevation move by WS_GUN_PIPER_ELEVATION
}
AddElement(gun_sight_mark)
use three named params to control gun piper mark position on HUD
to be continued...