Wrecking Crew Posted October 29, 2014 Share Posted October 29, 2014 Need to detect when a helicopter lands, anywhere. I spent a lot of time on this today and have a working solution to share. If there is a better way I'd like to hear about it. I tried a bunch of variations of 'return Unit.getByName('huey'):inAir()' but my result was toggling between 'flying' and 'landing' so much that I couldn't figure why or suppress the cycling. The result strengthened the notion that helicopters aren't really flying... :) The Unit's Altitude Lower Than condition wasn't suitable because the height argument for it is 'above sea level' and the the helicopter could be in an area where the terrain is actually higher than the set value. This condition works fine if the helicopter is landing at a zone where the height is known. To detect when a desired helicopter lands anywhere, I used three events: 1. Switched Condition, Unit's Speed Lower Than (unit name, 1), Flag On (1) 2. Switched Condition, Flag Is True (1) & Unit's Speed Higher Than (unit name, 1), Flag Off (1) 3. Switched Condition, Time Since Flag (1, 20), Message ("Helicopter has landed.") ..at less that 17 seconds in #3 there were false triggers as the helicopter prepared to land. The test mission is attached -- look at events 8-10. It would have been great if this could have worked: if Unit.getByName('UH-1H 11'):inAir() == 1 then trigger.action.setUserFlag(61105, 1) -- is flying trigger.action.setUserFlag(61107, 0) -- not landed else trigger.action.setUserFlag(61105, 0) -- not flying trigger.action.setUserFlag(61107, 1) -- is landed end WC Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site. Link to comment Share on other sites More sharing options...
xcom Posted October 30, 2014 Share Posted October 30, 2014 (edited) I would use the event handler. You can simply look for an event when a certain unit is landing. local eHandler = {} function eHandler:onEvent(e) if e.id == world.event.S_EVENT_LAND then if e.initiator then local gName = e.initiator:getname() if gName = 'whatever you want' then whatever you want end end end end world.addEventHandler(eHandler) You can also use e.place to get the exact location of landing. Edited October 30, 2014 by xcom [sIGPIC][/sIGPIC] BuddySpike Website | Live Map & Statistics BuddySpike Twitch Channel Buddyspike Discord Buddyspike Facebook Link to comment Share on other sites More sharing options...
Wrecking Crew Posted October 30, 2014 Author Share Posted October 30, 2014 Thanks, xcom! I read about this function in the v37 Mist Guide. Can you point me to other references that list the different events and their returns? WC Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site. Link to comment Share on other sites More sharing options...
xcom Posted October 30, 2014 Share Posted October 30, 2014 No problem, here is a list I collected a while back, it doesn't hold all the events but most of them - http://forums.eagle.ru/showpost.php?p=2207552&postcount=27 [sIGPIC][/sIGPIC] BuddySpike Website | Live Map & Statistics BuddySpike Twitch Channel Buddyspike Discord Buddyspike Facebook Link to comment Share on other sites More sharing options...
Paganus Posted October 31, 2014 Share Posted October 31, 2014 I tried using this but I'm getting an error on mission load. local eHandler = {} function eHandler:onEvent(e) if e.id == world.event.S_EVENT_LAND then if e.initiator then local gName = e.initiator:getname() if gName = 'PEDRO 1' then trigger.action.setUserFlag(1,true) end end end end world.addEventHandler(eHandler) Here is the error... [string "c:\Users\username\AppData\Local\Temp\DCS\/~misc00000480"]:7: 'then' expected near '=' So it's telling me line 7, then expected near =, but that makes no sense to me. Any help would be appreciated. Link to comment Share on other sites More sharing options...
Grimes Posted November 1, 2014 Share Posted November 1, 2014 if gName = 'PEDRO 1' then change to if gName == 'PEDRO 1' then The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting 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 More sharing options...
Paganus Posted November 1, 2014 Share Posted November 1, 2014 Mission script error [string "local eHandler = {}..."]:6: attempt to call method 'getname' (a nil value) stack traceback: [C]: in function 'getname' [string "local eHandler = {}..."]:6: in function 'onEvent' {string "Scripts/World/EventHandlers.lua"]:13: in function <[string "Scripts/World/EventHandlers.lua"]:11> ...but I don't think it will work as I and the OP had hoped anyway. Landing events only happen at airfields. Landing off field doesn't count. Link to comment Share on other sites More sharing options...
Wrecking Crew Posted November 1, 2014 Author Share Posted November 1, 2014 (edited) My three-event method is working in this attached mission with regular events. Quite complicated to detect a landing, when this could be simplified with a change to the event condition of Unit's Altitude Lower Than (agl) -- see this post: http://forums.eagle.ru/showthread.php?t=132956 WC Edited November 1, 2014 by Wrecking Crew using events Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site. Link to comment Share on other sites More sharing options...
xcom Posted November 1, 2014 Share Posted November 1, 2014 Paganus is correct, apparently the land/takeoff events work only from Aerodromes which means - Airbases, FARPs, Carriers, you cannot rely on them to make sure a unit is airborne. [sIGPIC][/sIGPIC] BuddySpike Website | Live Map & Statistics BuddySpike Twitch Channel Buddyspike Discord Buddyspike Facebook Link to comment Share on other sites More sharing options...
camsr Posted November 6, 2014 Share Posted November 6, 2014 I have an idea, but it may not work if the helicopter is hovering (very) still in the air. First, differentiate the unit's vertical position to attain it's vertical velocity. Might need to do this at a high rate, maybe 100 milliseconds per iteration, depending on how fast you'd want the landing event to register. Then add the unit's forward and lateral speeds (taken via differentiation again) to the result of the vertical. After doing this, you'll need to apply a peak following algorithm to the summed values, which is a function that will instantly increase in value if it goes above it's "decay", and the function will decay if the input value is lower. If you are familiar with electronics, it would look like the output of the bridge capacitor following the full wave rectifier in a power supply circuit, it just decays slowly after the input has ceased. And then maybe after that, use the InAir() function or whatever is used to report the aircraft is indeed flying, and if it returns true, add some large number to the derivatives' sum to offset any lack of motion in the air. Then compare the final sum to a small number and if it's below, most likely the thing has landed or crashed. Rather difficult to explain completely, if you want some help with the math, send me a PM. Link to comment Share on other sites More sharing options...
Wrecking Crew Posted November 6, 2014 Author Share Posted November 6, 2014 These three events do the job -- To detect when a desired helicopter lands anywhere: 1. Switched Condition, Unit's Speed Lower Than (unit name, 1), Flag On (1) 2. Switched Condition, Flag Is True (1) & Unit's Speed Higher Than (unit name, 1), Flag Off (1) 3. Switched Condition, Time Since Flag (1, 20), Message ("Helicopter has landed.") The InAir function kept returning false positives. This week I did see a quite successful Embark and Disembark for a bunch of soldiers and an Mi-8T. The mission is by Toxocara in this post if you want to take a look. http://forums.eagle.ru/showthread.php?p=2222442#post2222442 Whatever code is determining that the Mi-8T has landed works well for this feature. WC Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site. Link to comment Share on other sites More sharing options...
ajax Posted November 7, 2014 Share Posted November 7, 2014 If you prefer using a simple Lua predicate as a trigger condition, see this post: http://forums.eagle.ru/showpost.php?p=2066145&postcount=7 It's designed to check in a zone, but I suppose you could make a zone that covers the entire map to make it work for you. Link to comment Share on other sites More sharing options...
Wrecking Crew Posted November 7, 2014 Author Share Posted November 7, 2014 No... the idea behind this post is to land anywhere... Thanks, though. WC Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site. Link to comment Share on other sites More sharing options...
camsr Posted November 7, 2014 Share Posted November 7, 2014 I made a mission that embarked an "officer" (holding an AK47 :P) onto a helicopter. I used the altitude below trigger and vertical speed and unit in-zone. It works perfect but like you said, altitude is only above sea level. Link to comment Share on other sites More sharing options...
RetroBurn Posted November 7, 2014 Share Posted November 7, 2014 This sounds like a user called raaaaid some years ago. What? dumb it down for us humans...lol Win 7 HE / GigaByte Z68AP-D3 / i5-2500K 3.30 GHz / 16Gb RAM / GTX 570 2.5GB [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Wrecking Crew Posted November 7, 2014 Author Share Posted November 7, 2014 (edited) LOL A friend suggested a new mission where a Huey could deliver Stingers around a Red airbase. So my issue was to be able to drop off a Stinger team anywhere on the map. The Mission Editor has events to easily detect conditions for 'helicopter landed' when the helicopter lands in a zone, because the height of the zone is known. But to land anywhere and detect that condition required some investigation. The solution has to account for hovering, when the helicopter has zero speed. Here is my mission -- WC's Bridge At Zugdidi 1210v2r WC Edited November 7, 2014 by Wrecking Crew Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site. Link to comment Share on other sites More sharing options...
Recommended Posts