Grimes Beta Tester



Join Date: Jan 2006 Location: Black Mesa Posts: 8,198

[Script]Explode Missed AI A2A Missiles



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.



Code: 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 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 1if it equals 0 then the missile will self destruct via an explosion of the same explosive mass of the missileif 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.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.

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

Current Projects: Scripting Wiki, Something...

Useful Links: Mission Scripting Tools MIST-(Thread), SLMOD for DCS 1.5/2.0, IADScript, Mission Editing Wiki!, Mission Building Forum __________________The right man in the wrong place makes all the difference in the world.Useful Links: Mission Scripting Tools MIST-(GitHub) Last edited by Grimes; 07-28-2014 at 04:13 AM .