Page 1 of 1
About function in lua GetUnitNearestEnemy
Posted: 16 Oct 2013, 09:24
by Broker
Hi all!
I known this function Spring.GetUnitNearestEnemy but if i need get all enemy units in specific range. is it possible?
Re: About function in lua GetUnitNearestEnemy
Posted: 16 Oct 2013, 09:48
by Silentwings
Yes, use a Spring.GetUnitsIn**** call and then iterate through the unit list it returns to find enemy units.
Re: About function in lua GetUnitNearestEnemy
Posted: 16 Oct 2013, 18:47
by FLOZi
Code: Select all
local x, y, z = Spring.GetUnitPosition(unitID)
local teamID = Spring.GetUnitTeam(unitID) -- if you don't know it already
local unitsInRange = Spring.GetUnitsInCylinder(x,y,z, RANGE)
local enemyInRange = {}
for _, unitInRangeID in pairs(unitsInRange) do
local unitTeam = Spring.GetUnitTeam
if not Spring.AreTeamsAllied(unitID, unitInRangeID) then
table.insert(enemyInRange, unitInRangeID)
end
end
Just a e.g. it isn't the cleanest possible
Re: About function in lua GetUnitNearestEnemy
Posted: 16 Oct 2013, 19:02
by BrainDamage
Code: Select all
Spring.GetUnitsInSphere(x,y,z,radius,Spring.ENEMY_UNITS)
also, this should be moved to lua forum
Re: About function in lua GetUnitNearestEnemy
Posted: 16 Oct 2013, 19:33
by FLOZi
BrainDamage wrote:Code: Select all
Spring.GetUnitsInSphere(x,y,z,radius,Spring.ENEMY_UNITS)
also, this should be moved to lua forum
Much better, totally forgot Spring.ENEMY_UNITS even existed.

Re: About function in lua GetUnitNearestEnemy
Posted: 16 Oct 2013, 20:23
by Silentwings
oh me too :p