ESAc_matador Posted May 7, 2016 Posted May 7, 2016 (edited) hello. I am trying to do some lua stuff, and it is interesting for me that I can make flights to attack units in a zone via F10, menú. Menús, works fine, and the attackorder works if I just introduce the name of the unit to be attacked. But I want the flight to attack whatever unit is in zone. So, I have two main problems. To make the function attack as many times as redunits are inside a predefined area. And to cancel the attack and come back to its old flight plan. I you can have a look, it does not seem to be complicated, but I am starting with this... -- 1.0 CAS operations. -- ATTACK SCRIPT -- Attack function local redunits = mist.makeUnitTable{"[red]"}---- table of all red units local zone = {'N'} -- here i will put all trigger zones to be attacked local unitsinzones = mist.getUnitsInZones ( redunits, zone)---- this is to reduce the table to only the red units inside the such zone. function attack(Zone) -- This is the command I want to give to the aircraft CAS flight. -- This works for just one unit but it does not work for more than one, -- I guess I have to make iterations or something like that, and -- repeat the function until the order is set to attack all units in the area. -- Then the aircraft should attack all units, with no preference. attackunits = { id = 'AttackUnit', params = { unitId = Unit.getByName(unitsinzones):getID() } } _group = Group.getByName("CAS1") _controller = _group:getController() _controller:pushTask(attackunits); trigger.action.outText("CAS1 Engaging units in"..zone.."!!!", 30) end -- disengage it does not work... the aircraft keep the attack until it kills the enemy. -- I would like to be able to cancel the attack anytime. function stopattack() _group = Group.getByName("Group1") _controller = _group:getController() _controller:popTask(); trigger.action.outText("CAS1, Disengaging!!!", 30) end -- Radio commands. This works, so I have no problem with this. local _path1 = missionCommands.addSubMenu("CAS1 orders", nil) missionCommands.addCommand("Engage enemies in N",_path1, function()attack ("N") end,nil) missionCommands.addCommand("Disengaging ",_path1, function()stopattack() end,nil) Edited May 7, 2016 by ESAc_matador
Bearfoot Posted May 7, 2016 Posted May 7, 2016 While there's no harm in working out how to implement all this from scratch, you might be interested in checking out the MOOSE Escort class, which has already got routines to do all this and more: http://forums.eagle.ru/showthread.php?t=164696 [ame] [/ame] [ame] [/ame]
ESAc_matador Posted May 7, 2016 Author Posted May 7, 2016 (edited) wow, I ll see!!! definetly, i will give a try looks, very complete!!! from the video, I miss the location of the unit. Distance is ok, but... the location would be great Edited May 7, 2016 by ESAc_matador
ESAc_matador Posted May 12, 2016 Author Posted May 12, 2016 (edited) hello every one... I have done this. Still does not work. ----- attack all red units in zone function. function attack(zone,CASgroup) ---- I dont know what is wrong with the sintax. local zone = {'North'} local CASgroup = {'CAS1'} local redunits = mist.makeUnitTable({'[red]'}) local unit = mist.getUnitsInZones(redunits,zone) local redunitID = Unit.getByName(unit):getID() AttackUnit = { id = 'AttackUnit', params = { unitId = redunitID } } _group = Group.getByName(CASgroup) _controller = _group:getController() _controller:pushTask(AttackUnit); trigger.action.outText("CAS1 Engaging units in zone", 30) end ----- break the attack. function stopattack(CASGroup) local CASgroup = {'CAS1'} Task = { id = 'AttackUnit', params = { } } _group = Group.getByName(CASgroup) _controller = _group:getController() _controller:resetTask(Task); local path = mist.getGroupRoute(CASgroup) ---- this only gets CASGroup back to its previous waypoints, but not the Orbit, mist.goRoute(CASgroup, path) ---- or alternate WPs. I want the CASGroup to come back to orbit. It goes to WP 0 trigger.action.outText("CAS1, Disengaging!!!", 30) end -- Radio commands. This works for other fucntions I made, so I have no problem with this. local _path1 = missionCommands.addSubMenu("CAS1 orders", nil) missionCommands.addCommand("Engage enemies in N",_path1,function()attack ('North','CAS1') end,nil) missionCommands.addCommand("Disengaging ",_path1,function()stopattack('CAS1') end,nil) Edited May 14, 2016 by ESAc_matador
ESAc_matador Posted May 14, 2016 Author Posted May 14, 2016 Nothing... I am still fighting with this script. I read the manual, and I think, I have some concept mistake. I have few scripts in mind, but I need to get all the red units in a zone, so I can make it. THe problem is I can make this local redunits = mist.makeUnitTable({'[red]'}) local unit = mist.getUnitsInZones(redunits,zone) local redunitID = Unit.getByName(unit):getID() and apply redunitID to other functions... I think, I need do something like for i = 0, #unit then... and repeat the function... but I cannot make it work
Recommended Posts