Jump to content

Recommended Posts

Posted (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 by ESAc_matador
Posted (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 by ESAc_matador
Posted (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 by ESAc_matador
Posted

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

  • Recently Browsing   0 members

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