Jump to content

Kill, explode, or crash a unit via mission scripting (by invoking trigger action)


Go to solution Solved by cfrag,

Recommended Posts

Posted (edited)

I'm looking for a way to immersively take an (aerial) unit off the board via mission scripting. By immersive I mean killing the crew/pilot, ejecting the crew/pilot, crashing the unit into the ground, stopping its engines (e.g., by removing all fuel), or -- as a last resort -- exploding it mid-air. My application is the removal of units that aborted their mission to keep them from returning home. Example code run via a MISSION START trigger DO SCRIPT action (NOTE: only use a single removal method at a time):

local eh = {}
function eh:onEvent(event)
    if event.id == world.event.S_EVENT_AI_ABORT_MISSION then
        -- FIXME: unit vanishes into thin air -> lame
        event.initiator:destroy()

        -- FIXME: brute force approach. will it work reliably in multiplayer with desync/lag?
        trigger.action.explosion(event.initiator:getPoint(), 10)

        -- FIXME: not available from the mission scripting environment (i.e., a_do_script())
        a_unit_set_life_percentage(event.initiator:getID(), 0)
        a_explosion_unit(event.initiator:getID(), 10)
    end
end
world.addEventHandler(eh)

I do not want to vanish the unit via :destroy() and trigger.action.explosion() feels very brutal and prone to fail in multiplayer. DCS actually comes with ways to kill the unit by setting its life to 0% (forces crew ejection) and selectively exploding it via trigger actions:

image.png

However, neither is available from the mission scripting environment via trigger.action.*(). Digging inside the mission_file.miz/mission lua code reveals the two functions a_unit_set_life_percentage(2, 0) and a_explosion_unit(2, 10). Unfortunately, neither is available from the mission scripting environment (i.e., a_do_script()), with above code resulting in:

2025-02-01 04:56:11.955 ERROR   SCRIPTING (Main): Mission script error: ... attempt to call global 'a_unit_set_life_percentage' (a nil value)

Is anyone aware of a way to access the UNIT AI SET LIFE and/or EXPLODE UNIT trigger actions via mission scripting, e.g., above event handler?

Edited by Actium
added :getID()
  • Solution
Posted (edited)
5 hours ago, Actium said:

I'm looking for a way to immersively take an (aerial) unit off the board via mission scripting. By immersive I mean killing the crew/pilot, ejecting the crew/pilot, crashing the unit into the ground, stopping its engines (e.g., by removing all fuel), or -- as a last resort -- exploding it mid-air.

Since we currently cannot influence AI or AI units in a meaningful way (except through drastic ways just like the ones that you suggested), your approach seems to be workable. Setting zero fuel should get most AI planes to have the pilots bail out and the plane plummet to ground - if that was possible (spoiler: it's not). The good old explosion(unit:getPoint(), 30) should also do it, albeit a  bit more visceral.

5 hours ago, Actium said:

My application is the removal of units that aborted their mission to keep them from returning home.

Ah, then an explosion seems fitting 🙂 

5 hours ago, Actium said:
if event.id == world.event.S_EVENT_AI_ABORT_MISSION

I think (and that does not mean a lot) that current implementation of unit AI only kicks in with that event when the unit runs out of fuel (? undocumented) or damage (somewhat documented). So, re-top up regularly so they don't run dry.

The spanner in the works is of course that we currently cannot set a unit's fuel nor life. A colossal oversight for a military sim scripting engine, but that's DCS for you.

5 hours ago, Actium said:

trigger.action.explosion() feels very brutal and prone to fail in multiplayer.

It won't fail in MP. The script runs on the server, and all clients sync to the server eventually. If the server thinks that a unit is dead, it is dead and removed from all clients). It will work in MP. IMHO, the most reliable way to remove a unit is destroy(), but 'setting them up the bomb' by explosion() is a lot more satisfying, and you can probably forego the destroy() yourself (schedule a timed destroy() two minutes in the future just in case)

5 hours ago, Actium said:

Is anyone aware of a way to access the UNIT AI SET LIFE and/or EXPLODE UNIT trigger actions via mission scripting, e.g., above event handler?

There is the kludge approach: in the event handler that detects the unit aborting, set a named flag (I use the unit's name plus "_k" to keep this part short). Then create a trigger rule for every (messy, messy, messy!) unit that triggers on that named flag (e.g. FLAG TRUE "aerial-1-1_k") to execute the trigger for the actions (unit set life, explode). So, if you have 20 units that can abandon the mission, you'll have to create 20 separate trigger rules, one per unit. Very kludgy, very messy, extremely difficult to maintain, and wholly depressing from a scripting perspective. It really is a shame that DCS's mission scripting environment is in such a bad, amateurish state.

Edited by cfrag
  • Thanks 1
Posted (edited)

@Actium / @cfrag

Actium, I think cfrag is being very modest here.

I don't know if you are aware but he has written a brilliant utility called DML that does not require any scripting skill from the user. 

One of the modules is a clone feature (to put the AI on the map). This has a parameter called "despawnin" (see below), trigger a flag and boom, they are gone.

There is also another parameter called deClone which may be actually better for your purpose;

nullCheck out his thread here;

 

image.pngnull

image.png

Edited by DD_Friar
  • Thanks 1

Visit the Dangerdogz at www.dangerdogz.com. We are a group based on having fun (no command structure, no expectations of attendance, no formal skills required, that is not to say we can not get serious for special events, of which we have many). We play DCS and IL2 GBS. We have two groups one based in North America / Canada and one UK / Europe. Come check us out. 

Posted

Thanks @cfrag and @DD_Friar! I had a gut feeling I had exhausted DCS' limited scripting options and wanted to confirm that. The one trigger per unit kludge is not a viable option for me, because >100 units are involved. I guess I'll opt for just 'sploding the deserting units.

6 hours ago, DD_Friar said:

Actium, I think cfrag is being very modest here.

I tend to agree 😆. I've read dozens of his forum posts, typically including justified yet entertaining criticism of DCS' desolate mission scripting state. Today's post did not disappoint 🤣
I come from the very first ArmA, which was also painful to script with, but DCS appears to play in a wholly different league.

  • Recently Browsing   0 members

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