mission1.lua
Tool_EmulateNoConsole(true)
local u = ScenEdit_GetUnit({side='USN', name='Enterprise'})
local req = {}
for i=1, #(u.hostedUnits['Aircraft']), 1 do
local lo = ScenEdit_GetLoadout({ name=u.hostedUnits['Aircraft'][i] })
if lo ~= nil then
if lo.roles.role == 6001 then
local a = {}
a['dbid'] = lo.dbid
a['guid'] = u.hostedUnits['Aircraft'][i]
table.insert(req, a)
end
end
end
table.sort(req,function(a,b) return(a.dbid < b.dbid) end)
local count = {}
for i=1, #req, 1 do
local found = false
for j=1, #count, 1 do
if count[j].dbid == req[i].dbid then
count[j].number = count[j].number + 1
found = true
break
end
end
if found == false then
local a = {}
a['dbid'] = req[i].dbid
a['number'] = 1
table.insert(count, a)
end
end
if #count > 0 then
table.sort(count,function(a,b) return(a.number > b.number) end)
local best_loadout = count[1].dbid; print('best ' .. best_loadout)
local mission = ScenEdit_GetMission('USN', 'ASW patrol' )
if mission ~= nil then
for i=1, #req, 1 do
if req[i].dbid == best_loadout then
local u1 = ScenEdit_AssignUnitToMission( req[i].guid, mission.guid )
end
end
end
end