Here is what I've written thus far...
This not only gets the entities at the location but also validates and sorts entities by range.
Any suggestions?
Note: This will be used for the chain-lightning revamp.
Resin
---Code---- Code: Select all
GetValidTargetsAlongScaledVector = function(self, entity1, entity2, scale)
if self.BeamDebug then WARN('GetValidTargets') end
local posV1 = entity1:GetPosition()
local posV2 = entity2:GetPosition()
local modPos = utilities.GetScaledDirectionVector( posV1, posV2, scale )
if self.BeamDebug then
WARN('modPos x: ', modPos[1],'modPos y: ', modPos[2],'modPos z: ', modPos[3])
end
local targets, targByDist = {}
local targets = GetEntitiesInRect( Rect(modPos[1] - scale, modPos[3] - scale, modPos[1] + scale, modPos[3] + scale) )
if targets == nil or table.getsize(targets) < 0 then return nil end
for a, b in targets do
if not b:BeenDestroyed() and b:GetHealth() > 0 then
table.insert(targByDist, {dist = utilities.XZDistanceTwoVectors(posV1, b:GetPosition()), unit = b})
end
end
table.sort(targByDist, sort_by('dist'))
if self.BeamDebug then
for c, d in targByDist do
WARN(' Unit: ', d:GetEntityId(), ' Distance: ', utilities.XZDistanceTwoVectors(posV1, d:GetPosition()) )
end
end
return targByDist
end,