Jump to content

Detecting doors open/closed and setting Internal Cargo


MeerCaT

Recommended Posts

There's no API available to LUA scripts for "SET INTERNAL CARGO" is there?

Just checking I'm not missing something blindingly obvious.

 

(I have the natural work-around in place, but it's not a very elegant solution having a separate trigger configured through the mission editor for every possible internal cargo value we may want to assign.)

 

 

Related to assigning 'internal cargo', for immersion purposes it would be really nice to monitor the state of the doors on a unit and implement cargo loading procedures accordingly.

 

 

Specifically, of course, I'm interested in the UH-1 Huey and the Mi-8 Magnificent (and so modest!) Eight, but the broader question still applies:

How do we inspect the state of 'components' on an aircraft from within LUA script?

 

I think the 'devices.lua' file (and probably others), for each aircraft is going to be of use with this, but it's not entirely clear what we're looking for in those files or how to make use of the values.

 

The immediate, direct, question is: how to detect left/right side door open/closed on the Huey, and equally for the Mi-8 (side and cargo doors)?

 

But I'm also looking to learn more about general concept of monitoring the state of 'components/devices' on an aircraft from script.

 

Thank you kindly

(Slowly learning how to spell lua)

Link to comment
Share on other sites

Knowing or setting a cargo state isn't possible with lua. There has been a feature request open on this for a while now.

 

As for knowing the status of the doors, there is in fact a way. Unit.getDrawArgumentValue() I forgot about this scripting function on the documentation (sorry!) It is a matter of figuring out the number for the draw argument used. Essentially 3d objects in game have ids associated with different animations. So for example 86 is for the rear doors on the Mi-8. A return value of 0 is the door is closed and 1 its open. Would need to figure out arguments for other parts with other aircraft...

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Thanks that's great, it gives me something to work from.

 

I'm thinking a small piece of brute-force inspection should help figure out the 'bits' of interest, like doors:

Trigger a script on demand that logs the result of Unit.getDrawArgumentValue(n) for values 1 to, let's say, 200 should do it.

 

Comparing the values returned before and after jiggling the 'bits' of interest we should be able to see which values are changing and to what.

 

I'll try it out tonight. Thanks

Link to comment
Share on other sites

Preliminary test results are in and it's looking good.

Thanks once again for the pointer Grimes. ('Grimey'? 'The Filth-Meister'? Sorry, Mr G)

 

With a quick and dirty probing (hello sailor!) using the suggested function I've been able to determine the 'ID' values of the doors on the Huey:

 

 

  • Cockpit Doors: 38
    • Closed = 0
    • (Fully) Open = 0.89999997615814

     

    [*]Left Gunner Door: 43

    • Closed: = 0
    • (Fully) Open = 1

     

    [*]Right Gunner Door: 44

    • Closed: = 0
    • (Fully) Open = 1

     

These 'draw argument' values seem to represent an analogue 'position' of the component at any given time within it's possible range of motion.

Presumably all values ranging from -1 to +1.

 

For the doors on the Huey it seems 0 is the lower bound representing fully closed and, for the gunner doors at least, 1 is fully open.

Curiously the cockpit doors don't open fully to a value of 1, instead consistently coming to rest at a value of 0.89...

(Note to mechanic: the cockpit doors need calibrating!)

 

Of course these IDs are subject to change at the whim of the developers at any time, but I can't imagine them wanting/needing to do that often/ever.

 

I'll look to build a more comprehensive list of these 'component' IDs over time, especially for the Huey and the 'Humble' Eight.

(Unless developers of modules would care to save us plebs some time and open their windows a little to let us peek in)

 

Cheers

Link to comment
Share on other sites

  • 1 month later...
Preliminary test results are in and it's looking good.

Thanks once again for the pointer Grimes. ('Grimey'? 'The Filth-Meister'? Sorry, Mr G)

 

With a quick and dirty probing (hello sailor!) using the suggested function

 

Cheers

 

No Idea what function you talking about :helpsmilie:

 

Will do the Same wit Landing Lights.

Monitoring if its off or on.

 

Pleas can you explain wehr i Find the ID's and values

 

:smilewink:

Always happy landings ;)

Link to comment
Share on other sites

  • 6 months later...

 

  • Cockpit Doors: 38
    • Closed = 0
    • (Fully) Open = 0.89999997615814

     

 

Hi MeerCat,

 

Thanks for investigating.

 

To detect if cockpit doors are closed door I tried:

 

Condition

 

  • X-Cockpit Argument in Range
  • Argument: 38
  • Min: 0
  • Max: 0.05

Action

 

  • Message To All ("Doors closed")

 

It does not work, maybe I did something wrong?

- Tony -

. My Reviews: Oilfield Campaign - Argo Campaign l My Mission: Huey Ramp Start Voice-Over New!

. Microsoft Force Feedback 2 base modded with a CH Fighterstick - VKB Sim T-Rudder Mk.IV Pedals

. Intel i5 4670K @4.3 GHz - 32 Gb DDR3 - MSI GTX 1080 - ASUS PG278QR 27" 2K @165 Hz G-Sync

Link to comment
Share on other sites

Hell yea!! Thanks MeerCat!!

 

Preliminary test results are in and it's looking good.

Thanks once again for the pointer Grimes. ('Grimey'? 'The Filth-Meister'? Sorry, Mr G)

 

With a quick and dirty probing (hello sailor!) using the suggested function I've been able to determine the 'ID' values of the doors on the Huey:

 

 

  • Cockpit Doors: 38
    • Closed = 0
    • (Fully) Open = 0.89999997615814

     

    [*]Left Gunner Door: 43

    • Closed: = 0
    • (Fully) Open = 1

     

    [*]Right Gunner Door: 44

    • Closed: = 0
    • (Fully) Open = 1

     

These 'draw argument' values seem to represent an analogue 'position' of the component at any given time within it's possible range of motion.

Presumably all values ranging from -1 to +1.

 

For the doors on the Huey it seems 0 is the lower bound representing fully closed and, for the gunner doors at least, 1 is fully open.

Curiously the cockpit doors don't open fully to a value of 1, instead consistently coming to rest at a value of 0.89...

(Note to mechanic: the cockpit doors need calibrating!)

 

Of course these IDs are subject to change at the whim of the developers at any time, but I can't imagine them wanting/needing to do that often/ever.

 

I'll look to build a more comprehensive list of these 'component' IDs over time, especially for the Huey and the 'Humble' Eight.

(Unless developers of modules would care to save us plebs some time and open their windows a little to let us peek in)

 

Cheers

Coming Soon...
The Fraternity Returns : https://thefraternitysim.com/
Link to comment
Share on other sites

Meerkat are both cockpit doors under the same I’d meaning you either open or close both doors with no way to open just the pilot or copilot door and leaving the other in its current state

BlackeyCole 20years usaf

XP-11. Dcs 2.5OB

Acer predator laptop/ i7 7720, 2.4ghz, 32 gb ddr4 ram, 500gb ssd,1tb hdd,nvidia 1080 8gb vram

 

 

New FlightSim Blog at https://blackeysblog.wordpress.com. Go visit it and leave me feedback and or comments so I can make it better. A new post every Friday.

Link to comment
Share on other sites

  • 2 months later...

A little gift..

 

Hello, everydody, here is a script, for check doors state in "LUA PREDICATE" rule.

 

Sorry comments are in french, and thanks to thoses (like Grimes), who helps everyone... :)

 

------ SCRIP to put in an .lua file ----------------------------------------------------------------

--==========================================================

-- Controle de l'état des portes du UH et retourne true si la porte est ouverte, false sinon.

--

-- 1/ Charger dans l'éditeur de mission le présent fichier avec : "EXECUTER FICHIER SCRIPT" avec fichier = Ctrl_Portes.lua

-- 2/ utilisation : on ajoute une règle "LUA PREDICATE" avec la commande suivante :

-- return FG02.porteOuverteUH("UH 01", "AVANT") -- test portes avants

-- return FG02.porteOuverteUH("UH 01", "ARRIERES") -- test 2 portes arrières

-- return FG02.porteOuverteUH("UH 01", "ARR_D") -- test 1 porte arrière droite

-- return FG02.porteOuverteUH("UH 01", "ARR_G") -- test 1 porte arrière gauche

-- return FG02.porteOuverteUH("UH 01", "TOUTES") -- test que portes avants et 2 portes arrière sont ouvertes

 

--

-- Cette fonction a besoin de 2 paramètres (params) :

-- 1> Nom de l'unité à contrôler (unit name)(ex :"UH 01" )

-- 2> Code porte à contrôler (3 possibles) :

-- "AVANT" = contrôle portes avant ---------------> for pilot and copilot doors test

-- "ARR_G" = contrôle portes arrière gauche ------> for rear left door test

-- "ARR_D" = contrôle portes arrière droit ------> for rear right door test

-- "TOUTES" = Teste toutes les portes avant + le 2 arrières sont ouvertes --> for all doors test

-- "ARRIERES" = Teste si les 2 portes arrières sont ouvertes ------> for rear 2 doors test

--

-- avril/2018 - par FullGas

--

--

FG02 = {} -- NE PAS RETIRER !

-----------------------------------------------------------------------------------------------

function FG02.porteOuverteUH(helName, Porte)

local u, argdrawv = {}

local codes = {}

local code = ""

local ret = false

if not Unit.getByName(helName) then -- seulement pour unités avec slot client pris, car plantage si s/slot libre

trigger.action.outText("Erreur dans FG02.porteOuverteUH, l'hélico " .. helName .. " n'existe pas ! ", 30) -- if helName don't exist => error message

return nil

else

u = Unit.getByName(helName)

if string.upper(Porte) == "AVANT" then

codes[#codes+1] = 38 -- portes avant à tester

--code = 38 -- portes avant à tester

elseif string.upper(Porte) == "ARR_G" then

codes[#codes+1] = 43 -- portes arrière gauche à tester

-- code = 43 -- portes arrière gauche à tester

elseif string.upper(Porte) == "ARR_D" then

codes[#codes+1] = 44 -- portes arrière droite à tester

--code = 44 -- portes arrière gauche à tester

elseif string.upper(Porte) == "ARRIERES" then

codes[#codes+1] = 43 -- portes arrière gauche à tester

codes[#codes+1] = 44 -- portes arrière droite à tester

elseif string.upper(Porte) == "TOUTES" then

codes[#codes+1] = 38 -- portes avant à tester

codes[#codes+1] = 43 -- portes arrière gauche à tester

codes[#codes+1] = 44 -- portes arrière droite à tester

end

 

if #codes == 0 then -- si params "Porte" inconnu => message erreur

trigger.action.outText("Erreur dans FG02.porteOuverteUH, pour " .. helName .. ", le type de porte " .. tostring(Porte) .. " n'est pas correct (à contrôler) !", 30)

return nil

else

 

-- Tester tous les codes portes à vérifier 1 2 ou 3 selon parmas "Porte"

local pass1 = true

for i=1, #codes do

argdrawv = u:getDrawArgumentValue(codes)

 

if argdrawv ~= nil then

if codes == 38 and argdrawv > 0.899 then argdrawv = 1; end -- ajuster le maxi pour portes avant

 

if argdrawv == 1 then

if pass1 == true then --si premier passage forcer ret

pass1 = false

ret = true; -- porte détectée ouverte

else

ret = ret and true -- porte détectée ouverte

end

else

pass1 = false

ret = false -- porte détectée fermée

end

end

end

end

return ret -- dans tous les cas on retourne l'état de la porte contrôlée (pour les appels par prog lua)

end

end

-- END of SCRIP ---------------------------------------------------------------------------------------

-- how to call ex:

-- 1> in an action "EXECUTE FILE" load the lua file containing the present code

-- 2> in a LUA PREDICATE rule put this script: return FG02.porteOuverteUH("UH 09 HOT","AVANT")

-- for check if the front doors of th UH called "UH 09 HOT" are open

-----------------------------------------------------------------------------------------


Edited by FullGas
Link to comment
Share on other sites

A little gift.. MI8

 

And the same for MI8 :

 

------------- SCRIPT--------------------------

--==========================================================

-- Control de l'état des portes du MI8 et retourne true si la porte est ouverte, false sinon.

--

-- 1/ Charger dans l'éditeur de mission le présent fichier avec : "EXECUTER FICHIER SCRIPT" avec fichier = FG04.porteOuverteMI8.lua

-- 2/ utilisation : on ajoute une règle "LUA PREDICATE" avec la commande suivante :

-- return FG04.porteOuverteMI8("MI 01", "CARGO") -- teste portes arrière CARGO

-- return FG02.porteOuverteMI8("MI 01", "ARR_G") -- teste 1 porte arrière gauche

-- return FG04.porteOuverteMI8("MI 01", "TOUTES") -- teste que portes arrière gauche et cargo sont ouvertes

 

--

-- Cette fonction a besoin de 2 paramètres :

-- 1> Nom de l'unité à contrôler (ex :"MI 01" )

-- 2> Code porte à contrôler (3 possibles) :

-- "ARR_G" = contrôle portes arrière gauche

-- "TOUTES" = teste si portes arrière gauche et cargo sont ouvertes

-- "CARGO" = teste si portes arrière CARGO sont ouvertes

--

-- juillet/2018 - par FullGas

--

--

FG04 = {} -- NE PAS RETIRER !

-----------------------------------------------------------------------------------------------

function FG04.porteOuverteMI8(helName, Porte)

local u, argdrawv = {}

local codes = {}

local code = ""

local ret = false

if not Unit.getByName(helName) then -- seulement pour unités avec slot client pris, car plantage si s/slot libre

trigger.action.outText("Erreur dans FG04.porteOuverteMI8, l'hélico " .. helName .. " n'existe pas ! ", 30)

return nil

else

u = Unit.getByName(helName)

if string.upper(Porte) == "ARR_G" then

codes[#codes+1] = 38 -- portes arrière gauche à tester

elseif string.upper(Porte) == "CARGO" then

codes[#codes+1] = 86 -- portes arrières Cargo

elseif string.upper(Porte) == "TOUTES" then

codes[#codes+1] = 38 -- portes avant à tester

codes[#codes+1] = 86 -- portes arrières Cargo

end

 

if #codes == 0 then -- si params "Porte" inconnu => message erreur

trigger.action.outText("Erreur dans FG04.porteOuverteMI8, pour " .. helName .. ", le type de porte " .. tostring(Porte) .. " n'est pas correct (à contrôler) !", 30)

return nil

else

 

-- Tester tous les codes portes à vérifier 1 ou 2 ou 1 et 2 selon params "Porte"

local pass1 = true

for i=1, #codes do

argdrawv = u:getDrawArgumentValue(codes)

 

if argdrawv ~= nil then

--if codes == 38 and argdrawv > 0.899 then argdrawv = 1; end -- ajuster le maxi pour portes avant

if argdrawv == 1 then

if pass1 == true then --si premier passage forcer ret

pass1 = false

ret = true; -- porte détectée ouverte

else

ret = ret and true -- porte détectée ouverte

end

else

pass1 = false

ret = false -- porte détectée fermée

end

end

end

end

return ret -- dans tous les cas on retourne l'état de la porte contrôlée (pour les appels par prog lua)

end

end

 

-- ex : FG04.porteOuverteMI8("MI 09 HOT","CARGO")

--------------- END OF SCRIPT --------------------

Link to comment
Share on other sites

Just to add for each model that you have the edm (3d shape) files for you are able to view all the arguments and manipulate them to see what the different values do in the standard DCS World model viewer. Official edm files are usually under \DCS World\Bazar\World\Shapes or in DCS World\Mods\aircraft\ or in DCS World\CoreMods\aircraft\ depending on what you are looking for. The model viewer exe is located in DCS World\bin and there is a thread about how to set it up over in the 3d modelling sub forum.

 

 

Might save time for people looking for a particular argument id.

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...
Thanks a lot FullGas, it works perfect.

Also for the Gazelle, when you use "AVANT"

Hello PIetpuk,

 

I'm happy if this script is usefull for you.

 

I've not the gazelle, the Huey version have probably the same argument for front doors state. :)

 

Have fun

Link to comment
Share on other sites

  • Recently Browsing   0 members

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