Page 1 of 1

Reassigning missions/loadouts

Posted: Sun Jul 05, 2020 4:34 pm
by BHughes
Hi there,

Looking for advice - is there a script/s that I could use to reassign AI units from one mission to another. Ditto for load-outs?

I'm trying to make an AI CAG behavior more realistic with multi-role aircraft...used for multi role!

And whilst I'm at it...is there a script to change aircraft ready times?

TIA

Brendan

RE: Reassigning missions/loadouts

Posted: Mon Jul 06, 2020 10:28 am
by KnightHawk75
On the first ScenEdit_AssignUnitToMission() is your friend.
On the second and third ScenEdit_SetLoadout() is your friend.


http://commandlua.github.io/

Sample usage:

--Change mission way 1.
local unit = SE_GetUnit({side="AI",name="SomeName"})
unit.mission = "SomeNewMissionName"

--change mission way 2
local unit = SE_GetUnit({side="AI",name="SomeName"})
ScenEdit_AssignUnitToMission(unit.guid,"SomeNewMissionName")

--change loadout from whatever it currently is to new loadout# 12345, and mark it instantly ready.
local unit = SE_GetUnit({side="AI",name="SomeName"})
ScenEdit_ScenEdit_SetLoadout({unitname=unit.guid, LoudoutID=12345, TimeToReady_Minutes=0, IgnoreMagazines=false, ExcludeOptionalWeapons=false})

--Don't change loadout and mark unit ready in 30 minutes.
local unit = SE_GetUnit({side="AI",name="SomeName"})
ScenEdit_ScenEdit_SetLoadout({unitname=unit.guid, LoudoutID=0, TimeToReady_Minutes=30})

Code: Select all

--Change 5 units named SomeName #1 through 5 to a new mission and change their loadouts to id 12345,
 -- and ready in 30 minutes no matter if ammo is available or not.
 local unit;
 for i=1,5 do
   unit = ScenEdit_GetUnit( {side="AI", name="SomeName #" .. i} )
   if unit ~=nil then
     unit.mission = "SomeNewMissionName"
     ScenEdit_SetLoadout( {unitname=unit.guid, LoadoutID=12345, TimeToReady_Minutes=30, IgnoreMagazines=true, ExcludeOptionalWeapons=false} )
   end
 end
Edited to remove typos

RE: Reassigning missions/loadouts

Posted: Mon Jul 06, 2020 2:52 pm
by BHughes
Excellent. Many thanks. I'm really a LUA novice, so this is a great help.

RE: Reassigning missions/loadouts

Posted: Wed Jul 08, 2020 1:20 pm
by BHughes
I've been trying this and getting an error message in the load-out change scripts:

ERROR: [string "Console"]:8: attempt to call global 'ScenEdit_ScenEdit_SetLoadout' (a nil value)

If I remove the first 'ScenEdit' (why twice?) I then get the following error:

ScenEdit_SetLoadout 0 : ,LoadoutID has not been defined!

I'm using a loadout ID string taken from the unit DB

I'm in CMANO, not CMO - does this make a difference?

RE: Reassigning missions/loadouts

Posted: Wed Jul 08, 2020 2:43 pm
by KnightHawk75
The 'ScenEdit_' twice part is typo - as was loadout being misspelled, sorry I wrote that off the cuff, not copy and paste.
Try the now edited\updated version without the typos, which should work (tested working in my copies of CMO and CMANO). Also makes sure the mission you're assigning to exists.

RE: Reassigning missions/loadouts

Posted: Wed Jul 08, 2020 3:52 pm
by BHughes
Works like a charm. Many thanks!