Jump to content

How to set up trigger for when player has landed


Fisherman82

Recommended Posts

Hello!

 

Does anybody know how to set up a trigger for when the player in a singleplayer mission has landed? Or when the engines have stopped? I was trying with LUA predicate and GetUnitInAir function but I could not get it to work.

 

With the F15 I have done missions that wont trigger success unless the unit (player) is alive and has parked on the ramp with unit in zone and unit speed lower than 1m/s. Since the F15 wont fly at that speed so it must be on the ground if the condition is true. But that wont work with helicopters and an upcoming Harrier who can hover. I could use unit altitude lower than but that is in MSL so it would vary across different airfields and maybe different ramp positions on the same field. How can I set a flag for when a unit is on the ground or something else like when its engines are off? (the unit wont hover if the engines are off so it must be on the ground if it is alive)

 

Im a LUA noob by the way..

  • Like 1
Link to comment
Share on other sites

To be specific, you can do it cheaply with a condition of speed of the unit drops to a certain amount, like<1ms

LUA predicate is broken. You wont know that, that's not your fault, welcome to the oddities of the DCS SE.

 

If you want to do more complex things, this tiny part is contained in MOOSE functions and it automatically deals with the shutdown event, clears up the mess and can go off and spawn something else, but that is maybe far down the line for you and out of scope for your question.

___________________________________________________________________________

SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING *

Link to comment
Share on other sites

I have been trying to understand MOOSE and MIST but they seem to complex for me to learn. Thank you for the info that LUA Predicate is broken, I didnt know that and that knowledge will save me a lot of pointless efforts :) I guess I will have to do it with a combination of the ordinary conditions that is available in the mission editor.

Link to comment
Share on other sites

I have been trying to understand MOOSE and MIST but they seem to complex for me to learn. Thank you for the info that LUA Predicate is broken, I didnt know that and that knowledge will save me a lot of pointless efforts :) I guess I will have to do it with a combination of the ordinary conditions that is available in the mission editor.

 

Don't underestimate yourself.

 

In the long run it's harder to get what you want through the mission editor.

  • Like 1
Link to comment
Share on other sites

I'm gonna +1 this. I spent years with the ME and it was always limiting. There's no silver bullet solution for circumventing DCS ME quirks, but after a month with Moose I can achieve way more than I ever could with 50 billion triggers with 5 conditions and combinations of AND + OR, that needlessly test every second. Most of the people that had the desire to go further started to script basic things themselves. The half way houses of MIST and MOOSE and so on let you have great power in one or two lines of copy and paste code.

 

Unfortunately they appear more daunting than they really are. And there is no denying there is still much learning to be done. It's all down to whether you want to break the glass ceiling.

Don't underestimate yourself.

 

In the long run it's harder to get what you want through the mission editor.

  • Thanks 1

___________________________________________________________________________

SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING *

Link to comment
Share on other sites

Hello!

 

Does anybody know how to set up a trigger for when the player in a singleplayer mission has landed? Or when the engines have stopped? I was trying with LUA predicate and GetUnitInAir function but I could not get it to work.

 

With the F15 I have done missions that wont trigger success unless the unit (player) is alive and has parked on the ramp with unit in zone and unit speed lower than 1m/s. Since the F15 wont fly at that speed so it must be on the ground if the condition is true. But that wont work with helicopters and an upcoming Harrier who can hover. I could use unit altitude lower than but that is in MSL so it would vary across different airfields and maybe different ramp positions on the same field. How can I set a flag for when a unit is on the ground or something else like when its engines are off? (the unit wont hover if the engines are off so it must be on the ground if it is alive)

 

Im a LUA noob by the way..

 

In fairness a "has landed" test is relatively simple. Try using combinations:

 

1) Time more than x (so it doesn't trigger on mission start)

and

1) Unit speed less than 10 Km/h.

and

2) Unit altitude less than (airfield altitude + 5m)

and

3) Unit in zone.

 

There's also a way to return values for cockpit control settings, e.g. if a throttle is set to zero, but understanding the various codes for cockpit items is well beyond my lua abilities.

System Spec: Cooler Master Cosmos C700P Black Edition case. | AMD 5950X CPU | MSI RTX-3090 GPU | 32GB HyperX Predator PC4000 RAM | | TM Warthog stick & throttle | TrackIR 5 | Samsung 980 Pro NVMe 4 SSD 1TB (boot) | Samsung 870 QVO SSD 4TB (games) | Windows 10 Pro 64-bit.

 

Personal wish list: DCS: Su-27SM & DCS: Avro Vulcan.

Link to comment
Share on other sites

Hello!

 

Does anybody know how to set up a trigger for when the player in a singleplayer mission has landed? Or when the engines have stopped? I was trying with LUA predicate and GetUnitInAir function but I could not get it to work.

 

With the F15 I have done missions that wont trigger success unless the unit (player) is alive and has parked on the ramp with unit in zone and unit speed lower than 1m/s. Since the F15 wont fly at that speed so it must be on the ground if the condition is true. But that wont work with helicopters and an upcoming Harrier who can hover. I could use unit altitude lower than but that is in MSL so it would vary across different airfields and maybe different ramp positions on the same field. How can I set a flag for when a unit is on the ground or something else like when its engines are off? (the unit wont hover if the engines are off so it must be on the ground if it is alive)

 

Im a LUA noob by the way..

 

The way I do it for the Huey using only mission triggers, and it works pretty well for me but is somewhat complex, is as follows (this is all for one action):

 

1. Type: Switched Condition

 

Conditions: Unit Inside Zone, Units Speed Lower Than (1 kts), Units Vertical Speed In Limits (Minimum -.01, Maximum .01)

 

Action: Flag On (x)

 

2. Type: Switched Condition

 

Conditions: Units Speed Higher Than (0 knots) [or] Unit's Vertical Speed In Limits ( Minimum .02, Maximum 10) [or] Unit's Vertical Speed In Limits (Minimum -10, Maximum -.02)

 

Action: Flag Off (x)

 

3. Type: Once

 

Conditions: Time Since Flag (x) 5 seconds

 

Action: What you want to have happen

 

The reason I do it this way is because if you have a large landing zone with different ground elevations it makes it difficult to do the other way. Or if you're landing on a rooftop. To sustain a hover that still is difficult and usually if you meet those conditions for 5 seconds you have landed.

 

For the Gazelle there is a condition Type ; X: Cockpit Param Equal To

Param ; IS_LANDED (type this in)

Value ; 1


Edited by DarkCrow
  • Like 1
Link to comment
Share on other sites

I should put my money where my mouth is and provide an example since it's more helpful, attached. One thing I noticed about events was that the landing event didn't fire when I did an advanced waypoint action of land. I'm still experimenting with that as I need it. But for the purposes of code, the example attached has 4 lines

PlaneAI = UNIT:FindByName("Pilot #001")
PlaneAI:HandleEvent( EVENTS.Land )
function PlaneAI:OnEventLand( EventData )
 trigger.action.setUserFlag(1, 1 )
 MESSAGE:New("The Helicopter landed",30,"MOOSE Event"):ToAll() 
end

The setting of the flag is completely superfluous because I wanted to show you how to feed that back into the ME anyway if you wanted to use that. So i did it and you can have your playsound and whatever else you wanted to activate like a flare...bleh just an example. Might be useful for someone searching.

Also here is a link to the thread with the Huey's Cockpit Parameters Guide: https://forums.eagle.ru/showthread.php?t=143017&highlight=Huey+Cockpit+Parameters

Landing event.miz

___________________________________________________________________________

SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING *

Link to comment
Share on other sites

Thank you all for your tips!

 

It was something in the style of what DarkFire and DarkCrow described I was planning to do with ordinary conditions, I did not know that you could set the vertical speed to decimals I thought that 1 was min/max. I also opened Pikeys file, I dont know if I understand correct but for this specific case i assume it would work for me if I would load Moose.lua at mission start exactly as you did and add the do script code you posted, it would be the simplest way in that case. I downloaded MOOSE by the way, I will try to get into it when I have more time, its the stuff in the beginning of the user guide with setting up project folders and stuff I dont really understand.

Link to comment
Share on other sites

I should put my money where my mouth is and provide an example since it's more helpful, attached. One thing I noticed about events was that the landing event didn't fire when I did an advanced waypoint action of land. I'm still experimenting with that as I need it. But for the purposes of code, the example attached has 4 lines

PlaneAI = UNIT:FindByName("Pilot #001")
PlaneAI:HandleEvent( EVENTS.Land )
function PlaneAI:OnEventLand( EventData )
 trigger.action.setUserFlag(1, 1 )
 MESSAGE:New("The Helicopter landed",30,"MOOSE Event"):ToAll() 
end

The setting of the flag is completely superfluous because I wanted to show you how to feed that back into the ME anyway if you wanted to use that. So i did it and you can have your playsound and whatever else you wanted to activate like a flare...bleh just an example. Might be useful for someone searching.

 

Thanks for posting this. I have used Mist a little bit and do want to learn some more lua scripting so this will be helpful to me in future mission builds. I simplifies it for sure.

Link to comment
Share on other sites

What about this?

 

 world.addEventHandler(LandingHandler)

 function LandingHandler:onEvent(event)
   
 if event.id == world.event.S_EVENT_LAND then
   
       local unit = event.initiator
       if unit and unit:getGroup() then
           if string.find(unit:getGroup():getName(), "My plane group") then
         
            end
       end
     end
 end


Edited by sea2sky
  • Like 1

i5-9600K@4.8GHz 32Gb DDR4 Asus TUF rtx3080 OC Quest Pro Warthog on Virpil base

Link to comment
Share on other sites

What about this?

 

 world.addEventHandler(LandingHandler)

 function LandingHandler:onEvent(event)
   
 if event.id == world.event.S_EVENT_LAND then
   
       local unit = event.initiator
       if unit and unit:getGroup() then
           if string.find(unit:getGroup():getName(), "My plane group") then
         
            end
       end
     end
 end

 

I just plugged that code into zerobrane and didn't get any syntax errors but how could we use that to trigger something or set a flag?

 

If I just "do script file" I don't see where this causes any conditions we could use in the ME.

It's my understanding that using a script as a condition doesn't work properly. Am I just not seeing something here?

Link to comment
Share on other sites

I just plugged that code into zerobrane and didn't get any syntax errors but how could we use that to trigger something or set a flag?

 

If I just "do script file" I don't see where this causes any conditions we could use in the ME.

It's my understanding that using a script as a condition doesn't work properly. Am I just not seeing something here?

 

as an option, you can set a user flag:

 


world.addEventHandler(LandingHandler)    

function LandingHandler:onEvent(event)        
  if event.id == world.event.S_EVENT_LAND then              
    local unit = event.initiator         
    if unit and unit:getGroup() then             
       if string.find(unit:getGroup():getName(), "My plane group") then                
        trigger.action.setUserFlag('MyFlag', 1)              
       end         
     end       
    end   
end

 

Also, run (DO SCRIPT) this code on the mission start condition.


Edited by sea2sky

i5-9600K@4.8GHz 32Gb DDR4 Asus TUF rtx3080 OC Quest Pro Warthog on Virpil base

Link to comment
Share on other sites

I'm getting an error message:

Error.PNG.23396b5fba01abf270d7703c768b9ad9.PNG

 

Also if we ran the script at start we would already be landed and the flag would become true. Alternatively we could run the script when in a zone but I'm still getting the error.


Edited by DarkCrow
Link to comment
Share on other sites

[Rephrased]Apart from the error, remember event handlers just tell you what happens when it happens, they tell you nothing on a state. Ie it's LANDING, not landed and Takeoff, not airborne. If the plane does it multiple times the event is still collected as it happens. So generally you need some other logic to decide if its the right event that you want. Eg, the takeoff will fire, but if you bunny hop, it goes twice. So that's an added complexity. The event handler above only looks for the plane you want and tells you when, each time, its wheels hit the tarmac, nothing else, that's up to you. If you feed the flags back and forward and update them you can use them as ME conditions however you please.

I've not had an issue with similar code, not good enough to say what might have happened.

I'm getting an error message:

[ATTACH]160314[/ATTACH]

 

Also if we ran the script at start we would already be landed and the flag would become true. Alternatively we could run the script when in a zone but I'm still getting the error.


Edited by Pikey
rephrased
  • Like 1

___________________________________________________________________________

SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING *

Link to comment
Share on other sites

Pikey,

 

I managed to set it up with your script and MOOSE and it worked fine in my own mission!

 

I have a question though,

I want the condition to be so that if the player has completed his mission and is undamaged he must land and taxi to parking with the aircraft still undamaged. I can set this up now with the script you provided, but I also want to set up a condition so that if he is damaged it is ok to land very hard and break gears etc so long that he is alive and comes to a stop inside a predefined zone. A emergency landing so to speak. Does your script allow for a landing that causes damage to the aircraft or does that count as a crash? If so is there a similar condition for a crash that I can use?

Link to comment
Share on other sites

[Rephrased]Apart from the error, remember event handlers just tell you what happens when it happens, they tell you nothing on a state. Ie it's LANDING, not landed and Takeoff, not airborne. If the plane does it multiple times the event is still collected as it happens. So generally you need some other logic to decide if its the right event that you want. Eg, the takeoff will fire, but if you bunny hop, it goes twice. So that's an added complexity. The event handler above only looks for the plane you want and tells you when, each time, its wheels hit the tarmac, nothing else, that's up to you. If you feed the flags back and forward and update them you can use them as ME conditions however you please.

I've not had an issue with similar code, not good enough to say what might have happened.

 

 

 

I see what you're saying I believe. So it shouldn't trigger the flag by running the script at the start of the mission because it's not looking to whether you are landed but the actual event of landing.

 

Well still I wonder where the error is coming from. Maybe I'll try it in 1.5 later and see if it works.

 

 

Sent from my iPhone using Tapatalk

Link to comment
Share on other sites

I'm getting an error message:

[ATTACH]160314[/ATTACH]

 

Also if we ran the script at start we would already be landed and the flag would become true. Alternatively we could run the script when in a zone but I'm still getting the error.

 

Sorry, I'm cutting these examples out from a bigger script, so some modifications need to be done. Try what happens if you arrange the code this way:

 

do

function LandingHandler:onEvent(event)            
  if event.id == world.event.S_EVENT_LAND then                    
    local unit = event.initiator               
    if unit and unit:getGroup() then                      
      if string.find(unit:getGroup():getName(), "My plane group") then                                         
        trigger.action.setUserFlag('MyFlag', 1)                       
      end                
    end             
  end    
end

world.addEventHandler(LandingHandler)    

end

i5-9600K@4.8GHz 32Gb DDR4 Asus TUF rtx3080 OC Quest Pro Warthog on Virpil base

Link to comment
Share on other sites

Hi,

The Moose script and the event handler are both the same thing (MOOSE script just wraps the event handler into objects so you can refer to them later and provides a scripting structure with many other functions sharing the objects.

 

To answer your question, DCS regards a "landing" as something where the model meets the ground from the air inside an airport boundary and doesnt end up in death of the unit (as far as years of playing tells me). Taxiway and grass landings that rip gear off and the pilot then ejects still count as a DCS landing. Many times a landing event is triggered with a damaged aircraft or not hitting the runway. We have to deal with the way ED defines this. if you want MORE then you need to start adding those conditions, for example using exact zones.

 

I think if I were designing this based on what you say, I would look for an ENGINE SHUTDOWN event in a zone by the unit. It's likely more realistic and will make the player more happy about taking the time to taxi to parking and shutdown.

 

The ME doesn't give you the engine shutdown event to work with, it gives others but not this.

 

And here we go, seeing the ME and thinking we can nail everything, then it promises you something achievable but drags you in to something more and more complex you can't achieve unless you write some lines of code!

 

Does that help?

Pikey,

 

I managed to set it up with your script and MOOSE and it worked fine in my own mission!

 

I have a question though,

I want the condition to be so that if the player has completed his mission and is undamaged he must land and taxi to parking with the aircraft still undamaged. I can set this up now with the script you provided, but I also want to set up a condition so that if he is damaged it is ok to land very hard and break gears etc so long that he is alive and comes to a stop inside a predefined zone. A emergency landing so to speak. Does your script allow for a landing that causes damage to the aircraft or does that count as a crash? If so is there a similar condition for a crash that I can use?

___________________________________________________________________________

SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING *

Link to comment
Share on other sites

  • Recently Browsing   0 members

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