Reassigning missions/loadouts

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
User avatar
BHughes
Posts: 22
Joined: Tue May 12, 2020 3:23 pm

Reassigning missions/loadouts

Post 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
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Reassigning missions/loadouts

Post 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
User avatar
BHughes
Posts: 22
Joined: Tue May 12, 2020 3:23 pm

RE: Reassigning missions/loadouts

Post by BHughes »

Excellent. Many thanks. I'm really a LUA novice, so this is a great help.
User avatar
BHughes
Posts: 22
Joined: Tue May 12, 2020 3:23 pm

RE: Reassigning missions/loadouts

Post 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?
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Reassigning missions/loadouts

Post 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.
User avatar
BHughes
Posts: 22
Joined: Tue May 12, 2020 3:23 pm

RE: Reassigning missions/loadouts

Post by BHughes »

Works like a charm. Many thanks!
Post Reply

Return to “Lua Legion”