Page 1 of 1

Best way to get nearest unit of a certain type

Posted: 12 Jun 2011, 11:17
by Jools
I'm thinking of adding a feature to my map, namely that if a team is in the possession of a certain alien unit, then other aliens are more likely to join that team (maybe depending on distance to it). Would this function do it?

Code: Select all

Spring.GetTeamUnitsByDefs

 ( number teamID, number unitDefID | { number unitDefID1, ... } )
   -> nil | unitTable = { [1] = number unitID, etc... }
Do I supply the team id and unitDefID and then get just a number in return? I'm sorry but the description is a bit unclear.

The other way would be to store this information in a table when this other unit is created, would that be faster and more efficient than to lookup the value dynamically when a unit is created from a meteorite? Or should I try to minimise the amount of static variables in a gadget instead?

Sorry if this is a stupid question.

Re: Best way to get nearest unit of a certain type

Posted: 12 Jun 2011, 13:32
by FLOZi
You supply the teamID and unitDefID and get a TABLE of the units of that unitdef on that team.

IMO I'd go with this method and see how it works, unless you're spawning aliens many times a second I don't see it being a problem.