Hi all!
I known this function Spring.GetUnitNearestEnemy but if i need get all enemy units in specific range. is it possible?
About function in lua GetUnitNearestEnemy
Moderator: Moderators
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: About function in lua GetUnitNearestEnemy
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
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
- BrainDamage
- Lobby Developer
- Posts: 1164
- Joined: 25 Sep 2006, 13:56
Re: About function in lua GetUnitNearestEnemy
Code: Select all
Spring.GetUnitsInSphere(x,y,z,radius,Spring.ENEMY_UNITS)
Re: About function in lua GetUnitNearestEnemy
Much better, totally forgot Spring.ENEMY_UNITS even existed.BrainDamage wrote:also, this should be moved to lua forumCode: Select all
Spring.GetUnitsInSphere(x,y,z,radius,Spring.ENEMY_UNITS)
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: About function in lua GetUnitNearestEnemy
oh me too :p