Sometimes I get a bunch of mobs in the XTarget window which spread my group members' pets' attention. I am trying to code a way so they always fixate on whichever mob has lowest HP percentage.
So I have created the function below, which I call at a later time within the code if needed. Unfortunately, it is not doing what I want. Can anyone spot where the logic is wrong?
So I have created the function below, which I call at a later time within the code if needed. Unfortunately, it is not doing what I want. Can anyone spot where the logic is wrong?
Code:
--- All pets in group to switch targets to the lowest mob in the xTarget window
local function TargetLowestHP()
---Lets pick the mob in the xTarget window with lowest HP, so pets stick to it before moving to the next mob.
local CurrentLowestMob = 0 --- This is just a default to declare the variable
local CurrentLowestMobID = 0 --- This is just a default to declare the variable
local CurrentLowestMobName = "0" --- This is just a default to declare the variable
local CurrentLowestMobCleanName = "0" --- This is just a default to declare the variable
local CurrentLowestMob = 100 --- This is just a default to declare the variable
local CombatMobs = mq.TLO.Me.XTarget()
local CombatSlots = mq.TLO.Me.XTargetSlots()
local PetOwner = "0" --- This is just a default to declare the variable
--- Lets find out the mob in Xtarget with lowest HPs
for i = 1, CombatSlots do
local MobsID = mq.TLO.Me.XTarget(i).ID() or 0 -- safety net: incase of a nil, make it 0
if MobsID > 0 and mq.TLO.Me.XTarget(i).Type.NotEqual(CORPSE)() and mq.TLO.Me.XTarget(i).PctHPs() > 0 then -- safety net: make sure mob(i) is actually alive
if mq.TLO.Me.XTarget(i).PctHPs() < CurrentLowestPctHPs then
CurrentLowestMob = mq.TLO.Me.XTarget(i).PctHPs()
CurrentLowestMobIndex = i
end
CurrentLowestMob = mq.TLO.Me.XTarget(CurrentLowestMobIndex).Name()
CurrentLowestMobCleanName = mq.TLO.Me.XTarget(CurrentLowestMobIndex).CleanName()
CurrentLowestMobID = mq.TLO.Me.XTarget(CurrentLowestMobIndex).ID()
--- Now that we know which of the mobs in XTarget with lowest HP, lets all switch to that one.
for j=0,NumberOfGroupMembers do
if mq.TLO.Group.Member(j).ID() and mq.TLO.Group.Member(j).Type.NotEqual(CORPSE)() and mq.TLO.Group.Member(j).Pet.ID() ~= 0 then
if mq.TLO.Group.Member(j).Pet.Target() ~= CurrentLowestMob then
mq.TLO.Group.Member(j).Pet.DoTarget(CurrentLowestMob)
mq.delay(50)
PetOwner = mq.TLO.Group.Member(j).CleanName()
mq.cmd('/dex %s /pet attack', PetOwner)
end
end
end
end
end
end

