Jump to content

Recommended Posts

Posted

I want to make a mission where tanks are in cover until they shoot. My idea was to have them set to invisible (which makes them invisible to other AI, not to players) and then have a triggered action to AI task push>do command>invisible off, when they fire. This would be useful for simulating an ambush, which at present isn't easy to do given the AI's efficiency in spotting.

My problem is that there doesn't seem to be a "unit fired" or "unit has shot" condition. Since the game log registers each unit shot event, I imagine this would be fairly easy to implement? A "part of group has shot" would also be a useful condition.

Posted (edited)

What you are trying to accomplish may be possible, and it may require some Lua - and probably a slightly different way of looking at the mission. Often, (at least to me) creating a mission becomes easier when I'm looking at what I'm trying to accomplish rather than how things would work in the real world.

Now, if you want to simulate an ambush, you can always use late activation, which would hide the units from everyone (because they aren't on the map until you activate them). If the mission's goal is to prevent the ambush, then the players must be able to see and destroy those units, so late activation would not work in this case.

5 hours ago, Rolds said:

My problem is that there doesn't seem to be a "unit fired" or "unit has shot" condition. Since the game log registers each unit shot event, I imagine this would be fairly easy to implement?

It is, but only if you add some Lua scripting. There you can sign up to be notified if a unit fires a weapon (except for machine gun or autocannon). When you receive that notification, you perform some checks that the unit that fired indeed belongs to the group that you are interested in, and then you do the rest of the stuff that you are interested in. Depending on your level of Lua expertise in general and DCS mission scripting in particular, doing this experience can range from easy to painful indeed. I'd be happy to lend a hand. Below is a rough skeleton (untested, writing this on the road) that simply prints out whenever a unit shoots a weapons and tells you the unit's name and what weapon it used.

fmon = {}
function fmon:onEvent(event)
	if not event then return end -- sanity check 
	if not event.initiator then return end -- more sanity 
	if not event.weapon then return end 
	if event.id == 1 then -- S_EVENT_SHOT
		local theUnit = event.initiator 
		local who = theUnit:getName()
		local theWeapon = event.weapon 
		local what = theWeapon:getTypeName()
		trigger.action.outText("Unit <" .. who .. "> fired <" .. what .. ">", 30)
	end
end

world.addEventHandler(fmon)

Above code is just the beginning to get you started. Add it as a DOSCRIPT action AT START. You'd now have to check if theUnit belongs to the group that you are interested in, and then act appropriately. This is just to get you started. If you want some more ideas, or aren't yet that confident in writing Lua, just holler. Be advised, though: writing Lua for DCS missions is highly addictive. To protect us, ED have added some hurdles to discourage normal player and prevent them from catching the habit.

Edited by cfrag
Posted

Oh dear, this is too much. I just want a triggered action so units can say "they're shooting at us!" and stuff like that. Your example is more complicated than any mission I've made!

  • Like 1
  • 4 weeks later...
Posted (edited)

It doesn't fix the issue of the new trigger, but in that situation I would use "unit life less than ___%", and have it set to "less than 100%" for the vehicles in the convoy.

Other options include "unit damaged" or "unit hits successful". It's still not perfect since all of these require a damaging hit, but it's reasonably close I think.

Edited by SabreDancer
Posted (edited)
On 12/6/2023 at 8:29 AM, cfrag said:
fmon = {}
function fmon:onEvent(event)
	if not event then return end -- sanity check 
	if not event.initiator then return end -- more sanity 
	if not event.weapon then return end 
	if event.id == 1 then -- S_EVENT_SHOT
		local theUnit = event.initiator 
		local who = theUnit:getName()
		local theWeapon = event.weapon 
		local what = theWeapon:getTypeName()
		trigger.action.outText("Unit <" .. who .. "> fired <" .. what .. ">", 30)
	end
end

world.addEventHandler(fmon)

Above code is just the beginning to get you started. Add it as a DOSCRIPT action AT START. You'd now have to check if theUnit belongs to the group that you are interested in, and then act appropriately. This is just to get you started. If you want some more ideas, or aren't yet that confident in writing Lua, just holler. Be advised, though: writing Lua for DCS missions is highly addictive. To protect us, ED have added some hurdles to discourage normal player and prevent them from catching the habit.

 

Would this code work for example if I want an aircraft to report Fox Two every time they fire a Sidewinder?

Edited by JonathanRL

signature.png

Posted
11 minutes ago, JonathanRL said:

Would this code work for example if I want an aircraft to report Fox Two every time a Sidewinder is launched?

Yes, and it would require some adaptation to report only when an AIM-9 is fired. But - depending on what you want to achieve - those changes will be quite small.

Posted

To return to the topic at hand, I would love an official trigger on the topic where the trigger is "Unit has fired" and the you can select either weapon category or a specific weapon.
Would be awesome for us who want to use voice actors to call out weapon releases.

signature.png

  • 5 months later...
Posted

Thirded, the "Gulf Guardian" mission for the F-4E has this feature using a script, and it's a really nice affordance for the player to have their back seater or wingman call out a missile for them. I've been trying to make this work for a mission where a "peacetime" interception turns into a fight, so it's not enough to use a "unit damaged" trigger, I need the callout to happen when the missile is off the rail. For now I have an unreliable hack trigger instead.

  • Recently Browsing   0 members

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