Kyridious Posted December 1, 2016 Posted December 1, 2016 Good Morning, I am trying to task one air unit to follow another using the default DCS "Follow" task behavior. This is trivial to accomplish in the mission editor without scripting. Simply select the A/C, add a "Follow" Task, select the target group from the drop down menu and provide the desired offset vector. My problem is applying this to spawned units, or any unit with Late Activation. Below is loosely what I want to do: Mission Editor: Plane1 and Plane2 groups exist in mission and are set to late activation Lua executed in response to an event: --Create Spawn Groups spawnPlane1 = SPAWN:NEW("Plane1") spawnPlane2 = SPAWN:NEW("Plane2") --Spawn Groups into world groupPlane1 = spawnPlane1:Spawn() groupPlane2 = spawnPlane2:Spawn() --Create Task for plane2 (follow groupPlane1 at Vec3 offset) (Note: I think I need to be using controllers here) --i.e. cntrlPlane1 = groupPlane1.getController(groupPlane1) followTask = groupPlane2:TaskFollow( groupPlane1, Vec3 ) --Activate Task (Either PushTask/SetTask?) groupPlane2:pushTask(followTask) The furthest I've gotten is that old orders defined in the ME (I.e. an orbit task) get cleared. However, I see no indication that the new follow task is being applied. Any Thoughts?
FlightControl Posted December 2, 2016 Posted December 2, 2016 I understand your question, but need to take time to answer it. Just dropping this note that i saw your question and understand the issue. You make a few mistakes, but want to show you a good example with a test mission. A good example explains it the best, no? So bare with me and hopefully tomorrow i have time to provide you an answer. [TABLE][sIGPIC][/sIGPIC]| Join MOOSE community on: DISCORD :thumbup: Website of the MOOSE LUA Framework. MOOSE framework Downloads. Check out Example Missions to try out and learn. MOOSE YouTube Channel for live demonstrations and tutorials. [/TABLE]
FlightControl Posted December 3, 2016 Posted December 3, 2016 Hi, I've been looking into this, and find that there is something strange going on in the simulator. I am neither able to make the group follow the other group. This is the code that i used in the attached mission. I need to dig on monday a bit deeper into this and maybe this is a bug that needs a report. --Create Spawn Groups local SpawnHelo1 = SPAWN:New("Helo 1") local SpawnHelo2 = SPAWN:New("Helo 2") --Spawn Groups into world local GroupHelo1 = SpawnHelo1:Spawn() local GroupHelo2 = SpawnHelo2:Spawn() --Create Task for plane2 (follow groupPlane1 at Vec3 offset) (Note: I think I need to be using controllers here) --i.e. cntrlPlane1 = groupPlane1.getController(groupPlane1) local PointVec3 = POINT_VEC3:New( 0, 0, -10 ) -- This is a Vec3 class. -- This statement returns a structure. local FollowDCSTask = GroupHelo2:TaskFollow( GroupHelo1, PointVec3:GetVec3() ) --Activate Task (Either PushTask/SetTask?) -- PushTask will push a task on the execution queue of the group. -- SetTask will delete all tasks from the current group queue, and executes this task. GroupHelo2:SetTask( FollowDCSTask, 10 ) SvenMoose_Test_GROUP_TaskFollow.mizMoose_Test_GROUP_TaskFollow.lua [TABLE][sIGPIC][/sIGPIC]| Join MOOSE community on: DISCORD :thumbup: Website of the MOOSE LUA Framework. MOOSE framework Downloads. Check out Example Missions to try out and learn. MOOSE YouTube Channel for live demonstrations and tutorials. [/TABLE]
Kyridious Posted December 4, 2016 Author Posted December 4, 2016 Not there yet, but the following code allows a normal (late activation = false) group to follow a spawned leader: local Plane1 = SPAWN:New( "Plane1" ) local Plane1_spawn = Plane1:Spawn() local Plane1_group = Group.getByName(Plane1_spawn:GetName()) local FollowDCSTask = { id = 'Follow', params = { groupId = Plane1_group:getID(), pos = POINT_VEC3:New( -100, 0, 100 ):GetVec3(), lastWptIndexFlag = false, } } Group.getByName('Plane2'):getController():setTask(FollowDCSTask)
FlightControl Posted December 5, 2016 Posted December 5, 2016 Hi Kyridious, I found the reason why it did not work! There were two reasons, and both were my mistake in the MOOSE framework :doh: Fortunately, I could correct them both. :music_whistling: The reasons where: 1. In the CONTROLLER:TaskFollow method, I had the groupId field accidentally renamed to controllerId in the params structure... I replaced all controllerId fields in the CONTROLLER class file back to the correct groupId field. 2. The second was a bit more complicated. I should set lastWptIndexFlag to false. But I accidentally set it to nil ... So, I correct this in the method CONTROLLER:TaskFollow, and also did this correction in the method CONTROLLER:TaskEscort... So, now all works again. Ensure you replace the Moose.lua with the last version that I've just published on gitgub master. Just resync github, and reload Moose.lua in your mission. A few more explanations are required..., because there is one more important thing to know about DCS ... The reason why spawned units are not following when you execute a setTask command, is that a spawned group needs a bit of time to "start up"... So, when you spawn a group, and immediately after spawning you execute a setTask, then that command won't be executed. This is solved within MOOSE though :smartass: By using the GROUP:SetTask() method, which works just like the Controller:setTask function, there is an additional behaviour what GROUP:SetTask() does: It waits for one second before executing the command... In that way, the spawned group has time to activate, and after one second the command is executed ... Note that within the GROUP class, you don't need to use a Controller at all. The GROUP class encapsulates the Controller classes. GROUP derives from CONTROLLER. Also UNIT derives from CONTROLLER. Thus, using the same CONTROLLER methods, both GROUPS and UNITS can be controlled... Find the code below: [color=Green]--Create Spawn Groups[/color] [color=Purple]local [/color][color=DimGray]SpawnPlane1 [/color]= [b]SPAWN[/b]:New([color=Blue]"Plane 1"[/color]) [color=Purple]local [/color][color=DimGray]SpawnPlane2 [/color]= [b]SPAWN[/b]:New([color=Blue]"Plane 2"[/color]) [color=Green]--Spawn Groups into world[/color] [color=Purple]local [/color][color=DimGray]GroupPlane1 [/color]= [color=DimGray]SpawnPlane1[/color]:Spawn() [color=Green]--local GroupPlane1 = GROUP:FindByName( "Plane 1" )[/color] [color=Purple]local [/color][color=DimGray]GroupPlane2 [/color]= [color=DimGray]SpawnPlane2[/color]:Spawn() [color=Green]--local GroupPlane2 = GROUP:FindByName( "Plane 2" )[/color] [color=Green]--Create Task for plane2 (follow groupPlane1 at Vec3 offset) (Note: I think I need to be using controllers here) --i.e. cntrlPlane1 = groupPlane1.getController(groupPlane1)[/color] [color=Purple]local [/color][color=DimGray]PointVec3 [/color]= [b]POINT_VEC3[/b]:New( [color=Red]100[/color], [color=Red]0[/color], [color=Red]-100[/color] ) -- This is a Vec3 class. [color=Purple]local [/color][color=DimGray]FollowDCSTask [/color]= [color=DimGray]GroupPlane2[/color]:TaskFollow( [color=DimGray]GroupPlane1[/color], [color=DimGray]PointVec3[/color]:GetVec3() ) [color=Green]--Activate Task (Either PushTask/SetTask?) -- PushTask will push a task on the execution queue of the group. -- SetTask will delete all tasks from the current group queue, and executes this task.[/color] [color=DimGray]GroupPlane2[/color]:SetTask( [color=DimGray]FollowDCSTask[/color], [color=Red]1[/color] ) Note the last line above... The last parameter of SetTask is optional, and reflects the amound of seconds to wait before running the command. If not provided, the SetTask method will wait one second. hope this helps, FCMoose_Test_GROUP_TaskFollow.miz [TABLE][sIGPIC][/sIGPIC]| Join MOOSE community on: DISCORD :thumbup: Website of the MOOSE LUA Framework. MOOSE framework Downloads. Check out Example Missions to try out and learn. MOOSE YouTube Channel for live demonstrations and tutorials. [/TABLE]
Kyridious Posted December 5, 2016 Author Posted December 5, 2016 Amazing! I'll check it out as soon as I can - Thanks for your time & effort!
normre14232 Posted October 1, 2019 Posted October 1, 2019 Can’t SetTask for Delayed spawned units Interesting note...unable to get any :settask assignment work if :spawnscheduled is used. DCS log shows tried to access nil value for the object so spawned.
Recommended Posts