Jump to content

Attack Group, "expend" parameter work around


Go to solution Solved by Grimes,

Recommended Posts

Having lots of problems getting AI CAS aircraft to honor the "expend" parameter (# of rounds to shoot) when I set up an Attack Group trigger in the ME...If I give an A10 6 Mavs and set up an "attack group" trigger telling the aircraft to fire 4 Mavs at an armored column, it always fires all 6 of them. The same happens when I use an "attackGroup" lua script

Did some reading and it seems like 'attack group' might be bugged in that way. 

The 'expend' parameter does seem to work with an 'attack Unit' trigger or script, so I tried a work around. The idea was to use a for/do loop to iterate through the first 4 units in the armored column and shoot a single Mav at each...It doesn't work and I'm pretty sure it's just because I suck at lua and have my loop set up wrong (kind of a beginner here) 

Using the below code, AI picks the first vehicle, fires a single Mav at it, then peels away and ends the attack. I THINK I understand why it's doing that given the syntax I'm using, but I can't figure out how to tweak it so that AI iterates through the first 4 vehicles and fires a single missile at each before disengaging. 

I'm pretty sure a number of 'attack unit' triggers and flags in the ME would work but that would lead to problems of its own so I'm hoping there's a way I can do it with lua. Do I just need to fix my code, or is it not possible to do this with the kind of loop I'm trying to use?

Thank you in advance 👍 


local targetTable = (Group.getByName('Red Armor 1'):getUnits())
 
for i, Unit in pairs(targetTable)  do

if i <= 4

then

local Name = (Unit.getName(Unit))

local Target1 = {}
Target1.unitId = Unit.getByName(Name):getID()
Target1.weaponType = 131072
Target1.expend = "One"
Target1.attackQtyLimit = true
Target1.attackQty = 1
Target1.altitudeEnabled = true
Target1.altitude = 3000

local fire = {id = 'AttackUnit', params = Target1}
Group.getByName('Blue CAS 1'):getController():pushTask(fire)

end
end

Link to comment
Share on other sites

Three things.

1. It would be good practice to not use the name of any of the main object classes as a variable name. for i = 1, uObj in pairsj(targetTable) do would be better. Or even just a lower case unit. 

2. You don't need to get the name, then use that string to get the unit object, so you can get the unit id. You already have the unit object. Target1.unitId = uObj:getID() would work. 

3. If AI refuse to attack whenever you have a set weaponType it is good to try other weapon enumerator values. I'd try 1835008 for tactical ASM or or 262144 for fire and forget ASM. Its possible that "anti tank" missile is more in line with any of the ground launched ATGM like a TOW. I don't know anywhere in the files where it explicitly says "weapon has X weapon flag value". You just gotta try different things to figure it out. 

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

Link to comment
Share on other sites

Yeah, I know just enough about coding to break every best practice there is 🙂

I've dabbled with the weapon codes before and while 1835008 does work, the AI seems to prefer the APKWS missiles that are on board over the Mavs. I can't seem to make 'Fire and forget' work but 131072 does get the AI to use Mavs before the APKWS, so I stuck with that.  

Thanks for the heads up on calling the object from the unit name string, I nixed that part of the code and made the other tweaks you suggested. Also switched up how I looped through the first 4 vehicles but the behavior of the AI remains the same...It 'sees' that the first vehicle is a valid target and shoots at it, but then peels off and doesn't iterate shots at vehicles 2, 3, and 4. I dunno, seems like I must be using the loop wrong, or maybe the game engine just isn't capable of queuing up 4 'attackUnit' tasks in a single script execution(?)


 

local targetTable = (Group.getByName('Red Armor 1'):getUnits())
 
for uObj = 1, 4, 1 do

if (targetTable[uObj] ~= nil)

then

local Target1 = {}
Target1.unitId = (Group.getByName('Red Armor 1'):getUnits()[uObj]):getID()
Target1.weaponType = 131072
Target1.expend = "One"
Target1.attackQtyLimit = true
Target1.attackQty = 1
Target1.altitudeEnabled = true
Target1.altitude = 3000

local fire = {id = 'AttackUnit', params = Target1}
Group.getByName('Blue CAS 1'):getController():pushTask(fire)

end
end

Link to comment
Share on other sites

  • Solution

Could try engageUnit. https://wiki.hoggitworld.com/view/DCS_task_engageUnit

It doesn't necessarily require the previous task to be completed before the AI is allowed to engage any other valid targets. 

As for the weapon flags, you cannot really tell AI to prioritize one weapon over another if they are both governed by the same waeponType value. 

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

Link to comment
Share on other sites

1 hour ago, Grimes said:

Could try engageUnit. https://wiki.hoggitworld.com/view/DCS_task_engageUnit

It doesn't necessarily require the previous task to be completed before the AI is allowed to engage any other valid targets. 

As for the weapon flags, you cannot really tell AI to prioritize one weapon over another if they are both governed by the same waeponType value. 

That totally worked. Same script but just change the task to engageUnit and the AI queues up 4 missile shots, then peels off and heads to its next waypoint. Perfect.

In this mission I need the AI plane to save at least one Mav for later events, that's why the # of shots it was taking with 'attackGroup' mattered. Interestingly enuf, this method is actually a little more useful given that attackUnit or attackGroup won't allow you to select an oddball # of shots. Eg: I can pick '1', '2', '4', 'All', etc. but not say, '3' or '5'...Like I said, I only need to save one Mav so if I can kill 5 tanks on that first pass instead of 4, all the better.

Thank you, sir. Very helpful stuff, as always 👍

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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