• Hail Guest!
    We're looking for Community Content Contribuitors to Stratics. If you would like to write articles, fan fiction, do guild or shard event recaps, it's simple. Find out how in this thread: Community Contributions
  • Greetings Guest, Having Login Issues? Check this thread!
  • Hail Guest!,
    Please take a moment to read this post reminding you all of the importance of Account Security.
  • Hail Guest!
    Please read the new announcement concerning the upcoming addition to Stratics. You can find the announcement Here!

EC - Target lowest health pet, custom function

P

pgib

Guest
Second time i look at LUA, so this might be the least elegant function ever seen: targets the pet that has the lowest health in you current set of followers.

(in PetWindow.lua)
Code:
function PetWindow.GetPetHealth(petId)
	local h = WindowData.MobileStatus[petId].CurrentHealth
	return h
end

function PetWindow.TargetLowestHealthPet()
	local targetId = nil
	local lowestHealth = -1
	local i
	for i=1,PetWindow.totalPets do
		local id = WindowData.Pets.PetId[i]
		local health = PetWindow.GetPetHealth(id)
		if((lowestHealth == -1) or (health < lowestHealth)) then
			targetId = id
			lowestHealth = health
		end
	end
	if(targetId ~= nil) then
		HandleSingleLeftClkTarget(targetId)
	end
end
Then i use it in a macro like this:

Slot 1: script PetWindow.TargetLowestHealthPet()
Slot 2: bandage selected target

I find it quite useful when i take my dogs out, I'm still testing it, works well so far.

EDIT: of course it was fraught with problems (the table is used as reference didn't keep track of changes in the pet set, maybe). Now it works even after changing the pets. Sorry but coding for the EC is like moving blindfolded with a dark sky in a foggy night under heavy rain.
 
Top