Finding lowest health group member

Post Reply
Drevarr
Posts: 43
Joined: Tue Aug 06, 2013 12:07 am
Location: GA, USA

Finding lowest health group member

Post by Drevarr »

I'm attempting to find the group member with the lowest health for establishing a heal target.
The following code is working, just wondering if there is a more efficient or alternative method for doing this activity.
Code: [show] | [select all] lua
function table.min( myTable)
   local minValue
   for name, value in ipairs( myTable) do
      minValue = ((not minValue or value < minValue) and value)  or minValue
   end
   return minValue
end



--Populate myGroup and myHpPercent from group command output triggers

myGroup = {"Drella", "Ilshad", "Idor", "Caleel", "Istria"}
myHpPercent = {100, 90, 49, 100, 50}

--Find index of lowest health% and utilize index to find player

print(myGroup[table.index_of(myHpPercent, table.min(myHpPercent))])
print(table.min(myHpPercent).."% of Max Health")
Thanks for any suggestions.
Drevarr

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Finding lowest health group member

Post by Vadi »

It's quite fine for your purposes and I wouldn't worry about it. Especially with such a small data set.

There are micro-optimizations you could do - but it's not worth to get hung up on that stuff unless this code will be running a thousand times a second on hundreds of players.

Drevarr
Posts: 43
Joined: Tue Aug 06, 2013 12:07 am
Location: GA, USA

Re: Finding lowest health group member

Post by Drevarr »

Thanks for the review. It shouldn't exceed more than 20 members and 1 check every combat pulse for any given engagement.

Drevarr

Post Reply