fargo007 Posted January 23, 2021 Posted January 23, 2021 Looking for a method to obtain the cargo status and mass of a static cargo object. Thanks for any direction. Have fun. Don't suck. Kill bad guys. https://discord.gg/blacksharkden/
Vantskruv Posted January 27, 2021 Posted January 27, 2021 (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 January 27, 2021 by Vantskruv
fargo007 Posted January 28, 2021 Author Posted January 28, 2021 Thank you, this is enough of a lead for me to figure it out! Have fun. Don't suck. Kill bad guys. https://discord.gg/blacksharkden/
Zeathe Posted December 8, 2024 Posted December 8, 2024 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
Recommended Posts