Difference between revisions of "DCS task attackUnit"
From DCS World Wiki - Hoggitworld.com
m (1 revision imported) |
|||
Line 44: | Line 44: | ||
{{Template:DCS_enum_AI_expend_list}} | {{Template:DCS_enum_AI_expend_list}} | ||
− | |exam= | + | |exam= The following is a function that is passed a flight name and a target group name. It searches the target group for units with SAM SR and SAM TR attributes (search radar and tracking radar). It then assigns an attack unit task to the flight for each of those units. Allows the flight to make a single attack on the target firing any two air to surface missiles at each target. |
+ | |||
+ | <pre> | ||
+ | function smartAttackSam(flight, target) | ||
+ | local tgtGP = Group.getByName(target) | ||
+ | local fGP = Group.getByName(flight) | ||
+ | local attribs = {["SAM SR"] = true, ["SAM TR"] = true,} | ||
+ | if tgtGP and fGP then | ||
+ | local targets = {} | ||
+ | local units = tgtGP:getUnits() | ||
+ | local anyFound = false | ||
+ | for i = 1, #units do | ||
+ | for atName, _ in pairs(attribs) do | ||
+ | if units[i]:hasAttribute(atName) then | ||
+ | targets[units[i]:getName()] = units[i]:getID() | ||
+ | anyFound = true | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | if anyFound == true then | ||
+ | local fCon = fGP:getController() | ||
+ | for tName, tId in pairs(targets) do | ||
+ | fCon:pushTask({ | ||
+ | id = 'AttackUnit', | ||
+ | params = { | ||
+ | unitId = tId, | ||
+ | weaponType = 4161536, -- any ASM | ||
+ | expend = "Two", | ||
+ | attackQtyLimit = true, | ||
+ | attackQty = 1, | ||
+ | } | ||
+ | } | ||
+ | ) | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | </pre> | ||
|notes= Need to test, but I believe there is a possibility that you can assign friendly units as a valid target and the AI will engage said group with this task. Reason 138 why LUA can be more fun than the mission editor. | |notes= Need to test, but I believe there is a possibility that you can assign friendly units as a valid target and the AI will engage said group with this task. Reason 138 why LUA can be more fun than the mission editor. |
Latest revision as of 23:29, 16 November 2022