Useful to keep AU count down in large scenarios, you can either script this in for the AI to attack a field (before strike planning), or you could for example tie it to a special action for the player if they want to knock out an airfield.
Below is commented code and attached is a .scen file ready for you to go ahead and paste it in to test.
Code: Select all
local oldAirbase = ScenEdit_GetUnit({side='Cuba',name='Holguin Airfield'}) --Get the data of the single airbase unit
local side = VP_GetSide({side='Cuba'}) --create a list of all units and items associated with that side
local counter, aircraftTable = 0, {} --initialise a counter and prepare a table
for k,v in ipairs(side.units) do --go through the list of all units and items created above
local aircraft = ScenEdit_GetUnit({guid=v.guid}) --get the unit info of each unit on that side
if aircraft.type == 'Aircraft' and aircraft.base.name == oldAirbase.name then --pick out aircraft that have the old base as their designated base (can be in the air or on the ground)
counter = counter + 1 --increase counter if a unit matches the criteria
aircraftTable[counter] = aircraft --add that unit to the table in a sequential order
end
end
local oldAirbase = ScenEdit_SetUnit({guid=oldAirbase.guid,newname=oldAirbase.name..' Old'}) --change the name of the old airbase
ScenEdit_ImportInst('Cuba', '/CWDB Cuba/Holguin AB 1960.inst') --import the inst file unit
local newAirbase = ScenEdit_GetUnit({side='Cuba',name='Holguin Airfield'}) ---get the data from the generated group (make sure you know the name of the group, for best effect make sure it is named the same as the single unit airport)
for k,v in ipairs(aircraftTable) do --go through the list of aircraft that matched criteria
local aircraft = ScenEdit_SetUnit({guid=v.guid,base=newAirbase.guid}) --get each aircrafts individual data
if aircraft.altitude ~= oldAirbase.altitude then --if the aircraft isn't at the same altitude as its old base (then it's probably flying)
ScenEdit_SetUnit({guid=v.guid,base=newAirbase.guid})--assign it to the new base without teleporting it there. When it hits RTB is will land at the new base.
else --if the aircraft IS at the altitude of its old base, it's probably on the ground
ScenEdit_HostUnitToParent({HostedUnitNameOrID=v.guid,SelectedHostNameOrID=newAirbase.guid})--teleport it to the new base
end
end
ScenEdit_DeleteUnit({guid=oldAirbase.guid}) --delete the old base.
--by apache85; feel free to use, pick apart, whatever. Enjoy!



