Jump to content

DCS Mods structure : How to create your plugin from scratch


Recommended Posts

If can be of any help, function from:

local sensor_data = get_base_data()

getAngleOfAttack
getAngleOfSlide
getBarometricAltitude
getCanopyPos
getCanopyState
getEngineLeftFuelConsumption
getEngineLeftRPM
getEngineLeftTemperatureBeforeTurbine
getEngineRightFuelConsumption
getEngineRightRPM
getEngineRightTemperatureBeforeTurbine
getFlapsPos
getFlapsRetracted
getHeading
getHelicopterCollective
getHelicopterCorrection
getHorizontalAcceleration
getIndicatedAirSpeed
getLandingGearHandlePos
getLateralAcceleration
getLeftMainLandingGearDown
getLeftMainLandingGearUp
getMachNumber
getMagneticHeading
getNoseLandingGearDown
getNoseLandingGearUp
getPitch
getRadarAltitude
getRateOfPitch
getRateOfRoll
getRateOfYaw
getRightMainLandingGearDown
getRightMainLandingGearUp
getRoll
getRudderPosition
getSpeedBrakePos
getStickPitchPosition
getStickRollPosition
getThrottleLeftPosition
getThrottleRightPosition
getTotalFuelWeight
getTrueAirSpeed
getVerticalAcceleration
getVerticalVelocity
getWOW_LeftMainLandingGear
getWOW_NoseLandingGear
getWOW_RightMainLandingGear

Link to comment
Share on other sites

I think I understand how this is supposed to work now and I am following the example of Macro_handler.lua in the /Script/Aircrafts/_Common folder but it's still not working.

 

If I understand correctly, dev:listen_command calls SetCommand(command,value) when the command being listened to is sent to the sim. What I don't understand is why I would have to call a macro to perform one action.

 

 

BrakeController.lua

local dev = GetSelf()

local sensor_data = get_base_data()

local f = loadfile(LockOn_Options.script_path.."Macro_sequencies.lua")
if f then
  pcall(f)
end

local update_rate = 0.2 -- 1/5 sec, or 5 times per second
make_default_activity(update_rate)

local m_max = get_param_handle("Max_Mach")
local auto_ext = get_param_handle("AutoExtended")

local iPlaneAirBrakeOn = 147
local iPlaneAirBrakeOff = 148

dev:listen_command(iPlaneAirBrakeOn)
dev:listen_command(iPlaneAirBrakeOff)

function post_initialize()
   auto_ext:set(0)
   m_max:set(0)
   print("post_initialize called in BrakeController.lua")
end

function update()

   local spdbrkpos = sensor_data.getSpeedBrakePos()
   local mach = sensor_data.getMachNumber()

   if mach>0.78 then
       m_max:set(1)
   else
       m_max:set(0)
   end

   if mach>0.78 and spdbrkpos==0 then
       --BRAKES OUT
       dispatch_action(nil,iPlaneAirBrakeOn)
       auto_ext:set(1)
   elseif mach<0.75 and spdbrkpos==1 and auto_ext==1 then
       --BRAKES IN
       dispatch_action(nil,iPlaneAirBrakeOff)
       auto_ext:set(0)
   end
end

function SetCommand(command,value)
   if track_is_reading() then
       return
   end
if command == iPlaneAirBrakeOn then	
    check_routine(start_order,airbrakes_out)
elseif command == iPlaneAirBrakeOff then
       check_routine(start_order,airbrakes_in)
   end
end

need_to_be_closed = true -- close lua state after initialization

 

 

Command_defs.lua

Keys =
{
PlaneAirBrakeOn = 147,
PlaneAirBrakeOff = 148,
}

 

 

Macro_Sequences.lua

std_message_timeout = 2

airbrakes_out = {
{time = 0.050000,action = 147,message = _("AIRBRAKES OUT"),message_timeout = std_message_timeout},
}
airbrakes_in = {
{time = 0.050000,action = 148,message = _("AIRBRAKES IN"),message_timeout = std_message_timeout},
}

 

 

I have even tried to make my own button macro using this guide and replacing the common script modifications with the aircraft specific scripts. I couldn't get this to work either.

http://en.wiki.eagle.ru/wiki/Macros_%28Command_Sequences%29


Edited by SilentEagle
Link to comment
Share on other sites

  • ED Team

dev:listen_command is just subscribe this device to given command number , i.e. when you push putton on joystick and when this button is assigned to this command , your device will be notified about it and SetCommand will be called . macro_handler.lua is just sample of how to use dispatch_action , nothing more . dispatch_action is replacement for LoSetCommand ( which is export.lua function )

sigpic2354_5.gif
Link to comment
Share on other sites

  • ED Team
I think I understand how this is supposed to work now and I am following the example of Macro_handler.lua in the /Script/Aircrafts/_Common folder but it's still not working.

 

If I understand correctly, dev:listen_command calls SetCommand(command,value) when the command being listened to is sent to the sim. What I don't understand is why I would have to call a macro to perform one action.

 

 

BrakeController.lua

local dev = GetSelf()

local sensor_data = get_base_data()

local f = loadfile(LockOn_Options.script_path.."Macro_sequencies.lua")
if f then
  pcall(f)
end

local update_rate = 0.2 -- 1/5 sec, or 5 times per second
make_default_activity(update_rate)

local m_max = get_param_handle("Max_Mach")
local auto_ext = get_param_handle("AutoExtended")

local iPlaneAirBrakeOn = 147
local iPlaneAirBrakeOff = 148

dev:listen_command(iPlaneAirBrakeOn)
dev:listen_command(iPlaneAirBrakeOff)

function post_initialize()
   auto_ext:set(0)
   m_max:set(0)
   print("post_initialize called in BrakeController.lua")
end

function update()

   local spdbrkpos = sensor_data.getSpeedBrakePos()
   local mach = sensor_data.getMachNumber()

   if mach>0.78 then
       m_max:set(1)
   else
       m_max:set(0)
   end

   if mach>0.78 and spdbrkpos==0 then
       --BRAKES OUT
       dispatch_action(nil,iPlaneAirBrakeOn)
       auto_ext:set(1)
   elseif mach<0.75 and spdbrkpos==1 and auto_ext==1 then
       --BRAKES IN
       dispatch_action(nil,iPlaneAirBrakeOff)
       auto_ext:set(0)
   end
end

function SetCommand(command,value)
   if track_is_reading() then
       return
   end
if command == iPlaneAirBrakeOn then	
    check_routine(start_order,airbrakes_out)
elseif command == iPlaneAirBrakeOff then
       check_routine(start_order,airbrakes_in)
   end
end

need_to_be_closed = true -- close lua state after initialization

 

 

Command_defs.lua

Keys =
{
PlaneAirBrakeOn = 147,
PlaneAirBrakeOff = 148,
}

 

 

Macro_Sequences.lua

std_message_timeout = 2

airbrakes_out = {
{time = 0.050000,action = 147,message = _("AIRBRAKES OUT"),message_timeout = std_message_timeout},
}
airbrakes_in = {
{time = 0.050000,action = 148,message = _("AIRBRAKES IN"),message_timeout = std_message_timeout},
}

 

 

I have even tried to make my own button macro using this guide and replacing the common script modifications with the aircraft specific scripts. I couldn't get this to work either.

http://en.wiki.eagle.ru/wiki/Macros_%28Command_Sequences%29

 

your sample have mistakes :

 

need_to_be_closed must be false if you want get this state active after initialization .

if you set it to true , "update" , "SetCommand" will never be called ,

 

track_is_reading() should be checked before calling dispatch_action , if it will be checked on start of SetCommand , SetCommand will be not fully executed in track which broke track reproducibility.

 

you dont need to dlisten PlaneAirBrakeOn and PlaneAirBrakeOff in this sample,

sigpic2354_5.gif
Link to comment
Share on other sites

Just to clear it in my mind

dispatch_action(nil,iPlaneAirBrakeOff)

it's the code needed to send to sim engine the "close air break" command?

and if i need to close them just to 40% (or just for three state flaps (closed, takeoff, landing))?

Link to comment
Share on other sites

Thanks Alex!! Got it working perfectly.

 

 

local dev = GetSelf()

local sensor_data = get_base_data()

local update_rate = 0.2 -- 1/5 sec, or 5 times per second
make_default_activity(update_rate)

local m_max = get_param_handle("Max_Mach")
local auto_ext

local iPlaneAirBrakeOn = 147
local iPlaneAirBrakeOff = 148

function post_initialize()
   auto_ext=0
   m_max:set(0)
   print("post_initialize called in BrakeController.lua")
end

function update()

   local spdbrkpos = sensor_data.getSpeedBrakePos()
   local mach = sensor_data.getMachNumber()

   if mach>0.78 then
       m_max:set(1)
   else
       m_max:set(0)
   end

   if mach>0.78 and spdbrkpos==0 then
       --BRAKES OUT
       dispatch_action(nil,iPlaneAirBrakeOn)
       auto_ext=1
   elseif mach<0.75 and spdbrkpos==1 and auto_ext==1 then
       --BRAKES IN
       dispatch_action(nil,iPlaneAirBrakeOff)
       auto_ext=0
   end
end

need_to_be_closed = false -- close lua state after initialization

 

question about what you said on track_is_reading.

 

Where exactly in my example should:

if track_is_reading() then
   return
end

 

be called? Or is it even needed?

Link to comment
Share on other sites

  • ED Team
Thanks Alex!! Got it working perfectly.

 

 

local dev = GetSelf()

local sensor_data = get_base_data()

local update_rate = 0.2 -- 1/5 sec, or 5 times per second
make_default_activity(update_rate)

local m_max = get_param_handle("Max_Mach")
local auto_ext

local iPlaneAirBrakeOn = 147
local iPlaneAirBrakeOff = 148

function post_initialize()
   auto_ext=0
   m_max:set(0)
   print("post_initialize called in BrakeController.lua")
end

function update()

   local spdbrkpos = sensor_data.getSpeedBrakePos()
   local mach = sensor_data.getMachNumber()

   if mach>0.78 then
       m_max:set(1)
   else
       m_max:set(0)
   end

   if mach>0.78 and spdbrkpos==0 then
       --BRAKES OUT
       dispatch_action(nil,iPlaneAirBrakeOn)
       auto_ext=1
   elseif mach<0.75 and spdbrkpos==1 and auto_ext==1 then
       --BRAKES IN
       dispatch_action(nil,iPlaneAirBrakeOff)
       auto_ext=0
   end
end

need_to_be_closed = false -- close lua state after initialization

 

question about what you said on track_is_reading.

 

Where exactly in my example should:

if track_is_reading() then
   return
end

 

be called? Or is it even needed?

 

ok let's me to explain :

 

dispatch_action send command to player's unit and put copy to the track . when track is reading this value poped from track and sended back to player's unit

 

so correct handling should be

if not  track_is_reading() then
  dispatch_action(nil,command,value_if_it_exist)
end

 

to avoid duplicates in input queue when track is playnig , cause command will be already there

sigpic2354_5.gif
Link to comment
Share on other sites

Ok Alex, thanks for your help, correct me if i am wrong.

 

This is the scenario:

  1. 3D cockpit, i click on a button X to set flaps to landing;
  2. button X is attached to device Y;
  3. on device Y is called the function SetCommand();
  4. we call the dispatch_action(nil, iFlaps, iFull).

Is this the right way to interact from our LUA device with the simulation engine?

Link to comment
Share on other sites

my question is:

how do i export to a log file, the words that are displayed on the screen while in game?

Asus x99, i7 5930k, 32g mem, MSI 1070GTX, 970 Samsung M.2, LG 35in Ultra-Wide, TrackIR 4

Thrustmaster Warthog HOTAS

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Alex... can you help me find a list of element controllers?

 

I know only of these:

 

text_using_parameter

move_up_down_using_parameter

move_left_right_using_parameter

rotate_using_parameter

parameter_in_range

 

I'd also love to find a list of Elements themselves... like

ceTexPoly

ceStringPoly

 

etc.


Edited by aaron886
Link to comment
Share on other sites

  • 1 month later...

I have some difficulties with adding new aircraft unit in DCSW.

Using Wunderluft template, I`ve made new aircraft Mod folder. I`ve changed all "wunderluft" inside files of my Mod folder.

Result is only working patch (I can set wallpaper) bottom in main DCS window, in mission editor my craft is absent. Also I tried delete Wunderluft mod folder, but no success again.

I suppose problem in some identifier like CLSID or something else.

So, what parameters exactly should be different compare to another craft?

thanks

  • Like 1
Link to comment
Share on other sites

Sevas,

If you just copy all of the template files into the mods\aircrafts folder withouth changing anything, do you see it in main menu, mission editor and in flight?

 

If you do, then it's a process of elimination to see what file is causing your problem.

 

I would suggest step by step like this:

Copy templates files to mods\aircrafts - do not rename anything

Export your exterior 3d model and rename that file to Wunderluft.edm and put it into mods\aircrafts\wunderluft\shapes

 

Do you see the exterior model in sim?

 

If so, move onto the next step which is to rename things. You have to be very careful here though to make sure you don't delete " or ; or ,

 

Next is to look at the code.

Always do things one step at a time, don't rush in changing things here and there. Trust me I've spent many hours trying to debug errors when I've changed a lot.

It may seem like a long task to change one thing, go in sim, check it, change another, check in sim, repeat... but it is worth it in the long run.

 

Let me know how you get on with the exterior model bit first and then I'll talk you through the code, and then the cockpit functions.

 

Cheers,

Chris.


Edited by Ells228
Link to comment
Share on other sites

If I just copy and past Wunderluft folder (like Wunderluft2) without changing anything then impossible to run DCSW.

After, I tried to change entry.lua and myplane.lua and I see myplane only in main DCS menu. So, all tests with shapes impossible, cause in editor I can`t choose my plane.

Someone, test please my mod folder, is it appear in mission editor?


Edited by BR=55=Sevas
Link to comment
Share on other sites

Doesn't work for me either, Sevas. I've had similar problems when trying to use the correct identifier/name for my aircraft, in the end I had to settle for a name consisting only of letters. ("Hornet") I wonder if it's just a limitation of the present system.

Link to comment
Share on other sites

Sevas, in Mig-15.lua change MiG-15 = { to MiG_15 = {

and at the end of file make it add_aircraft(MiG_15)

 

let me know if it works for you

 

at this stage to avoid confusion try naming your aircraft with one word without -,_ etc

  • Like 1
Link to comment
Share on other sites

Thanks, Aaron!

Now it works.

 

Madhog, I will try.

UPD: It works, madhog, thank you very much!

I hope developers will fix it in future.


Edited by BR=55=Sevas
Link to comment
Share on other sites

Hello to all..

I was able to successfully import the-39 thanks to your comments positive

Downloaded MI-15 I am not visual model in mission editor

I renamed the files .. but without success.

I noticed that the folder shepes "mig 15" and 'without file.Il ME does not lead to see the model.

In the root there is a file DCSW edm Mig-15 and we will never see it.

Reason for the opposite L-39 'cause exists at the root DCSW.

Link to comment
Share on other sites

Doesn't work for me either, Sevas. I've had similar problems when trying to use the correct identifier/name for my aircraft, in the end I had to settle for a name consisting only of letters. ("Hornet") I wonder if it's just a limitation of the present system.

 

Aaron i resolve this problem.....now i have 2(and i see) aircraft for my mod( SMT and UBT)....if i have free time this week i help you.....

Link to comment
Share on other sites

  • Recently Browsing   0 members

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