I need to count how many of each type of cargo (dbid) there is in a unit. But can't figure out the right algo.
So far I can obtain this result, a loop returning in the console the list of all cargo guid's loaded in the unit.
So I can see that in this example, in the unit, there are:Output is:
2346
2346
2568
2568
2568
2436
2436
2266
2266
2266
2 * #2346
3 * #2568
2 * #2436
3 * #2266
Of course the size of the file is unknown.
But can't find the right algorithm to have the program do it for me ... Yes, I know it's basic
But would appreciate some help ...
-------------------------------------------------------
local selectedUnit = ScenEdit_SelectedUnits()
local unitGuid = selectedUnit.units[1].guid
local c = ScenEdit_GetUnit({guid=unitGuid}).components
local i = 0
local cargoType
for _ in pairs(c) do
if c[_].comp_type == 'Cargo' then
cargoType = c[_].comp_dbid
i = i + 1
print(cargoType)
end
end

