Xanthix,Mar 25 2005, 02:21 PM Wrote:Even if the code is a little down-and-dirty, I'd really like to see the algorithm you use. I'm curious, and I have an idea for an interesting mod. Even if you don't post it in the UI forum (although I think lots of people would love it!), would you consider posting at least the targetting code it here?
[right][snapback]71902[/snapback][/right]
Ok, here it is. I still haven't used it on an honest-to-goodness instance run, but I think it works pretty well (now that tab targeting works). Friday night after our Zul'Farrak run I will put it up for download.
Any good ideas for a name? I called it AggroHelper but that isn't informative or interesting.
Edit:
I forgot to mention that I will credit Ravage with the idea for the mod. Do you want to be credited as Ravage or something different/more specific?
Code:
-- The real work of the mod
function AggroHelper()
-- If disabled, don't do anything
if ( AggroHelper_disabled ) then return; end
local orig_target = UnitName("target");
if ((orig_target == nil) or (UnitIsEnemy("target", "player"))) then
return;
end
local cur_enemy_target;
local cur_enemy;
local i;
AggroHelper_Debug("Aggro Help for " .. orig_target .. "!");
for i = 1,AggroHelper_target_search_limit do
TargetNearestEnemy();
cur_enemy = UnitName("target");
if ((cur_enemy == nil) or (UnitIsFriend("target", "player"))) then
AggroHelper_Announce(" ** No enemy targetable **");
break;
end
-- We have found an enemy within range of the function. Now "assist" it
AssistUnit("target");
cur_enemy_target = UnitName("target");
AggroHelper_Debug(" --- checking " .. cur_enemy .. " : " .. cur_enemy_target .. " ---");
if (cur_enemy_target == orig_target) then
-- We have found a match! Target the last enemy, it should be the right one.
TargetLastEnemy();
AggroHelper_Debug(" ** selected " .. UnitName("target") .. " **");
return;
end
end
-- If we reach here, after AggroHelper_target_search_limit tries, we couldn't
-- find a suitable candidate. Target our original target again, as that
-- seems to be the least surprising thing to do.
AggroHelper_Announce(" ** No enemy found targeting " .. orig_target .. " **");
TargetByName(orig_target);
end