When leveling there is a lot of humanoid packs thats most likely will kill you that I like to ignore. So I made my own "get nearest target" function with some extra parameters. I share it if anyone would wanna use it. Basicly I grind on beasts, and "ignore" humanoids since they are usually in large groups.
-- Target selection parameters
pullDistance = 88; -- searches for enemies within X yards
skipHumanoid = true; -- Skip killing humanoid (usually in groups etc...)
skipUndead = true; -- Skip killing undead (usually in groups etc...)
maxLevelDiff = 1; -- pull mobs who are maximum X level above our own level
minLevelDiff = 5; -- pull mobs who are minimum X levels below our own level
function AssignTarget(localObj, bot_)
if (bot_ == 1) then
targetObj = 0;
-- Fetch last target
lastTarget = GetTarget();
-- Clear last target if it's dead or tapped by other player
if (IsDead(lastTarget) == 1 or (IsTapped(lastTarget) == 1 and IsTappedByMe(lastTarget) == 0)) then
ClearTarget();
lastTarget = 0;
else
targetObj = lastTarget;
end
-- Fetch the nearest valid target
nearestTarget = 0;
mobDistance = pullDistance;
local objectTable = GetObjects();
for i,v in pairs(objectTable) do
if IsDead(i) == 0 and v.type == 3 and CanAttack(i) == 1 and IsCritter(i) == 0
and ((GetLevel(i) <= GetLevel(localObj) + maxLevelDiff and GetLevel(i) >= GetLevel(localObj) - minLevelDiff) or GetUnitsTarget(i) == localObj)
and GetDistance(i) < pullDistance and (IsTapped(i) == 0 or IsTappedByMe(i) == 1) then
if (skipHumanoid and GetCreatureType(i) == 'Humanoid' and GetUnitsTarget(i) ~= localObj) then
-- do nothing
elseif (skipUndead and GetCreatureType(i) == 'Undead' and GetUnitsTarget(i) ~= localObj) then
-- do nothing
else
-- return the closest mob, or a mob that is attacking us
if (GetDistance(i) < mobDistance) then
-- New closest distance
mobDistance = GetDistance(i);
nearestTarget = i;
end
end
end
end
-- Select the closest target if our last target is dead
if (lastTarget == 0) then
targetObj = nearestTarget;
end
-- Check: If we are in combat but we have no targets perhaps it's low level mob, kill it
if (lastTarget == 0 and nearestTarget == 0 and IsInCombat() == 1) then
targetObj = GetTarget();
end
-- Check: Swap to the nearest enemy if not in combat yet
if (IsInCombat() == 0 and GetDistance(nearestTarget) < GetDistance(lastTarget)) then
targetObj = nearestTarget;
end
-- Check: Swap to the target with lowest HP
lastTargetHP = GetHealthPercentage(lastTarget);
nearestTargetHP = GetHealthPercentage(nearestTarget);
if (lastTargetHP >= nearestTargetHP and GetUnitsTarget(nearestTarget) == localObj) then
targetObj = nearestTarget;
end
else
targetObj = GetTarget(); -- Set target for rotation (player selection)
end
return targetObj;
end
-- Target selection parameters
pullDistance = 88; -- searches for enemies within X yards
skipHumanoid = true; -- Skip killing humanoid (usually in groups etc...)
skipUndead = true; -- Skip killing undead (usually in groups etc...)
maxLevelDiff = 1; -- pull mobs who are maximum X level above our own level
minLevelDiff = 5; -- pull mobs who are minimum X levels below our own level
function AssignTarget(localObj, bot_)
if (bot_ == 1) then
targetObj = 0;
-- Fetch last target
lastTarget = GetTarget();
-- Clear last target if it's dead or tapped by other player
if (IsDead(lastTarget) == 1 or (IsTapped(lastTarget) == 1 and IsTappedByMe(lastTarget) == 0)) then
ClearTarget();
lastTarget = 0;
else
targetObj = lastTarget;
end
-- Fetch the nearest valid target
nearestTarget = 0;
mobDistance = pullDistance;
local objectTable = GetObjects();
for i,v in pairs(objectTable) do
if IsDead(i) == 0 and v.type == 3 and CanAttack(i) == 1 and IsCritter(i) == 0
and ((GetLevel(i) <= GetLevel(localObj) + maxLevelDiff and GetLevel(i) >= GetLevel(localObj) - minLevelDiff) or GetUnitsTarget(i) == localObj)
and GetDistance(i) < pullDistance and (IsTapped(i) == 0 or IsTappedByMe(i) == 1) then
if (skipHumanoid and GetCreatureType(i) == 'Humanoid' and GetUnitsTarget(i) ~= localObj) then
-- do nothing
elseif (skipUndead and GetCreatureType(i) == 'Undead' and GetUnitsTarget(i) ~= localObj) then
-- do nothing
else
-- return the closest mob, or a mob that is attacking us
if (GetDistance(i) < mobDistance) then
-- New closest distance
mobDistance = GetDistance(i);
nearestTarget = i;
end
end
end
end
-- Select the closest target if our last target is dead
if (lastTarget == 0) then
targetObj = nearestTarget;
end
-- Check: If we are in combat but we have no targets perhaps it's low level mob, kill it
if (lastTarget == 0 and nearestTarget == 0 and IsInCombat() == 1) then
targetObj = GetTarget();
end
-- Check: Swap to the nearest enemy if not in combat yet
if (IsInCombat() == 0 and GetDistance(nearestTarget) < GetDistance(lastTarget)) then
targetObj = nearestTarget;
end
-- Check: Swap to the target with lowest HP
lastTargetHP = GetHealthPercentage(lastTarget);
nearestTargetHP = GetHealthPercentage(nearestTarget);
if (lastTargetHP >= nearestTargetHP and GetUnitsTarget(nearestTarget) == localObj) then
targetObj = nearestTarget;
end
else
targetObj = GetTarget(); -- Set target for rotation (player selection)
end
return targetObj;
end