LUA Cargo 2.0 Ground and Mobile Units Programming

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
winslow756
Posts: 1
Joined: Tue Jun 02, 2020 12:01 pm

LUA Cargo 2.0 Ground and Mobile Units Programming

Post by winslow756 »

I have a question about LUA coding for new Ground and Mobile Units. I have previous scenarios that I created that load cargo at a base or on a ship or plane. The function that I wrote looks like this:

function createCargoAtBase(base,num,db)
-- creates cargo onto a base or on an aircraft at the base, ex passing 6,357 creates six 7.62 MG Rfiles at the base passed
-- pass the base or object that the cargo is to be created at, number of cargo to create and cargo dbid
local u = ScenEdit_GetUnit({name=base})
ScenEdit_UpdateUnitCargo({guid=u.guid, mode='add_cargo', cargo={{num,db}}})
return
end

If I use this it creates a cargo type of "mount", which after some investigation I found that "type" = 1 and after creating ground units and mobile units manually I have found that
Type 1 = Mount
Type 2 = Ground Unit
Type 3 = Mobile Facility

So far after numerous tries, trial and error, guessing on syntax, etc, I cannot get the command to work to add a type = 2 or type = 3, For instance, if I wanted to load Ground Unit ID 32 Light Utility Vehicle onto a ship with LUA, how to I specify it is type 2? It always comes out type 1. I can find no examples or new documentation for this.

Thanks in advance,
Steve
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: LUA Cargo 2.0 Ground and Mobile Units Programming

Post by KnightHawk75 »

Good question. :D
Also why if you add one manually is it type-2 but then if you say add 2 more, all 3 get listed in lua as 1 with quantity 3, in addition to being changed to type 1 and lose the prior entry and name... yet the gui still correctly shows the original manual entry.

But then revert back to original if you manually remove the 2 I added there in the script.
cargowtf.jpg
cargowtf.jpg (557.22 KiB) Viewed 840 times
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

Re: LUA Cargo 2.0 Ground and Mobile Units Programming

Post by michaelm75au »

The new cargo method uses a different way to add cargo. It is run off the unit wrapper as a method. There is a 'delete' method too: u:deleteUnitCargo(cargo_guid)

Code: Select all

local u = ScenEdit_GetUnit({name='Single-Unit Airfield (4x 4000m+ Runways)', guid='CY41MA-0HMT2K1IOQ76K'})
print(u.cargo)
u:createUnitCargo( 3, 361, 'Test') -- create unit called Test' as cargo
print(u.cargo)
Michael
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

Re: LUA Cargo 2.0 Ground and Mobile Units Programming

Post by michaelm75au »

I will be retrofitting support for the new cargo types into UpdateUnitCargo() for the next build.

Code: Select all

local u = ScenEdit_GetUnit({name='Yokosuka Building 14 (Large)', guid='29541903-93d0-436b-9f08-a4696f12a4fc'})
print(u.cargo)
local a = ScenEdit_UpdateUnitCargo({guid='29541903-93d0-436b-9f08-a4696f12a4fc',mode='add_cargo',cargo={ {1,2541}, {3,361,3}, {4,7,4}, {2,246,2} } })
print(a.cargo)
{ }
{ [1] = { name = 'Yokosuka Building 14 (Large)', cargo = { [1] = { name = 'FV510 Warrior IFV', mass = 26, dbid = 2541, status = 'Operational', area = 19, guid = 'CY41MA-0HMT2MLKE7FB2', crew = 10, Type = 1, quantity = 1 }, [2] = { name = 'SAM Bty (Patriot [PAC-2]) #3143', mass = 87, dbid = 361, status = 'Operational', area = 144.600006103516, guid = 'CY41MA-0HMT2MLKE7FBB', crew = 44, Type = 3, quantity = 1 }, [3] = { name = 'SAM Bty (Patriot [PAC-2]) #3144', mass = 87, dbid = 361, status = 'Operational', area = 144.600006103516, guid = 'CY41MA-0HMT2MLKE7FCM', crew = 44, Type = 3, quantity = 1 }, [4] = { name = 'SAM Bty (Patriot [PAC-2]) #3145', mass = 87, dbid = 361, status = 'Operational', area = 144.600006103516, guid = 'CY41MA-0HMT2MLKE7FE1', crew = 44, Type = 3, quantity = 1 }, [5] = { name = 'Generic Wooden Pallet', mass = 0.0149999996647239, dbid = 7, status = 'Operational', area = 1.23850405216217, guid = 'CY41MA-0HMT2MLKE7FFC', crew = 0, Type = 4, quantity = 1 }, [6] = { name = 'Generic Wooden Pallet', mass = 0.0149999996647239, dbid = 7, status = 'Operational', area = 1.23850405216217, guid = 'CY41MA-0HMT2MLKE7FFE', crew = 0, Type = 4, quantity = 1 }, [7] = { name = 'Generic Wooden Pallet', mass = 0.0149999996647239, dbid = 7, status = 'Operational', area = 1.23850405216217, guid = 'CY41MA-0HMT2MLKE7FFG', crew = 0, Type = 4, quantity = 1 }, [8] = { name = 'Generic Wooden Pallet', mass = 0.0149999996647239, dbid = 7, status = 'Operational', area = 1.23850405216217, guid = 'CY41MA-0HMT2MLKE7FFI', crew = 0, Type = 4, quantity = 1 }, [9] = { name = 'ZTZ-96B #3146', mass = 41.5, dbid = 246, status = 'Operational', area = 29.0237998962402, guid = 'CY41MA-0HMT2MLKE7FFK', crew = 0, Type = 2, quantity = 1 }, [10] = { name = 'ZTZ-96B #3147', mass = 41.5, dbid = 246, status = 'Operational', area = 29.0237998962402, guid = 'CY41MA-0HMT2MLKE7FGN', crew = 0, Type = 2, quantity = 1 } }, guid = '29541903-93d0-436b-9f08-a4696f12a4fc' } }
...
Michael
Post Reply

Return to “Lua Legion”