Hey.
I have 4 variables for summon health:
summ1health
summ2health
summ3health
summ4health
I also have 4 variables with summon names:
summon1, summon2, summon3 and summon4
These are set auto by my script/triggers.
Now:
I want to have an if-script to automatically send "say, $summon2, defend me" if $summ1health drops below 4.
Well, what I really want is for it to send "say, (summon with highest health), defend me, and then set a variable, say $tanker to (whichever $summon1-4) is tanking.
I probably don't make much sense, the script is really long (since I don't really know perl well yet, and made it the "simple" way. I guess I can paste the whole thing here, it's like 100 lines or something.
Actually, here's what I've done so far, maby it'll make more sense. What's left to do is the rotate-thingy, where the summon with most health is tanking, and switch if it gets low.
# Rotate-tanking for 1-4 summons
# The trigger:
# ^(.*?)\-\-\> ([a-zA-Z ]+):([^,]+),? ?([a-zA-Z ]+)?:?([^,]+)?,? ?([a-zA-Z ]+)?:?([^,]+)?,? ?([a-zA-Z ]+)?:?([^,]+)?(.*?)$
#Original line: --> Giant weasel:+, Wererat:+, Huge spider:+, Orc:+
#Note: summon names are random
sub rotatescript
{
my ($thename, $theoutput, $wildcards) = @_;
That is an incredibly long script. My first reaction when I see virtually the same coded repeated four times is, that this should be a subroutine. Copy and paste is tedious and makes it hard to debug.
I'm not a Perl expert so I'll do my solution in Lua. If you want to stick to Perl, you can take the ideas from it.
health_levels = {
["+"] = 6,
["A"] = 5,
["B"] = 4,
["C"] = 3,
["D"] = 2,
["E"] = 1 }
-- look up health in table, convert to a number
function convert_health (which)
-- get rid of tilde (~) from string
which = string.gsub (which, "%~", "")
return health_levels [which] or 0
end -- convert_health
function rotatescript (thename, theoutput, wildcards)
local summon1, summ1health,
summon2, summ2health,
summon3, summ3health,
summon4, summ4health
summon1 = GetTriggerInfo (thename, 102) -- name of first summon
summ1health = convert_health (GetTriggerInfo (thename, 103)) -- health of first summon
summon2 = GetTriggerInfo (thename, 104) -- name of 2nd summon
summ2health = convert_health (GetTriggerInfo (thename, 105)) -- health of 2nd summon
summon3 = GetTriggerInfo (thename, 106) -- name of 3rd summon
summ3health = convert_health (GetTriggerInfo (thename, 107)) -- health of 3rd summon
summon4 = GetTriggerInfo (thename, 108) -- name of 4th summon
summ4health = convert_health (GetTriggerInfo (thename, 109)) -- health of 4th summon
local highestnumber, highestname
-- assume 1st summon is highest first
highestnumber = summ1health
highestname = summon1
-- see if 2nd summon has more health
if summ2health > highestnumber then
highestnumber = summ2health
highestname = summon2
end -- 2nd higher than first
-- see if 3rd summon has more health
if summ3health > highestnumber then
highestnumber = summ3health
highestname = summon3
end -- 3rd higher than others
-- see if 4th summon has more health
if summ4health > highestnumber then
highestnumber = summ4health
highestname = summon4
end -- 4th higher than others
-- the highest name is our tanker
SetVariable ("tanker", highestname)
Send ("say, " .. highestname .. ", defend me")
end -- rotatescript
First thing is to make turning the health letter into a number into a separate function, and use a look-up table for the conversion.
Then call that function for each of the 4 summons, remembering its health.
Then we keep track of the one with highest health so far, and with a few ifs, work out which one is to be the tank. If there were more than 4 I would be doing a sort, but this isn't too bad like this.
Then we set the variable, and do the "say", and we are done. :)
Okay I tried out Lua some and it looks really nice.
There are however some issues with your script that I wonder if you could help me out with.
First off, there's trouble if 2 summons have the same name, for instance "large rat", or say that all 4 is named "large rat", the script will just keep saying "say large rat, defend me".
And secondly, This trigger runs every round. Is there a way to only send "say <summon>, defend me" when we get a new tank?
First off, there's trouble if 2 summons have the same name, for instance "large rat", or say that all 4 is named "large rat", the script will just keep saying "say large rat, defend me".
Well, what would you type if you weren't using a script?
Quote:
And secondly, This trigger runs every round. Is there a way to only send "say <summon>, defend me" when we get a new tank?
Change the last couple of lines to see if the tanker has changed:
-- the highest name is our tanker
if GetVariable ("tanker") ~= highestname then
SetVariable ("tanker", highestname)
Send ("say, " .. highestname .. ", defend me")
end -- if tank has changed
If I were not using a script I would type:
(If say <summon1> and <summon2> have the same name:
"say, <summonname> 2, defend me"
and if 3 have the same name:
or "say, <summonname> 3, defend me" (if 3 has the most life of course) :)
--
The other part of the script worked fine, no spammy spam now, thanks Nick.