Page 1 of 1
enumerate units
Posted: Wed Jul 22, 2020 10:34 am
by pclaurent
Simple question:
Is there a way to get a list of all existing units of a given side using a lua script?
RE: enumerate units
Posted: Wed Jul 22, 2020 5:00 pm
by KnightHawk75
If you want them not filtered by type at all...
local s = VP_GetSide({Side="myside"})
for k,v in pairs(s.units) do --units holds a table of all unit names and guids.
print('name: ' .. v.name .. ' guid: ' .. tostring(v.guid))
end
RE: enumerate units
Posted: Wed Jul 22, 2020 5:21 pm
by pclaurent
Wow, works great. Filtering by type should be a piece of cake. Thanks!
RE: enumerate units
Posted: Wed Jul 22, 2020 5:50 pm
by KnightHawk75
Keep in mind you don't have to do some of the filtering yourself anymore in 1146+
You can use enhancements to s:unitsBy() filtering mechanisms for type and then subtype or category with-in that type to get back a prefiltered table. Super handy and faster than old way of sub filtering manually.
ie
side:unitsBy('Ship')
side:unitsBy('Ship',2002)
side:unitsBy('Ship', 2002, 3003)
side:unitsBy('Ship',,3002)
etc
RE: enumerate units
Posted: Fri Jul 24, 2020 5:08 am
by pclaurent
got it - works fine. Tx