Jump to content

How can I get the mass of a static cargo object?


Recommended Posts

Posted (edited)

Hoggit has a good reference to DCS lua scripting, sometimes with examples, and sometimes you need to test and trial how to implement the functions.

https://wiki.hoggitworld.com/view/DCS_func_getByName

https://wiki.hoggitworld.com/view/DCS_func_getCargoWeight

 

-- not 100% sure if this is the correct code to retrieve a static object.
cargoObject = StaticObject.getByName("cargo666")
-- currently not sure the correct way to get the data, I think it is either of these two.
weight = cargoObject.getCargoWeight()
weight = StaticObject.getCargoWeight(cargoObject)

 

EDIT:

Also, you can get a table of data with all the information concerning the object (I guess), in either of these two ways:

https://wiki.hoggitworld.com/view/DCS_func_getDescByName

https://wiki.hoggitworld.com/view/DCS_func_getDesc

Though, the structure of the table may be different depending on what type of object it is, currently I am not sure where to find the reference of this, but you can print the table of the object in the mission, and do some detective work from there....

Edited by Vantskruv
  • 3 years later...
Posted

Necro Thread: Because I found this searching for answers to the new warehouse.... Thanks Google, Sorta.... I think updated code may help others...

-- Get the Static Object
-- WARNING: you can use Unit.getByName() and get the SO as a Unit and then warehouse functions and cargo functions fail
local AmmoStack = StaticObject.getByName("Static Ammo-1")

-- Get the Static Object instance description with :getDesc()
trigger.action.outText("SO/Unit <Static Ammo-1>: ".. net.lua2json(AmmoStack:getDesc()), 30)
-- Result: SO/Unit <Static Ammo-1>: {"life":0,"attributes":{"Cargos":true},"_origin":"","category":4,"displayName":"Ammo","typeName":"ammo_cargo","box":{"min":{"y":-0.0673937946558,"x":-0.65713477134705,"z":-0.58641439676285},"max":{"y":1.0960557460785,"x":0.65079057216644,"z":0.57894480228424}}}

-- Get the Static Object instance cargo weight with :getCargoWeight()
trigger.action.outText("CargoWeight <Static Ammo-1>: ".. net.lua2json(AmmoStack:getCargoWeight()), 30)
-- Result: CargoWeight <Static Ammo-1>: 1500


-- Access the Warehouse of the Cargo Static Object
local AmmoStackWH = Warehouse.getCargoAsWarehouse(AmmoStack)

-- Get the Warehouse Inventory within the cargo object instance with :getInventory()
trigger.action.outText("WH <Static Ammo-1>: ".. net.lua2json(AmmoStackWH:getInventory()), 30)
-- Result: WH <Static Ammo-1>: {"liquids":[0,0,0],"weapon":{"weapons.bombs.British_MC_500LB_Bomb_Mk2":1,"weapons.missiles.AGM_65K":1,"weapons.bombs.Mk_82":1},"aircraft":{}}

TBD -- I am not sure if the inventory properly impacts weight.  I think it does based on the fact that the cargo itself is less than 1500 in ME

Screen_241208_084108.jpg

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...