Jump to content

how to fire trigger on unit "defeated" (dead or significantly damaged)


twistking

Recommended Posts

On 5/26/2023 at 4:06 AM, twistking said:

how can i set up a trigger that fires, if an AI group/flight is "defeated" meaning it has no combat capable aircraft left, even if it has still aircraft in the air (damaged, out of ammo, retreating etc).

Thanks.

This is untested, but you could iterate through each unit in the group - check what is still alive, and then use a combination of:

UNIT:GetDamageRelative()  and  UNIT:GetAmmo()

... to check the damage to each unit and to get the ammo count, and come to a conclusion from those values.

I'm not sure how to check however (or even if it's possible) whether a group is now tasked for RTB (which is probably what you're wanting to check to see if it's retreating). 


Edited by Dangerzone
  • Thanks 1
Link to comment
Share on other sites

8 hours ago, Dangerzone said:

This is untested, but you could iterate through each unit in the group - check what is still alive, and then use a combination of:

UNIT:GetDamageRelative()  and  UNIT:GetAmmo()

... to check the damage to each unit and to get the ammo count, and come to a conclusion from those values.

I'm not sure how to check however (or even if it's possible) whether a group is now tasked for RTB (which is probably what you're wanting to check to see if it's retreating). 

 

Thanks for the answer. Will have a lok at it. I fear this will be a bit too complicated for me to pull off (not really good with lua, so i'm still using the ME script "blocks" exclusively), but maybe i will give it a try anyway!

Link to comment
Share on other sites

13 hours ago, twistking said:

Thanks for the answer. Will have a lok at it. I fear this will be a bit too complicated for me to pull off (not really good with lua, so i'm still using the ME script "blocks" exclusively), but maybe i will give it a try anyway!

There's not much difference between using the blocks and a lua file to be honest.  A lua file simply makes it easier to edit/read what you're doing as opposed to doing it in the mission editor blocks.

Likewise, doing it in a file - you could have a menu in DCS that is a 'dofile' for your script, so you run it through the F10 menu, and if it fails, instead of having to go out, back to the mission editor, change, and then relaunch - you simply edit your file while DCS is running, save it and re-do the F10 menu again - giving you an instant 're-run' option of your script. 

But either way - unfortunately what you're trying to achieve is going to be difficult. There's no native way of doing it, and even with that lua stuff - there's no clear path I can see - it would be a matter of spending a number of hours trying stuff to see what works. 

Link to comment
Share on other sites

11 hours ago, Dangerzone said:

There's not much difference between using the blocks and a lua file to be honest.  A lua file simply makes it easier to edit/read what you're doing as opposed to doing it in the mission editor blocks.

Likewise, doing it in a file - you could have a menu in DCS that is a 'dofile' for your script, so you run it through the F10 menu, and if it fails, instead of having to go out, back to the mission editor, change, and then relaunch - you simply edit your file while DCS is running, save it and re-do the F10 menu again - giving you an instant 're-run' option of your script. 

But either way - unfortunately what you're trying to achieve is going to be difficult. There's no native way of doing it, and even with that lua stuff - there's no clear path I can see - it would be a matter of spending a number of hours trying stuff to see what works. 

Thanks for the answer. I have found a workaround for now: Basically checking if player unit is still alive and if in certain conditions and then with timers for delay just concluding (guessing) that enemies must be dead (or retreated). Simple and good enough for what i need.

Your post make me a bit more interested in getting to start with LUA. Do you know a simple tutorial that simply recreates some triggers from the "trigger block". Basically just like "if condition x, then make AI do y and set flag a to b"? Also is there a database with scripting commands? I'm relatively used to scripting for ARMA and for that there is a very nice offical glossary with every command, explanation and even user commands/examples. Anything even remotely similar for DCS?

Thanks.

  • Like 1
Link to comment
Share on other sites

10 hours ago, twistking said:

Thanks for the answer. I have found a workaround for now: Basically checking if player unit is still alive and if in certain conditions and then with timers for delay just concluding (guessing) that enemies must be dead (or retreated). Simple and good enough for what i need.

Your post make me a bit more interested in getting to start with LUA. Do you know a simple tutorial that simply recreates some triggers from the "trigger block". Basically just like "if condition x, then make AI do y and set flag a to b"? Also is there a database with scripting commands? I'm relatively used to scripting for ARMA and for that there is a very nice offical glossary with every command, explanation and even user commands/examples. Anything even remotely similar for DCS?

Thanks.

There may be more than one way to skin a cat, but for most of what I've experienced with lua - I don't use triggers. Instead I use event handlers (which I'm assuming might be a lower level of what is used for the trigger side of things anyway). 

As for tutorials, there's a number on the internet. I don't really have any off the top of my head that stand out. It's probably a matter of having a bit of a dabble and see how you go.

The first thing that I had to learn was that running some files don't actually "Do anything" - all they do is load additional functions that you can use after that into memory. (MIST and MOOSE are classic examples of this - you can add them to your mission and nothing changes until you actually start calling the functions). These are basically a library that needs to be utilised before they do anything.

Other scripts aren't libraries as such - but active scripts. If we go back to talking about events, a simple example of this is EVENTS.Dead.  You can hook the EVENTS.Dead event so everytime something becomes dead - it will trigger your function. 

This is an example of hooking EVENTS.Dead:

 

evh1 = EVENTHANDLER:New()
evh1:HandleEvent(EVENTS.Dead)
function evh1:OnEventDead(EventData)
  if EventData.IniDCSUnitName and string.match(string.upper(EventData.IniDCSUnitName), "HVT") then
      MESSAGE:New('Mission Complete', 30):ToAll() 
     trigger.action.outSound("win.ogg")
  end 
end --OnEventDead  / evh1

In the above - everytime the EVENT.Dead is triggered it will run this script. It checks the unit name. if the Unit name starts with "HVT" it will consider the mission a success, and play the win.ogg file (provided it is loaded into the mission editor) and display a message. (The message above uses MOOSE, but you can change this to use something else if you want). 

That same event handler can be expanded, so you can have multiple checks in the one event (or trigger) instead of 2 different triggers the one event is used to compare 2 different scenario's. ie:

 

evh1 = EVENTHANDLER:New()
evh1:HandleEvent(EVENTS.Dead)
function evh1:OnEventDead(EventData)
  if EventData.IniDCSUnitName and string.match(string.upper(EventData.IniDCSUnitName), "HVT") then
      MESSAGE:New('Mission Complete', 30):ToAll() 
     trigger.action.outSound("win.ogg")
  end 
  if EventData.IniDCSUnitName and string.match(string.upper(EventData.IniDCSUnitName), "DONTKILL") then
      MESSAGE:New('Mission FAILED', 30):ToAll() 
     trigger.action.outSound("failed.ogg")
  end   
end --OnEventDead  / evh1

This now does 2 checks - the second if the unit name starts with DONTKILL - and if so - it will fail the mission instead. 

The beauty about doing it this way is that I can have a whole bunch of these created in a single .lua file - and have it load on all of my missions. I don't have to redo any custom scripting - provided I use the unit names above, it will trigger. If I don't want certain things to trigger in one of my missions - I just don't name any units with that naming prefix. 

CFRAG has designed some cool stuff that doesn't require any lua coding at all that's probably worth checking out as well. I come from a programming background so I much prefer to type out all my code in a text editor rather than use a GUI with a bunch of checks and stuff so LUA fits me much better, but YMMV so before you get too invested, check out the different options that are available. 

The more you get comfortable with LUA, the more functions you can just dump in your "loader" on your misisons. There's some really good stuff out there including a disembark script (that basically once a vehicle is hit may have some troops jump out of the vehicle), CSAR (when an aircraft goes down it will auto-SPAWN pilots that can be rescued using helicopters, etc') - that are basically like the above, just hundreds more lines - but the beautiful thing is you don't need to know it - just load it in your mission and the functions just 'work'. 

Like the basic script above - many of these can be done just by running the script and it's fully automatic. (such as the original CSAR by Ciribob). Others are incorporated into MOOSE were all you do is run the MOOSE command, and then add a couple of extra lines to your mission just to 'start' certain functions that you want for that mission. 

I hope this is helpful.

  • Thanks 1
Link to comment
Share on other sites

  • Recently Browsing   0 members

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