i = 1
while (todrink == 1) and (i <= 3) do
for k,v in pairs (drinkqueue) do
if (healpriority == k) and (v ~= 0) then
Send (drinkqueue.v)
SetVariable("elixbal","0.5")
drinkqueue = {health = 0, mana = 0, ego = 0}
todrink=0
break
end -- if
end -- for
i = i+1
end -- while
II'm not quite sure I understand the outer loop in this part. i is never used within the loop, so it will either do the loop once if you send a drink, or it will repeat three times if you don't send a drink (which is impossible due to you needing a drink in the first place.
I'm also still not clear on some of those variables. If the heal priority is the same as the function I posted above, then you should go through that array using ipairs to ensure the proper order, and match drinkqueue up with that.
The following block of code is how I would do the whole thing (both functions and supporting tables). Obviously, it's not the only way to do it, but this way you just have one loop to deal with testing and sending data. This will require changing the max health/mana/ego variables to lowercase, but if that would complicate things too much for other scripts, just change the keys/values for the various tables here. I tested this out with some dummy data, and it seemed to work. I've also taken advantage of quite a few scripting tricks to make the loop easier to deal with, such as concatenating the "max"..healpriority[i] have only one loop take care of all the data comparisons.
healstart = { health = 2/3, mana = 0.25, ego = 1/3 }
healaction = { health = "drink health", mana = "drink mana", ego = "drink bromide" }
healqueues = { health = { "health", "mana", "ego" },
mana = { "mana", "ego", "health" },
ego = { "ego", "health", "mana" } }
healpriority = healqueues.health --make health the default
function change_priority(name,line,wildcards)
healpriority = healqueues[ wildcards[1] ] or healpriority
ColourNote ("aqua","","Healing priority: ",
"lime","", string.upper(wildcards [1]) )
for k,v in ipairs( healpriority ) do
Note( k.."="..v.." action = "..healaction[v] )
end
end
function system_drink()
i = 1
repeat
if tonumber( GetVariable( healpriority[i] ) ) <
tonumber( GetVariable( "max"..healpriority[i] ) ) * healstart[healpriority[i]] then
Send( healaction[healpriority[i]] )
SetVariable( "elixbal", "0.5")
i = 3
end
i = i + 1
until i > 3
end
edit: Once again foiled by the forum eating my table brackets. |