Originally Posted by
Wildbreath
use objectscount one time and save it returns to value, else you call it each time in cycle
This is my code:
Code:
local uau_cache_time = { }
local uau_cache_count = { }
local uau_cache_dura = 0.5
function UnitsAroundUnit(unit, distance, checkCombat)
local uau_cache_time_c = uau_cache_time[unit..distance..tostring(checkCombat)]
if uau_cache_time_c and ((uau_cache_time_c + uau_cache_dura) > GetTime()) then
return uau_cache_count[unit..distance..tostring(checkCombat)]
end
if UnitExists(unit) then
local total = 0
local totalObjects = ObjectsCount(unit,distance)
for i = 1, totalObjects do
local object = ObjectByIndex(i)
if UnitExists(object) then
local reaction = UnitReaction("player", object)
local combat = UnitAffectingCombat(object)
if reaction and reaction <= 4 and (checkCombat or combat) then
if Distance(object, unit) <= distance then
total = total + 1
end
end
end
end
uau_cache_count[unit..distance..tostring(checkCombat)] = total
uau_cache_time[unit..distance..tostring(checkCombat)] = GetTime()
return total
else
return 0
end
end
While I in combat,the fps from 100+ to 10