Code: Select all
ScenEdit_AddMission('NATO', 'Svalbard Strike', 'strike', {type='land', StrikeOneTimeOnly=true, use_refuel_unrep='Allow', tankerMissionList={Svalbard Tanker}})Where is the error in the code?
Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command
Code: Select all
ScenEdit_AddMission('NATO', 'Svalbard Strike', 'strike', {type='land', StrikeOneTimeOnly=true, use_refuel_unrep='Allow', tankerMissionList={Svalbard Tanker}})Post by KnightHawk75 »
Trying to do it all in one step. AddMission is for the basic creation of a Mission, it takes but a few parameters.
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
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
