Jump to content

Recommended Posts

Posted

Some time ago Grimes posted a script that would be great for training SAM evasion.

 

I am however unable to get it to run, thus would be very, very grateful if anyone could provide a simple mission where it is included and working?

 

And while I am at it; does this work for Air to Air missiles as well? Or could be made working with them??

 

Thank you!

-T

[sIGPIC][/sIGPIC]

Posted

It should work for any guided missile fired by AI. So that includes sams and a2a missiles. The script ignores missiles fired by players though.

training_missiles.miz

  • 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

Posted

It tracks guided missiles fired by AI and destroys the missile if it is about to hit the player's aircraft and then displays a message saying that the player would have been hit.

  • 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

Posted

Awesome! I hadn't seen this before, this is going to be SO useful for training missions! Thanks very much for posting this...

 

Edited to add: Could you possibly post the .lua script on its own please?

System Spec: Cooler Master Cosmos C700P Black Edition case. | AMD 5950X CPU | MSI RTX-3090 GPU | 32GB HyperX Predator PC4000 RAM | | TM Warthog stick & throttle | TrackIR 5 | Samsung 980 Pro NVMe 4 SSD 1TB (boot) | Samsung 870 QVO SSD 4TB (games) | Windows 10 Pro 64-bit.

 

Personal wish list: DCS: Su-27SM & DCS: Avro Vulcan.

Posted
do
   local remove_missile_method = 1
   -- 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
   
   get3DDist = function(point1, point2)
       return getMag({x = point1.x - point2.x, y = point1.y - point2.y, z = point1.z - point2.z})
   end
   
   local function removeMis(id)
       if Object.isExist(aiMissiles[id].missile) then -- if missile is still active and needs to be destroyed
           if Weapon.getTarget(aiMissiles[id].missile) == aiMissiles[id].origTarg and Unit.getPlayerName(aiMissiles[id].origTarg) then
               trigger.action.outText(Unit.getPlayerName(aiMissiles[id].origTarg) .. ' has been hit by a simulated missile. You should eject in shame.', 20)
           end
           if remove_missile_method == 0 then
               trigger.action.explosion(Object.getPosition(aiMissiles[id].missile).p, 5)
           else
               Object.destroy(aiMissiles[id].missile)
           end
       end
       aiMissiles[id] = nil
       numActive = numActive - 1
       
       return
   end
   local function checkMis(mis)
       local tot = 0
       
       if Object.isExist(mis.missile) == false then
           removeMis(mis.uid)
       else
           if Object.isExist(mis.origTarg) == true then
               local misVel = getMag(Object.getVelocity(mis.missile))
               local targVel = getMag(Object.getVelocity(mis.origTarg))
               local dist = get3DDist(Object.getPoint(mis.missile), Object.getPoint(mis.origTarg))
               if dist < 100 then -- if its close and still guiding
                   removeMis(mis.uid)
               else
                   tot = dist/(misVel*2)
                   timer.scheduleFunction(checkMis, mis, timer.getTime() + tot)
               end
           end        
       end
       
       
   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 == 2 or 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)
               newMis.lostTrack = false
               aiMissiles[uid] = newMis
               uid = uid + 1
               numActive = numActive + 1
               
               timer.scheduleFunction(checkMis, newMis, timer.getTime() + 4)
           end            
       end        
   end
   simpleEvent(aiShot)

   env.info('Training Sams by Grimes Loaded')
end

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

Posted
It should work for any guided missile fired by AI. So that includes sams and a2a missiles. The script ignores missiles fired by players though.

 

My Hero!

Thank you very much Sir! :)

 

Could it be modified to work with human fired A/A missiles??

[sIGPIC][/sIGPIC]

Posted

Sure modify it however you want. The modification needed depends on what you are trying to do. If you want to use it just for human a2a practice then remove the following from the function aiShot

 

and not Unit.getPlayerName(event.initiator)

 

If you want the script to work against AI targets then the removeMis function would need to be edited to remove the checks to see if the missile will hit a player in addition to the message that displays.

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

Posted
It tracks guided missiles fired by AI and destroys the missile if it is about to hit the player's aircraft and then displays a message saying that the player would have been hit.

 

Mmm, nice.

Posted
Sure modify it however you want. The modification needed depends on what you are trying to do. If you want to use it just for human a2a practice then remove the following from the function aiShot ...

 

If you say that it does sound easy :)

 

Yep, apart from SAM Evasion for the A-10s the idea is to have Air/ Air Training. With your Script and TacView we can have a couple of actual engagement including Missile Launch without the need to restart the mission.

 

A BIG Timesaver and it does visualize even better if there has been a hit or not.

 

So again thank you very much, most appreciated!

 

-T

[sIGPIC][/sIGPIC]

Posted (edited)

Excellent, thanks very much, I'll definitely be using this one...

 

One last question if I may: from reading the script, does this require MIST to be used & loaded prior to initialisation?

Edited by DarkFire

System Spec: Cooler Master Cosmos C700P Black Edition case. | AMD 5950X CPU | MSI RTX-3090 GPU | 32GB HyperX Predator PC4000 RAM | | TM Warthog stick & throttle | TrackIR 5 | Samsung 980 Pro NVMe 4 SSD 1TB (boot) | Samsung 870 QVO SSD 4TB (games) | Windows 10 Pro 64-bit.

 

Personal wish list: DCS: Su-27SM & DCS: Avro Vulcan.

Posted

In a way yeah it could be like a smokey sam system, but the main purpose is to just remove a missile before it hits its target for training purposes. Its still a fully threatening sam site with the same AI and stuff. Without a modded unit for a smokey sam I'm afraid thats the best we can do. In terms of gameplay the script achieves the same result.

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

  • 8 months later...
Posted
Sure modify it however you want. The modification needed depends on what you are trying to do. If you want to use it just for human a2a practice then remove the following from the function aiShot

 

and not Unit.getPlayerName(event.initiator)

 

If you want the script to work against AI targets then the removeMis function would need to be edited to remove the checks to see if the missile will hit a player in addition to the message that displays.

 

Grimes,

 

This script is working fine for AI missiles in 2.0 however it seems that it isn't working for client vs client missile shots after making the edit you mention above. Any ideas?

 

Here's the script as I'm trying it.

do
   local remove_missile_method = 1
   -- 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
   
   get3DDist = function(point1, point2)
       return getMag({x = point1.x - point2.x, y = point1.y - point2.y, z = point1.z - point2.z})
   end
   
   local function removeMis(id)
       if Object.isExist(aiMissiles[id].missile) then -- if missile is still active and needs to be destroyed
           if Weapon.getTarget(aiMissiles[id].missile) == aiMissiles[id].origTarg and Unit.getPlayerName(aiMissiles[id].origTarg) then
               trigger.action.outText(Unit.getPlayerName(aiMissiles[id].origTarg) .. ' has been hit by a missile.', 5)
           end
           if remove_missile_method == 0 then
               trigger.action.explosion(Object.getPosition(aiMissiles[id].missile).p, 5)
           else
               Object.destroy(aiMissiles[id].missile)
           end
       end
       aiMissiles[id] = nil
       numActive = numActive - 1
       
       return
   end
   local function checkMis(mis)
       local tot = 0
       
       if Object.isExist(mis.missile) == false then
           removeMis(mis.uid)
       else
           if Object.isExist(mis.origTarg) == true then
               local misVel = getMag(Object.getVelocity(mis.missile))
               local targVel = getMag(Object.getVelocity(mis.origTarg))
               local dist = get3DDist(Object.getPoint(mis.missile), Object.getPoint(mis.origTarg))
               if dist < 100 then -- if its close and still guiding
                   removeMis(mis.uid)
               else
                   tot = dist/(misVel*2)
                   timer.scheduleFunction(checkMis, mis, timer.getTime() + tot)
               end
           end        
       end
       
       
   end
   
   
   local function aiShot(event)
       
       if event.id == world.event.S_EVENT_SHOT and event.initiator then
           if event.weapon and Weapon.getDesc(event.weapon).missileCategory and (Weapon.getDesc(event.weapon).missileCategory == 2 or 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)
               newMis.lostTrack = false
               aiMissiles[uid] = newMis
               uid = uid + 1
               numActive = numActive + 1
               
               timer.scheduleFunction(checkMis, newMis, timer.getTime() + 4)
           end            
       end        
   end
   simpleEvent(aiShot)

   env.info('Training Sams by Grimes Loaded')
end

 

 

Posted
This script is working fine for AI missiles in 2.0 however it seems that it isn't working for client vs client missile shots after making the edit you mention above. Any ideas?

 

I don't have any guinea pigs available to test client on client handling of the script at the moment. But all it would take is a missing value that it needs to prevent it from working correctly. Check DCS.log on the server to see if it produced errors by trying to math on a nil value. If you are getting the "player was hit" message then the problem is will the missile being removed, could try changing the value to 0 to create a small explosion. I won't know for sure until I can get another person to help out to test it. If stuff works in SP it'll work for the host, but not necessarily for clients.

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

Posted

Thanks. I'll retest and have a look at logs over the weekend to see if there is anything.

 

It is working for clients against for AI fired missiles (SAMs tested) but it isn't working for either client or host fired AAMs when fired against another client/host. When it doesn't work the message box doesn't pop up either and DCS doesn't have any script errors so it seems to me like the script is doing its thing but perhaps a parameter isn't set right for it to work with clients. But really I'm clueless as to where to go next.

 

 

Posted

Well the script was created and tested for AI shot missiles. The only "config" for clients was the silly not getPlayerName() check to make sure it was an AI shooting. I'll see if I can drag someone into testing it. At the very least I'm a little happy to hear that issues are occurring with the host, that makes it a tad easier to test.

 

 

There is one other possibility which might be likely based on an assumption of the aircraft and missiles being used... Change the 4 in the following line to a very small number like 0.4. Basically the script has a 4 second delay before it actually starts checking if the missile will hit its target. I think I coded it this way so that if the AI shot a missile that was both close to the target and missed immediately, then the AI won't be inclined to do a follow-on shot and waste another missile.

 

timer.scheduleFunction(checkMis, newMis, timer.getTime() + 4)

  • 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

Posted

Hmm, the TOF for the AIM-9 test shots Stuka and I made were in at least some cases less than 4 seconds so that sounds like a plausible cause/solution indeed. Will give it a test as soon as I can find a willing victim.

 

Still have the DCS.log from last night's test and there are no errors reported, so it does seem that the script is doing what it's supposed to do, or at least DCS thinks it is.

 

One thing I have just picked up on when checking the ACMI recording is that one AIM-9 (client's) shows as being destroyed and not hitting anything (although it hit me). While my AIM-9 shows as having hit Stuka. It certainly seems like it's a MP specific issue. I really hope it's one that can be resolved, because this script could be a real game changer for training missions.

 

 

Posted
timer.scheduleFunction(checkMis, newMis, timer.getTime() + 4)

 

Well it seems that changing this value at all causes the script not to work at all, even offline. No clue why as again there are no errors in dcs.log or in sim, it just doesn't work.

 

 

Posted

So testing it with host/client I at least got it working for shots by a client against a host. I was unable to test 2 clients shooting at each other or the host shooting at a client so I can't verify that functionality. Simply put its damn near impossible to fly an SU-25T using teamviewer. I upped the threshold to remove the missile up to 300 meters instead of 100. I think it might have been down to trying to synchronize the chain of events with the client in such a short period of time. As in its very much possible that on the server the missile was removed, but to the client it was still tracking and hit its target. I'd venture to guess that if more stuff was going on in the background be it more players, AI, whatever, then the threshold might need to be higher.

 

The host server did crash on exit of the game, not sure if its related. Weird stuff happens when you do stuff the game isn't really expecting to happen. :)

 

do
   local remove_missile_method = 1
   -- 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
   
   get3DDist = function(point1, point2)
       return getMag({x = point1.x - point2.x, y = point1.y - point2.y, z = point1.z - point2.z})
   end
   
   local function removeMis(id)
	if Object.isExist(aiMissiles[id].missile) then -- if missile is still active and needs to be destroyed
           if Weapon.getTarget(aiMissiles[id].missile) == aiMissiles[id].origTarg and Unit.getPlayerName(aiMissiles[id].origTarg) then
               trigger.action.outText(Unit.getPlayerName(aiMissiles[id].origTarg) .. ' has been hit by a missile.', 5)
           end
           if remove_missile_method == 0 then
               trigger.action.explosion(Object.getPosition(aiMissiles[id].missile).p, 5)
           else
               Object.destroy(aiMissiles[id].missile)
           end
       end
       aiMissiles[id] = nil
       numActive = numActive - 1
       
       return
   end
   local function checkMis(mis)
       local tot = 0
       if Object.isExist(mis.missile) == false then
		removeMis(mis.uid)
       else
	   if Object.isExist(mis.origTarg) == true then
			local misVel = getMag(Object.getVelocity(mis.missile))
               local targVel = getMag(Object.getVelocity(mis.origTarg))
               local dist = get3DDist(Object.getPoint(mis.missile), Object.getPoint(mis.origTarg))
			if dist < 300 then -- if its close and still guiding
                   removeMis(mis.uid)
               else
				tot = dist/(misVel*2.5)
                   timer.scheduleFunction(checkMis, mis, timer.getTime() + tot)
               end
           end        
       end
       
       
   end
   
   
   local function aiShot(event)
       
       if event.id == world.event.S_EVENT_SHOT and event.initiator then
           if event.weapon and Weapon.getDesc(event.weapon).missileCategory and (Weapon.getDesc(event.weapon).missileCategory == 2 or 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)
               newMis.lostTrack = false
               aiMissiles[uid] = newMis
               uid = uid + 1
               numActive = numActive + 1
               
               timer.scheduleFunction(checkMis, newMis, timer.getTime() + 2)
           end            
       end        
   end
   simpleEvent(aiShot)

   env.info('Training Sams by Grimes Loaded')
end

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

Posted

Should this still work with SAMs in an offline mission for the player? I've just run some quick tests in both 2.0 and 1.5 and the updated version doesn't work at all (although dcs.log shows it is loaded), although the original version does work in the same situation.

 

 

  • Recently Browsing   0 members

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