A more efficient 'enemies in range'?
So this is what I have right now for seeing if there are 3+ enemies in combat and within range of whirlwind. Is there a more elegant solution? Broken out into multiple ifs just for debugging purposes.
Code:
function are3EnemiesInRange() |
I don't know how nameplate numbering works, but if it always starts at 1 then maybe you could add this optimization:
Lua Code:
|
UnitCanAttack should be used insteadof UnitIsEnemy and UnitAffectingCombat since Whirlwind will hit a unit whether it is in combat or not. UnitExists is implied if any Unit function returns true so it can be removed. Also, inRange only updates in one place so you should check it's value right after instead of at the end of the loop where it may not have changed.
Code:
function are3EnemiesInRange() |
You can also use C_NamePlate.GetNamePlates to get only visible nameplates. A plus to this is it gives you the nameplate.
Lua Code:
|
Perfect Vrul! I wasn't aware of UnitCanAttack, between that and removing the exists check I should be able to drop some time off the function.
DahkCeles - nameplates is a fixed array, it doesn't compress or expand as nameplates are added or removed. If nameplate1 points to a mob, and that mob dies, nameplate1 becomes a null even though nameplate2 may still point to a mob. |
If you value efficiency over elegance then you want a slightly modified version of what jeruku posted:
Code:
function are3EnemiesInRange() Code:
local pairs_iter, nameplates = pairs(NamePlateDriverFrame.pools.pools.NamePlateUnitFrameTemplate.activeObjects) |
Nice. Yeah, this is throttled to once ever 100ms.
Thanks! -Rick |
All times are GMT -6. The time now is 01:27 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI