er2.getSoldiersInArea 3

Get all alive soldiers within a specific radius from a specific position, ordered by the distance from the given position.
Notice: After a new soldier spawns or dies, this function might get a few instant before returning a correctly updated value.


Return value

Return TypeDescription
TableThe script fills the Table given as parameter with the found soldiers, indexing it from 1,...,n ordered by distance from the given position and returns the filled table

Parameters

ParameterTypeDescription
1vec3Center of the radial search
2floatRadius where to search soldiers in
3TableA Lua initialized Table to fill with found soldiers

Examples

--get a list of all soldiers arount pos 0,0,0 for 20 meters
local closeSoldiers = {}  -- Create an empty table.
er2.getSoldiersInArea(vec3(0,0,0), 20, closeSoldiers); -- fill it with all soldiers currently alive

--print the name of each soldier
for key, soldier in pairs(closeSoldiers) do
    print("Name: "..soldier.getName())
end

Back to Scripting API