Getting an AI Chopper to fly a route and ‘orbit’ when we say so, then resume route
LINK UPDATED << to zip file containing the code files and mission (miz) file
Updated the link - I left the flag(99), see below, in the ‘ON’ position so I set it to flag(99) = OFF, so it will use the internal files.
Uses the Nevada map (loads really fast for testing stuff)
You will need to update the first line in the AI Escort Loader.lua to refer to where your script files are on your PC
In sim you need to access the F10 menu (however you have it bound) then your choices are “Orbit” or “Continue”. On “Orbit” the CH47 will turn in circles, on “Continue” it will resume its route.
Issue: ‘StopRoute’ works for ground units (say we’re escorting a convoy here, not a chopper) but does not work for aircraft. While you could figure out a way, I guess, using triggers, with embedded lua scripts too, this to me, makes things a bit more ‘tidy’.
The ME doesn’t have a ‘popTask’ trigger, which is necessary for this example. It only has ‘push’/'set’task. pushTask says, “do this now”. Fine, but what about when I want it to STOP doing that, and continue on its route? setTask just gives it another task - but we want it to do what it was doing before.
Via the F10 menu (see miz file) you can make them ‘orbit’/‘continue’ over and over.
NOTE: This didn’t format here the way I wanted, comments, so refer to the source code in the linked to zip file.
Escort =
{
groupName = nil,
lastPosn3d = {x = 0, y = 0,z = 0} – save position of our escorted chopper
}
Escort.main = function(_escortGroupName)
Escort.groupName = _escortGroupName
timer.scheduleFunction(Escort.loop, nil, timer.getTime() + 3)
trigger.action.outText("calling loop..", 3, false)
end
Escort.loop = function()
local grp = Group.getByName(Escort.groupName)
local u = grp:getUnit(1)
Escort.lastPosn3d = u:getPoint()
return timer.getTime() + 3 -- do this every 3 sec's or a variable to simulate reaction time
end
Escort.hold = function()
local task = {
id = 'Orbit',
params = {
pattern = "Circle",
point = {x = Escort.lastPosn3d.x, y = Escort.lastPosn3d.z},
}
}
local grp = Group.getByName(Escort.groupName)
local grpCntrlr = grp:getController()
grpCntrlr:pushTask(task)
trigger.action.outText("holding..", 3, false)
end
Escort.continue = function ()
local grp = Group.getByName(Escort.groupName)
local grpCntrlr = grp:getController()
grpCntrlr:popTask()
trigger.action.outText("continuing..", 3, false)
end
Standby…I have an urgent ‘honey-do’ to do…BRB…will post the link below in a bit
Ok, back, where was I…
The ‘loop’ fxn above is necessary because DCS only knows waypoints. If the chopper is on a route (like in the linked file) there might be a LONG distance from where it is back to the fix it last passed. So, when you give the ‘orbit’ task will do it but it will go ALL THE WAY back to that wp.
I’d rather they just orbit where they are, roughly. The update rate (last line in the ‘loop’ fxn) is set to 3, which is seconds. You’ll need to change as you’d like.
Note we’re not storing more than that one point here - it gets overwritten each time. Also, you don’t really need the loop: just get the getPoint() when you give the command (this is how I do it in the larger system). I merely added that for those that might not understand the scheduleFunction() thingy. Your imagination can take over from there.