I'd love to see this working, would be great for chain heal. I don't think you're accounting for the fact that GetPlayerMapPosition returns a value from 0 to 1 and is based on the current zone map, seems you're assuming it returns a value in yards?Hello guys.
I have made a "find clusters, rank them and heal them" type of code, and here it is :
Code:local sqrt = sqrt local GetPlayerMapPosition = GetPlayerMapPosition local table = table local twipe = table.wipe local tsort = table.sort local groupType = "raid"--"raid" --"party" local groupSize = 10 local minHealthForGrowth = 7000 -- 10k for 5ppl min, deficit 0 means full health local growthHealsHowManyTargets = 6 -- local function determineDistanceBetween(aUnit, anotherUnit) local tX1, tY1 = GetPlayerMapPosition(aUnit) if (tX1 + tY1 <= 0) then return nil -- not valid end local tX2, tY2 = GetPlayerMapPosition(anotherUnit) if (tX2 + tY2 <= 0) then return nil -- not valid end local xd = tX2-tX1 local yd = tY2-tY1 return sqrt(xd*xd + yd*yd) end local function IsInRange(u1,u2) local range = determineDistanceBetween(groupType..u1,groupType..u2) -- groupType used if range ~= nil and range<30 then return true end return false end local function IsInRangeOfPlayer(u1) local range = determineDistanceBetween("player",groupType..u1) -- groupType used if range ~= nil and range<30 then return true end return false end local function getDefHealth(unit) return UnitHealthMax(groupType..unit) - UnitHealth(groupType..unit) -- groupType used end local function sortDefHealth(aUnit, anotherUnit) return getDefHealth(aUnit) > getDefHealth(anotherUnit) end local function averageClusterDefHealth(unit) local playersInRange = {} local groupCount = 0 for x=1, groupSize do if IsInRange(unit,x) then -- count oneself table.insert(playersInRange, x) groupCount = groupCount + 1 end end tsort(playersInRange, sortDefHealth) local sumHP = 0 groupCount = math.min(growthHealsHowManyTargets, groupCount) -- possible targets for x=1, groupCount do sumHP = sumHP + getDefHealth(playersInRange[x]) end return sumHP/groupCount end local function findGoodTarget() local goodTarget = nil local maxDefHealth = minHealthForGrowth -- 10k for 5ppl min, deficit 0 means full health local tempDef = 0 -- temporary var to help performance for player=1, groupSize do if IsInRangeOfPlayer(player) then tempDef=averageClusterDefHealth(player) if tempDef > maxDefHealth then goodTarget = player maxDefHealth = tempDef end end end --for return goodTarget end local start, duration, enabled = GetSpellCooldown("Wild Growth") if (enabled ~= nil and enabled == 0) then return false elseif ( (start ~= nil and start > 0) and ( duration ~= nil and duration > 0)) then return false else local target = findGoodTarget() if target ~=nil then print ("Casting Wild Growth on "..UnitName(groupType..target)) CastSpellByID(48438,groupType..target) end end return false
Right now, I noticed it likes to cast on the first member of raid or party alot, maybe because he is always the lowest (beeing tank and all), hopefully it isnt a bug