Jump to content

[Script]Explode Missed AI A2A Missiles


Recommended Posts

Current AI fighters in DCS have a quirk that has existed for quite a long time that boils down to the AI aircraft only firing one missile at a given target at a time. Once the missile is removed, the AI would fire again. Before the Advanced Flight Model Missiles were added any missile that wasn't guiding to a target would simply self destruct at somepoint. With the AFM-M the missiles simply fall back to the ground. Thus AI air combat exhibits rather odd behavior of not engaging the enemy in the time it takes a missile to fall to the ground. It is a bug that has been reported to the relevant developers, but I decided to try and fix it mission scripting side.

 

All this script does is it tracks A2A missiles fired by AI, and once the missile is no longer tracking a target for a short period of time, the missile is destroyed. As a result the AI shooter can more quickly follow up with successive shots. This script doesn't change any other AI behavior. The noticeable difference with this script running is that the AI fire more missiles and AI won't as easily get to the merge with each other.

 

There is a single option available.

 

remove_missile_method = 0 or 1

if it equals 0 then the missile will self destruct via an explosion of the same explosive mass of the missile

if it equals 1 then the missile is removed from the simulation world with Object.destroy() this means the missile will simply vanish in mid air.

 

do
-- Explode Missed AI A2A Missiles - by Grimes

local remove_missile_method = 0
-- 0 will create an explosion
-- 1 will use Object.destroy() which simply makes the missile disappear.


local aiMissiles = {}
local numActive = 0
local uid = 1
local idNum = 1
local function simpleEvent(f) -- from mist
	local handler = {}
	idNum = idNum + 1
	handler.id = idNum
	handler.f = f
	handler.onEvent = function(self, event)
		self.f(event)
	end
	world.addEventHandler(handler)
end

getMag = function(vec) -- from mist
	return (vec.x^2 + vec.y^2 + vec.z^2)^0.5
end

local function removeMis(id)
	if Object.isExist(aiMissiles[id].missile) then -- if missile is still active and needs to be destroyed
		if remove_missile_method == 0 then
			trigger.action.explosion(Object.getPosition(aiMissiles[id].missile).p, Weapon.getDesc(aiMissiles[id].missile).warhead.explosiveMass)
		else
			Object.destroy(aiMissiles[id].missile)
		end
	end
	aiMissiles[id] = nil
	numActive = numActive - 1
	
	return
end

local function aiShot(event)
	
	if event.id == world.event.S_EVENT_SHOT and event.initiator and not Unit.getPlayerName(event.initiator) then -- if AI
		if event.weapon and Weapon.getDesc(event.weapon).missileCategory and Weapon.getDesc(event.weapon).missileCategory == 1 then
			local newMis = {}
			newMis.launchTime = timer.getTime()
			newMis.uid = uid
			newMis.missile = event.weapon
			newMis.origTarg = Weapon.getTarget(event.weapon):getName()
			newMis.lostTrack = false
			aiMissiles[uid] = newMis
			uid = uid + 1
			numActive = numActive + 1
		end			
	end		
end
simpleEvent(aiShot)
local function checkMis()
	if numActive > 0 then
		for index, data in pairs(aiMissiles) do
			if not Object.isExist(data.missile) then
				removeMis(index)
			else
				local caseToRemove = false
				if data.lostTrack == false and not Weapon.getTarget(data.missile) then -- missile hasnt lost track before, and is currently not tracking
					data.lostTrackAtTime = timer.getTime()
					data.lostTrack = true
				elseif data.lostTrack == true then -- missile already lost track 
					if Weapon.getTarget(data.missile) then -- missile reaquired a target
						if getMag(Weapon.getTarget(data.missile):getVelocity()) < getMag(Object.getVelocity(data.missile)) then
							data.lostTrack = false
						else
							caseToRemove = true
						end
					else -- missile still lost
						if Weapon.getDesc(data.missile).guidance == 3 then -- its active so give it a chance to track
							if data.lostTrackAtTime + math.random(3, 8) + math.random() < timer.getTime() then -- random chance to not remove the missile. longer missile is alive, greater chance of destruction
								caseToRemove = true
							end	
						else 
							if data.lostTrackAtTime + math.random(1, 4) + math.random() < timer.getTime() then -- every other type of missile
								caseToRemove = true
							end
						end		
					end
									
				else
					if data.lostTrack == true then
						data.lostTrack = false
						data.lostTrackAtTime = 0
					end
				end
				if caseToRemove == true then
					removeMis(index)
				end
			end

		end
	end
	timer.scheduleFunction(checkMis, {}, timer.getTime() + 0.65)
end
env.info('Explode Missed AI A2A Missile Script by Grimes Loaded')
checkMis()
end

 

The script is small enough that you can copy and paste it into a "do script" box and it relies on no other scripts to function correctly. Feel free to modify it however you wish, just give credit if you publish it.


Edited by Grimes
  • Like 1

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting 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

I will be trying this out later today, sounds like it will work quite nicely with the GCI/CAP script....once again, Great Work Grimes...

 

 

...must spread rep....sorry....looks like I rep the same few script builders....I need to scroll through the other forums, I guess...


Edited by Davis0079

It only takes two things to fly, Airspeed and Money.

Link to comment
Share on other sites

I just want to bump this.....after testing, I will say this script has really brought A2A a step in the right direction for DCS...I can't believe more ppl aren't posting here...the AI does multiple missile every merge and after the merge the heaters are all over the place, it really wakes up BVR and WVR...

 

...This script is a must for anyone dogfighting the AI in the mission editor...I did have to make it into a .lua file and use the do script file for some reason...but after putting it on a Once, Time more (5), do script file, everything worked great...

 

...another homerun Grimes....my single player map has your name all over it now....and its getting very aggressive...

 

...if you could only get them to abandon the missiles that run out of energy....if you dont break the lock, they will stay with it even though its doing 150knots and you are leaving it at 500knots....maybe something like once the distance from missile to target stops decreasing and starting increasing for a few seconds (or longer???), the missile should be destroyed (maybe one day abandoned, not destroyed) ...


Edited by Davis0079

It only takes two things to fly, Airspeed and Money.

Link to comment
Share on other sites

There's already a check on the missile speed that will remove missiles that are slower than their target. It still doesn't help much against AI launching missile at R_aero and then waiting for the missile to slow down though. Maybe also missiles launched before sensible launch distance should be removed when AI plane gets into good launch parameters. This is much harder to do but it would actually make a big difference in AI lethality.

DCS Finland: Suomalainen DCS yhteisö -- Finnish DCS community

--------------------------------------------------

SF Squadron

Link to comment
Share on other sites

It doesn't hurt to have multiple solutions to the same problem. :)

 

 

Removing missiles launched before a sensible launch distance will just prompt the AI to re-engage as soon as possible. I think the big difference in AI lethality would have to come with a script to micro-manage AI engagement decisions by changing their tasking, ROE, etc multiple times per engagement. It is doable, but complex.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting 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

My idea was to remove the R_aero missile only after the AI is within lethal range so that it will waste only one missile. But of course altering ROE or some other method that prevents the firing altogether before in sensible range is much better solution.

DCS Finland: Suomalainen DCS yhteisö -- Finnish DCS community

--------------------------------------------------

SF Squadron

Link to comment
Share on other sites

  • 3 months later...

Alright, its been 4 days and no one has answer you. I searched. I know I've typed it before. I know for fact I asked once and it got typed for me. But, for some reason I cant find it and just copy it, paste it here.

 

So here it is. C:\Program Files\Eagle Dynamics\DCS World\Doc\DCS User Manual page80 .....just kidding....

 

In the mission editor on the left of the screen from top to bottom has a "file" category, a "mission" category, an "object" category, and a "map" category. In the mission category, the third one down says "set rules for triggers". This is where the magic happens. When clicked on, it opens a window that has three sections called "triggers", "conditions", and "action". You must set these three things up correctly for any script to run.

 

An easy way to do this is for "trigger", use the forth option "4 mission start". Leave conditions empty. And under actions, select the drop down menu, scroll down to "do script" and copy/paste the script that Grimes posted in the first post.

 

Be fairly warned that I am no script writer nor am I a mission builder. The best info anyone can give you is to read what the author of the script says closely (maybe doesn't help in this situation), read the DCS user manual (the mission editor part is most helpful). And read the Mission Editing Wiki (can be overwhelming and even unclear to a new mission builder, but has all the info needed).

 

Good luck.


Edited by Davis0079

It only takes two things to fly, Airspeed and Money.

Link to comment
Share on other sites

Alright, its been 4 days and no one has answer you. I searched. I know I've typed it before. I know for fact I asked once and it got typed for me. But, for some reason I cant find it and just copy it, paste it here.

 

So here it is. C:\Program Files\Eagle Dynamics\DCS World\Doc\DCS User Manual page80 .....just kidding....

 

In the mission editor on the left of the screen from top to bottom has a "file" category, a "mission" category, an "object" category, and a "map" category. In the mission category, the third one down says "set rules for triggers". This is where the magic happens. When clicked on, it opens a window that has three sections called "triggers", "conditions", and "action". You must set these three things up correctly for any script to run.

 

An easy way to do this is for "trigger", use the forth option "4 mission start". Leave conditions empty. And under actions, select the drop down menu, scroll down to "do script" and copy/paste the script that Grimes posted in the first post.

 

Be fairly warned that I am no script writer nor am I a mission builder. The best info anyone can give you is to read what the author of the script says closely (maybe doesn't help in this situation), read the DCS user manual (the mission editor part is most helpful). And read the Mission Editing Wiki (can be overwhelming and even unclear to a new mission builder, but has all the info needed).

 

Good luck.

 

Thanks for that. I wasn't aware there was anything on the mission editor in the manual :doh:

Link to comment
Share on other sites

  • 10 months later...
Sadly this doesn't seem to be working. If 0 is selected missiles don't explode, if 1 is selected you get a error on mission start

 

The script isn't really needed anymore due to the bug preventing AI from re-engaging when a missile still exists has been fixed for quite some time. That said the script should still work, however I am able to reproduce the error message. But am at a total loss as it doesn't make any sense. The simple act of changing a 0 to a 1 should not be causing any sort of error at all.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting 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

  • Recently Browsing   0 members

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