Jump to content

Scripting aircrafts tasks with lua -> Main task or role task. Is it possible to change it during a mission ?


Recommended Posts

Hi,

 

The good working of DCS tasks assigned to an aircraft group depends on the Main TASK or ROLE defined in ME or when spawning (string task value in lua). For exemple "Ground Attack" is necessary to have a good working of the "AttackGroup" task.

 

But, when the group has been spawned, is it possible to change it  during the mission, of course with a lua function  ?

 

Thanks in advance for your returns.

Sunski.

Link to comment
Share on other sites

21 minutes ago, sunski34 said:

...But, when the group has been spawned, is it possible to change it  during the mission, of course with a lua function  ?...

 

It has to be tested. I know I've added a maintask through addition of a dynamic waypoint to a unit that already had one, and it wrote in the log "unit already had a task" or something like that. But as it was the same task I don't know if it replaced or not. (using mist.goroute, with a maintask described in 1 waypoint of assigned route)


I'd say yes, there is almost always a way. If adding a maintask through lua doesn't replace the one that unit already has, then it's always possible to replace the whole unit where it stands in the 3d world. (...ultimately...)

Link to comment
Share on other sites

1 hour ago, sunski34 said:

so you said in a mission task? 

 

A main task, like ground attack or sead or tanker. Example : (unit gets AWACS maintask when reaching the Wpt)

 

Spoiler

local routeA = {
                [1] = {
                                ["alt"] = 3500,
                                ["type"] = "Turning Point",
                                ["action"] = "Turning Point",
                                ["alt_type"] = "BARO",
                                ["formation_template"] = "",
                                ["properties"] = 
                                {
                                    ["vnav"] = 1,
                                    ["scale"] = 0,
                                    ["angle"] = 0,
                                    ["vangle"] = 0,
                                    ["steer"] = 2,
                                }, 
                                ["ETA"] = currentTime,
                                ["y"] = -00130000,
                                ["x"] = -00140000,
                                ["speed"] = 150,
                                ["ETA_locked"] = false,
                                ["task"] = 
                                {
                                    ["id"] = "ComboTask",
                                    ["params"] = 
                                    {
                                        ["tasks"] = 
                                        {
                                            [1] = 
                                            {
                                                ["number"] = 1,
                                                ["auto"] = true,
                                                ["id"] = "AWACS",
                                                ["enabled"] = true,
                                                ["params"] = 
                                                {
                                                }, 
                                            },
                                            [2] = 
                                            {
                                                ["number"] = 2,
                                                ["auto"] = true,
                                                ["id"] = "Orbit",
                                                ["enabled"] = true,
                                                ["params"] = 
                                                {
                                                    ["pattern"] = "Circle",
                                                    ["speed"] = 130,
                                                    ["altitude"] = 3500,
                                                }, 
                                            }, 
                                        }, 
                                    }, 
                                }, 
                                ["speed_locked"] = true,
                            }
                    }
        mist.goRoute('Wizard-1', routeA)

 

Link to comment
Share on other sites

The scripting engine isn't limited to the "role" that different aircraft are assigned to. The limitation is more to do with whatever attributes a given group has. The same goes tasks like "Search and Engage" where the editor limits what you are able to assign to it, but the task is still the same thing. Here are a couple of examples. 

 

-- A CAS task
local cas = { 
  id = 'EngageTargets', 
  params = { 
    targetTypes = {'Ground Units'}, 
    priority = 1, 
  } 
}

-- SEAD
local sead = { 
  id = 'EngageTargets', 
  params = { 
    targetTypes = {'SAM'}, 
    priority = 1, 
  } 
}
-- This would allow the AI to attack any fighters, sams, or tanks that they find. 
local combo =  { 
  id = 'EngageTargets', 
  params = { 
    targetTypes = {'Fighters', 'SAM', 'Tanks'}, 
    priority = 1, 
  } 
}

 

So you can either set a new mission task or assign directly via pushTask or setTask. 

  • Thanks 1

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-(GitHub) MIST-(Thread), SLMOD, IADScript, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Posted (edited)

Hi Grimes,

 

Yes, I thought that the rules for tasking were like you asked.  But the real problem is with the "Nothing" main task.

For example, two missions with only a 'AttackMapObject' task and a group with one AV-8. The aircraft group is set to 'Nothing' in ME for the first mission and to 'Ground Attack' for the other. You can notice at 12:00:50 that the group fires an AGM65 in the mission called "test attack with Ground Attack.miz", but do nothing in the other one.

 

I thought that the "Nothing" main task has a limited option like "weapon hold" set, but same result, with "Nothing" main task, the aircraft group never open fire when a attack, bombing or other task is set.

 

Here is the very simple script  :

local zone = trigger.misc.getZone("MapTarget")


local task = {
	id = "AttackMapObject",
	params = {
		point = {x = zone.point.x, y =zone.point.z},
		weaponType = 262144, -- FireAndForgetASM
		expend = "Half",
	},
}

local group = Group.getByName("Bombardier-1")

group:getController():pushTask(task)

 

In the other hand, when the aircraft group fly over ennemies with that pushed task and have "Ground Attack" main task, it engages ennemies. If you want the group do nothing, you have to set option WEAPON_HOLD :

 

local zone = trigger.misc.getZone("MapTarget")


local task = {
	id = "AttackMapObject",
	params = {
		point = {x = zone.point.x, y =zone.point.z},
		weaponType = 262144, -- FireAndForgetASM
		expend = "Half",
	},
}

local group = Group.getByName("Bombardier-1")

-- Weapon Hold
group:getController():setOption(AI.Option.Air.id.ROE, AI.Option.Air.val.ROE.WEAPON_HOLD)
--
group:getController():pushTask(task)

 

And finally, when the aircraft group fly over ennemies with that pushed task and have "Nothing" main task, it never engages ennemies even if WEAPON_FREE option set :

 

local zone = trigger.misc.getZone("MapTarget")


local task = {
	id = "AttackMapObject",
	params = {
		point = {x = zone.point.x, y =zone.point.z},
		weaponType = 262144, -- FireAndForgetASM
		expend = "Half",
	},
}

local group = Group.getByName("Bombardier-1")

-- Weapon Free
group:getController():setOption(AI.Option.Air.id.ROE, AI.Option.Air.val.ROE.WEAPON_FREE)
--
group:getController():pushTask(task)

 

 

So, when main task "Nothing" is set, is there something to do to force aircraft group to engage ?

 

Thanks in advance

Sunski.

test attack task with Nothing.miz test attack task with Ground Attack.miz


Edited by sunski34
Link to comment
Share on other sites

On 5/14/2021 at 5:51 AM, sunski34 said:

...

So, when main task "Nothing" is set, is there something to do to force aircraft group to engage ?....

 

 

Yes, you can assign a main-task via route/waypoint addition (with a main task described in wpt), like in my previous post code.

For me it works for units with no main task, to have AWACS or Tanker main task when reaching the dynamically added waypoint. It should work the same for any main task, like ground attack.

Link to comment
Share on other sites

Posted (edited)

No that doesn't work. Setting main task in mission task doesn't change anything. Note that _waypoints are good and the aircraft will follow this route.

 

task = { 
 id = 'Mission', 
 params = {
   airborne = true,
   task = "Ground Attack",
   route = {
     points = _waypoints,
   },
 },
}

 

 


Edited by sunski34
Link to comment
Share on other sites

3 hours ago, sunski34 said:

No that doesn't work. Setting main task in mission task doesn't change anything. Note that _waypoints are good and the aircraft will follow this route....

 

You are right. It works with "AWACS" or "Tanker" tasks, but it doesn't work with "CAS" (I tried with CAS because "attackGroup" is not a valid task for "Ground Attack" maintask, but valid for "CAS").

Link to comment
Share on other sites

Posted (edited)

As a conclusion,  there's no way to change a group with "Nothing"  main task to any attack main task when group has been spawned. I must create for example a group with  "Ground Attack" main task in ME (or directly in script with addGroup) and set the Weapon Hold value to ROE option to have a group ready to engage.

 

Am I right?

 

 


Edited by sunski34
  • Like 1
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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