AddWeaponToUnitMagazine using mag_guid troubles

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

AddWeaponToUnitMagazine using mag_guid troubles

Post by KnightHawk75 »

Trying to do something basic that I swear used to work (at least at one point) in CMANO.

I want to add a mag to a carrier and I want to specifically put munitions into this particular new mag.

So I create the unit, and apply the mag addition I want via delta...no problems it gets added as the 5th mag as expected in this case for example to a ship (#657). Now I go to add some AGM-84k's to my new mag.

mag_id = c.magazines[5].mag_guid; --I assure you this is grabbing the correct mag_guid, guid isn't the problem.
ScenEdit_AddWeaponToUnitMagazine( { guid=c.guid, MAG_GUID=mag_id,WPN_DBID=452,number=100, maxcap=200,new=true } )

That should add a 100/200 AGM-84k entry to my nice fresh mag right?
Doesn't happen, instead it adds 1/200 AGM-84k to the mag at index 1, which is the wrong mag, and the wrong amount.
I can see that the matching guid search happens, and the correct magazine matching the guid I submitted is found and set\selected initially but then something goes wrong it seems, both in the 'which mag' to use process and the number being added. Hard for me to tell what exactly is going on but it's as if it takes the wrong mode branch at some point, for lack of a better way of saying it.

If one runs it a second time ... it repeats the above but for the mag at index #2.
A third time will land it in the original carrier mag and put 1/200.
A fouth time will not add anything to the forth mag but add one more to the existing 1/200 in the 3rd??
A fifth time will not add anything to the forth mag but add one more to the existing 2/200 in the 3rd??
Removing\adding the 'new=true' param has no effect on this happening from what I can tell.

So either I don't understand logic or something is borked at the moment when trying to add to a specific mag.
Not using the mag_guid operates correctly in that it adds the 100/200 record, but throws all the weapons into the first mount, which is undesirable for obvious reasons for various unit types.

Additionally being able to add a magazine itself without having to resort to delta's and where guids have to match would be a welcome addition in the longer term. Anyone see the same thing or found away around this beyond just put everything into a delta (which has it's own drawbacks)?
User avatar
michaelm75au
Posts: 12464
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: AddWeaponToUnitMagazine using mag_guid troubles

Post by michaelm75au »

Do you have the save so I try your examples?
Michael
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: AddWeaponToUnitMagazine using mag_guid troubles

Post by KnightHawk75 »

Sure use the special action in the attached otherwise empty scene, there is nothing particularly special about it.
You'll need the associated folder structure in the zip under scenarios though for the delta part to work. Was trying to do sort of tutorial for that other thread that tied all the piece meal comments together to one script.

Attachments
MyScenarioName.zip
(9.82 KiB) Downloaded 9 times
User avatar
michaelm75au
Posts: 12464
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: AddWeaponToUnitMagazine using mag_guid troubles

Post by michaelm75au »

It works for a magazine with an existing weapon record, but it is not checking the magazine id when adding a new weapon record to the magazine.

Also found it is case sensitive for the MAG_GUID, so have corrected that too.
Michael
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: AddWeaponToUnitMagazine using mag_guid troubles

Post by KnightHawk75 »

Yeah I noticed the case issue, hence you see why I was using caps in the script and testing at various points,I should have mentioned that too. ;)

"It works for a magazine with an existing weapon record"
Then why on 2nd 3rd.. (don't delete ships and just run the add part again at the bottom) does it not use the existing record it just created in say the first try?

Btw I wish when one uses the mag_guid version of the method it didn't try and be smart like re-using existing entries, often, if not always, it's explicitly what I'm trying to avoid, especially if I'm feeding it a maxcap. I get why it does that for the more simpler add procedures though.

User avatar
michaelm75au
Posts: 12464
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: AddWeaponToUnitMagazine using mag_guid troubles

Post by michaelm75au »

ORIGINAL: KnightHawk75

"It works for a magazine with an existing weapon record"
Then why on 2nd 3rd.. (don't delete ships and just run the add part again at the bottom) does it not use the existing record it just created in say the first try?

The presence of the mag_guid is forcing it to look for that particular magazine. But there is no weapon record in that one as it was created in some other magazine.
If you created an empty weapon record in that magazine thru the gui, and then ran the Lua function on the magazine, I would expect it to update the inventory count in the magazine.
Michael
Post Reply

Return to “Lua Legion”