vettim89 wrote: Sun May 08, 2022 12:28 am
Where is the error in the code?
Trying to do it all in one step. AddMission is for the basic creation of a Mission, it takes but a few parameters.
SetMission, or the mission wrapper you get back from AddMission success is what you want to use to customize the doctrine settings for the Mission. Also the docs are wrong the tankerMissionList needs the mission guids for the tanker-support missions, not the name. Additionally to let it know to parse and use the list you must set tankerUsage=1.
So for example assuming you didn't already know the tanker mission guid:
Code: Select all
local mtank = ScenEdit_GetMission('NATO','Svalbard Tanker'); --get tanker mission wrapper.
ScenEdit_AddMission('NATO', 'Svalbard Strike', 'strike', {type='land'});
if mtank ~=nil then
ScenEdit_SetMission('NATO','Svalbard Strike',{StrikeOneTimeOnly=true, use_refuel_unrep=2, tankerUsage=1,tankerMissionList={mtank.guid}}); --use guid instead of name
end
end
For a different example doing the same thing wrapped into one call, and accounts for a mission already existing.
Code: Select all
local gKH={}; --just here so this snippet works without me changing things.
gKH.Missions={}; --just here so this snippet works without me changing things
function gKH.Missions.CreateMissionWithParams(theside,thenameguid,thetype,typeoptions,missionparams)
local fn = 'gKH.Missions.CreateMissionWithParams(): ';
if theside ==nil then print(fn.. 'Missing side name.'); return; end
if thenameguid==nil then print(fn.. 'Mission name or guid is missing.'); return; end
if thetype==nil then print(fn.. 'Missing mission type name. '); return; end
if (typeoptions == nil) or type(typeoptions) ~="table" then print(fn.. "Missing type options table, min {type='land'}"); return; end
local retval,m = pcall(ScenEdit_GetMission,theside,thenameguid);
if retval and m ~=nil then
print(fn.. 'Mission already exists. ' .. tostring(m.name));
else
retval,m = false,nil;
retval,m = pcall(ScenEdit_AddMission,theside, thenameguid, thetype,typeoptions);
if retval and m ~= nil then
print(fn.. 'Successfully added mission. ' .. tostring(m.name));
end
end
if (retval and m~=nil) and missionparams ~= nil then
local n;
retval, n = pcall(ScenEdit_SetMission,theside,m.guid,missionparams);
if retval and n ~=nil then
print(fn.. 'Successfully set mission parameters. ' ..tostring(m.name));
else
print(fn.. 'Error setting the mission parameters. ' ..tostring(m.name));
end
elseif (retval and m==nil) then
print(fn.. 'Error adding mission ' .. tostring(thenameguid) .. '. Make sure the side exists.')
end
end
--NOTE: "Svalbard Tanker" in the list must be that of the support mission's guid that pre-exists on said side for it to be set.
--NOTE: The docs are wrong about name being able to be used so first we get that guid and then use it.
local retval,m = pcall(ScenEdit_GetMission,'NATO','Svalbard Tanker');
if retval and m ~=nil then
gKH.Missions.CreateMissionWithParams('NATO','Svalbard Strike','strike',{type='land'},{StrikeOneTimeOnly=true, use_refuel_unrep=2, TankerUsage=1,TankerMissionList={m.guid}});
end
.