[Edit 2021: Adding Mags via UpdateUnit() was added to CMO lua api after this original post, so some of this may not be relevant post early 2021+]
ORIGINAL: ProdigyofMilitaryPride
And for adding additional magazine entries for carriers in carrying the appropriate weaponry for key missions.
For specifically adding Mags, I think you'll still have to resort to using a specific delta file for each specific unit guid involved there. I'm kind of glad you asked cause that's something I meaning to ask for that I totally forgot about, a AddMagazine(), or an addition to UpdateUnit() more likely with mode='add_mag','remove_mag', like we have for mounts.
Anyway for now to use the delta method. Customize the delta.ini file for you specific unit and then call UpdateUnit()
Let's assume for the example you have a delta file here: CMO-Install\Scenarios\KHTests\iniSaves\MyS400x12Default4.ini the contents are listed below
It does the following to a #2029 Facility.
Removes the original mag that has slower reload (lets cheat!)
Adds one that's near instantaneous, populate its with just 994 sa-21b's and no sa-21a records
Now delta files are a topic in and of themselves but this is just an example I had around, but most of all just make sure the <Unit_GUID-HERE> matches your unit or they will not get applied and throw an error.
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<ScenarioUnits>
<Unit_4FH7PU-0HM0IN9JP6C9D>
<!--MyS400x12Default (SAM Bn (SA-21a/b Growler [S-400 Triumf]) [2029])-->
<MagRemove_1_1363 />
<!--SA-21a/b Bn-->
<MagAdd_1185 />
<!--Munitions-->
<Mag_2_1185>
<!--Munitions-->
<WeaponRecAdd_0_2104 />
<!--SA-21b Growler [40N6]-->
<WeaponEdit_2104_994 />
<!--SA-21b Growler [40N6]-->
</Mag_2_1185>
</Unit_4FH7PU-0HM0IN9JP6C9D>
</ScenarioUnits>
local unit = ScenEdit_GetUnit( { name='MyS400x12Default', guid='4FH7PU-0HM0IN9JP6C9D' } );
ScenEdit_UpdateUnit( {guid=unit.guid, name=unit.name, mode='delta', file='\\KHTests\\iniSaves\\MyS400x12Default4.ini'} ) ;
Now that actually does both,adds a mag and populates it with specific weapon records you want) but you could have just had the <MagAdd_1185 /> line to just add the mag and then used the following to throw stuff into the mags that exist (including the new ones you add):
ScenEdit_AddWeaponToUnitMagazine( {guid=unit.guid, wpn_dbid=2104, number=994, maxcap=10000,new=true} )
If there were 1000 in there already and you wanted to remove 500..
ScenEdit_AddWeaponToUnitMagazine( {guid=unit.guid, wpn_dbid=2104, number=500, remove=true} )
This assumes you don't care what goes in which mag, as I recall and I might be wrong it'll keep looking for
empty mags if it fills one up entirely and move on to the next. But test that cause I haven't in awhile.
When it comes to filling a mag you can either do it all like above and custom or if you're just looking for quick and easy way to say 'give me 25 loadouts for a f-22 with SBD's' into whatever mags are available then you can use:
ScenEdit_FillMagsForLoadout({guid=unit.guid, loadoutid=19337, quantity=25})
or if you were looping though a bunch of aircraft...
ScenEdit_FillMagsForLoadout({guid=unit.guid, loadoutid=u.loadoutdbid, quantity=25})
Now if you explicitly care about what weapons go into which specific mag inside the same unit, and there are multiple mags that share dbid id's like the generic 1185, well.. it can be done but it gets more involved. As you'll need to 'find' the matching mag-guid for it first, or you'll need to know the index in has in the mag table you want to put it in. Lot easier when you have stuff pre-made in the scenario, becomes more challenging as you try to add things like mags dynamically during a scenario where new guids and indexes might change but it can be done. I'll leave it there for now as doing the grab the specific mag-guid or by index etc is more and slightly more complex code, but if you need such it let me know.