Try taking a look at my plugin for doing this as www.magnumsworld.com/muds. It will actually go a bit beyond what you are asking, though you will need to modify the triggers and script a bit to fit your own mud.
The following should 'fix' it to work with yours. The parts I changed, added or which I felt the need to point out are commented with "'***", where possible. The only part that is not is the 'match' line in the trigger intself. ;)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="HitBar_Plugin"
author="Kagehi"
language="vbscript"
purpose="Gives visual warning of when your hp (or hp and cp) drop below a set level."
save_state="y"
date_written="2002-10-11"
date_modified="2002-10-20"
requires="3.25"
version="2.7"
id="fba8f08ebbdd03bcae94ab05"
>
<description trim="y">
<![CDATA[
This plugin designed by request of Bale. ;)
Commands>
hitbar:help - This screen.
hitbar:% <number> - Sets the percentage below which to show the warning color.
hitbar:% inc - Incremental color, i.e. HP, CP and mob condition change based on condition.
Range is Green through Yellow to Red.
hitbar:% inc2 - Incremental color, ranges from Blue through Violet to Red.
hitbar:% inc3 - Incremental color, HP are G>Y>R, while CP are B>V>R.
hitbar:% inc4 - Incremental color, HP are B>V>R, while CP are G>Y>R.
g, good .................... hitbar:good <color> - Color used for good health in % format.
w, warn, warning ........... hitbar:warn <color> - Color used for bad health in % format.
b, back, background ........ hitbar:back <color> - Color used a background.
Colors are in the form of a name (Red, Blue, Yellow) or a number (#FF4425).
]]>
</description>
</plugin>
<aliases>
<alias
name="SetHealth"
script="SetHealth"
match="^hitbar:(\w{1,}|\S)( \S{1,})"
enabled="y"
regexp="y"
ignore_case="y"
>
</alias>
</aliases>
<triggers>
<trigger
enabled="y"
match="HP: (/d+) EP: (/d+)(.*)"
name="HitBar"
omit_from_log="y"
omit_from_output="y"
sequence="1"
regexp="y"
script="HealthDisp"
>
</trigger>
</triggers>
<script>
<![CDATA[
sub OnPluginInstall
if world.getvariable("Version") <> "2.6" then
world.setvariable "goodcol","#00FF00"
world.setvariable "warncol","Red"
world.setvariable "backcol","Black"
world.setvariable "perc","0"
'*** These lines are unchanged. However, unless you mud
'*** provides your opponents status while in combat along
'*** side of your condition, it won't do anything.
'*** If the mud does, then you will likely need to change
'*** these phrases to match what yours shows. There
'*** "MUST" be that same number of phrases as there
'*** are Hues and Lums, if you add more phrases than
'*** are currently here the plugin will crash, if you
'*** have less, then it will never show the opponents
'*** condition in red.
Types = "perfect health,few scratches,slightly bruised,has some cuts,few wounds,wounded,badly wounded,nasty wounds,deep gashes"
Types = Types + ",blood flowing freely,near death"
Hues = "110,99,88,77,66,55,44,33,22,11,0" '** Hues running from blue to red. (ranges are from 0 to 359).
Sat ="180" '** Saturation level (255 = full color, 180 means it is a bit grey).
Lums = "128,128,128,128,128,128,128,128,128,128,128" '** Luminosities (brightness).
world.setvariable "Types",Types
world.setvariable "Hues",Hues
world.setvariable "Sat",Sat
world.setvariable "Lums",Lums
world.setvariable "HPInc","0"
world.setvariable "CPInc","0"
world.setvariable "Version","2.6"
end if
end sub
sub HealthDisp (name, output, wilds)
dim perc, test, count
dim gfore, wfore, backc, nfore, nback
dim Types, Hues, Sat, Lums, TLine
dim temp
gfore = world.getvariable("goodcol") '** Retrieve all our colors
wfore = world.getvariable("warncol")
backc = world.getvariable("backcol")
'*** Also not changed, but these "should" be changed to
'*** reflect the ANSI color that your health bar is normally,
'*** since only the numbers actually get colored.
nfore = world.RGBColourToName(world.NormalColour(8)) '** Get our default colors (so prompt stays gray).
nback = world.RGBColourToName(world.NormalColour(1))
Types = split(world.getvariable("Types"),",") '** Get the settings for mob damage.
Hues = split(world.getvariable("Hues"),",")
Sat = world.getvariable("Sat")
Lums = split(world.getvariable("Lums"),",")
'*** The original line is merely commented out here.
'perc = cint((wilds(1) / wilds(2)) * 100) '** HP percentage.
'*** These are the 'new' lines to make it work for your hp.
'*** Note that all we really do is save a copy of the last
'*** maximum value to use later, instead of getting it from
'*** the captured line (which in your case doesn't provide it.
CHP = int(wilds(1))
LMax = getvariable("MaxHP")
LMax = LMax * abs(LMax >= CHP) + CHP * abs(LMax < CHP)
setvariable "LMax",LMax
perc = cint(CHP / LMax) * 100)
test = world.getvariable ("perc") '** Match for the non-incremental method.
if test = "inc" then '** Are we using the incremental version?
dim hbcols, HPinc, CPinc
hbcols = split(GetHBCol,",") '** Get the 'Normal' foreground and back ground to use later.
gfore = hbcols(0)
backc = hbcols(1)
HPinc = world.getvariable("HPInc") '** Find the direction of the color change.
CPinc = world.getvariable("CPInc")
if HPinc = "0" then '** Figure out the Hue for this % and direction.
'** Colors are circular, so going either direction will give us red at the end.
t1 = int(120 * (perc/100)) '** This one starts at green and goes down.
else
t1 = 360 - int(120*(perc/100)) '** This one starts at blue and goes up.
end if
t2 = int(58 * (perc/100)) + 100 '** Figure out the Intensity (Lum) for this %.
wfore = HSLtoRGB(t1, 255, t2) '** Get the color. ;)
'*** Again. These are the originals.
'world.colourtell gfore, backc, "HP: ["
'world.colourtell "#" & wfore, backc, wilds(1) & "/" & wilds(2) '** Show the colored HP.
'world.colourtell gfore, backc, "] CONC: ["
'*** And the new lines.
world.colourtell gfore, backc, "HP: "
world.colourtell "#" & wfore, backc, wilds(1) '** Show the colored HP.
world.colourtell gfore, backc, " EP: "
'*** And our second percentage.
'perc = cint((wilds(3) / wilds(4)) * 100) '** Find the % for the CONC:
'*** Its replacement.
CEP = int(wilds(2))
EMax = getvariable("MaxEP")
EMax = EMax * abs(EMax >= CEP) + CEP * abs(EMax < CEP)
setvariable "EMax",EMax
perc = cint(CEP / EMax) * 100) '** Find the % for the EP:
if CPinc = "0" then '** Figure out the Hue for this % and direction.
t1 = int(120 * (perc/100)) '** This one starts at green and goes down.
else
t1 = 360 - int(120*(perc/100)) '** This one starts at blue and goes up.
end if
t2 = int(58 * (perc/100)) + 100 '** Figure out the Lum for this %.
wfore = HSLtoRGB(t1, 215, t2) '** Get the color.
'*** Our finish.
'world.colourtell "#" & wfore, backc, wilds(3) & "/" & wilds(4) '** Show the colored CONC:
'world.colourtell gfore, backc, "]"
'*** The replacement for it.
world.colourtell "#" & wfore, backc, wilds(2)
wfore = gfore
'*** The rest of this is for coloring the opponents
'*** condition.
for count = 0 to ubound(Types) '** Lets find the hue and luminosity for the mob and get the color.
if instr(wilds(5),Types(count)) then
wfore = HSLtoRGB(Hues(count), Sat, Lums(count))
exit for
end if
next
world.colourtell "#" & wfore, backc, wilds(5)
else
if perc > int(test) then
world.colourtell gfore, backc, output
else
world.colourtell wfore, backc, output
end if
end if
world.colournote nfore, nback, " "
end sub
function GetHBCol()
dim line, test, temp, output
line = world.getlinesinbuffercount
do
temp = world.getlineinfo(line,1) ' Lets find the last line with HP: in it from the buffer to get the correct colors.
test = instr(temp,"HP: [")
line = line - abs(test = 0)
'world.note "Line: " & line
'world.note "Contents: " & temp
loop until test > 0 or line = 0 ' In case the buffer doesn't have one, lets exit before we loop forever.
if line = 0 then
output = "#C0C0C0,#000000" ' We don't have a color, so lets use a gray on black, yuck.
else
temp = world.getstyleinfo(line,1,14) ' We found it, so lets get the colors and store them.
output = world.RGBColourToName(temp)
temp = world.getstyleinfo(line,1,15)
output = "," & world.RGBColourToName(temp)
end if
GetHBCol = output
end function
sub SetHealth (name, output, wilds)
dim gfore,wfore,back,nback
dim a, b, cl, temp
gfore = world.getvariable("goodcol")
wfore = world.getvariable("warncol")
backc = world.getvariable("backcol")
nback = world.RGBColourToName(world.NormalColour(1))
select case wilds(1)
case "%"
select case trim(wilds(2))
case "inc"
world.setvariable "perc","inc"
world.setvariable "HPInc","0"
world.setvariable "CPInc","0"
world.note " "
world.tell "Set to incremental form "
world.colourtell "#3DFF3D", nback, "[] "
world.colourtell "#3DFF3D", nback, "[]"
world.note "."
world.note " "
case "inc2"
world.setvariable "perc","inc"
world.setvariable "HPInc","-1"
world.setvariable "CPInc","-1"
world.note " "
world.tell "Set to incremental form "
world.colourtell "#3D3DFF", nback, "[] "
world.colourtell "#3D3DFF", nback, "[]"
world.note "."
world.note " "
case "inc3"
world.setvariable "perc","inc"
world.setvariable "HPInc","0"
world.setvariable "CPInc","-1"
world.note " "
world.tell "Set to incremental form "
world.colourtell "#3DFF3D", nback, "[] "
world.colourtell "#3D3DFF", nback, "[]"
world.note "."
world.note " "
case "inc4"
world.setvariable "perc","inc"
world.setvariable "HPInc","-1"
world.setvariable "CPInc","0"
world.note " "
world.tell "Set to incremental form "
world.colourtell "#3D3DFF", nback, "[] "
world.colourtell "#3DFF3D", nback, "[]"
world.note "."
world.note " "
case else
if isnumeric(wilds(2)) then
if wilds(2) < 100 and wilds(2) > 0 then
world.setvariable "perc",wilds(2)
world.note " "
world.note "You will now be warned if you HP fall below " & trim(wilds(2)) & "%."
world.note " "
else
world.colournote wfore,backc,"Error: Value must be between 0-100."
end if
else
world.colournote wfore,backc,"Error: Value must be between 0-100 or an 'inc' command."
end if
end select
case "g","good"
color = ValidateColor(wilds(2))
if color = "Error!" then
world.colournote wfore,backc,"Error: Invalid color."
else
world.setvariable "goodcol",color
world.note " "
world.note "Normal color set to " & color & "."
world.note " "
end if
case "w","warn","warning"
color = ValidateColor(wilds(2))
if color = "Error!" then
world.colournote wfore,backc,"Error: Invalid color."
else
world.setvariable "warncol",color
world.note " "
world.note "Warning color set to " & color & "."
world.note " "
end if
case "b","back","background"
color = ValidateColor(wilds(2))
if color = "Error!" then
world.colournote wfore,backc,"Error: Invalid color."
else
world.setvariable "backcol",color
world.note " "
world.note "Background color set to " & color & "."
world.note " "
end if
case "help"
world.note " "
world.note "Commands>"
world.note "hitbar:help - This screen."
world.note "hitbar:% <number> - Sets the percentage below which to show the warning color."
world.note "hitbar:% inc - Incremental color, i.e. HP, CP and mob condition change based"
world.note " on condition. Range is Green through Yellow to Red."
world.note "hitbar:% inc2 - Incremental color, ranges from Blue through Violet to Red."
world.note "hitbar:% inc3 - Incremental color, HP are G>Y>R, while CP are B>V>R."
world.note "hitbar:% inc4 - Incremental color, HP are B>V>R, while CP are G>Y>R."
world.note " "
world.note "g, good .................... hitbar:good <color> - Color used for good health"
world.note " in % format."
world.note "w, warn, warning ........... hitbar:warn <color> - Color used for bad health"
world.note " in % format."
world.note "b, back, background . hitbar:back <color> - Color used a background."
world.note " "
world.note "Colors are in the form of a name (Red, Blue, Yellow) or a number (#FF4425)."
world.note " "
end select
end sub
function HSLtoRGB (Hue, Sat, Lum)
dim rm1, rm2, Temp, Temp2, Red, Green, Blue
Lum = Lum / 255 '** Get these back to a %. Hue is an arc from 0 to 360, so we don't touch it.
Sat = Sat / 255
if Sat = 0 then
Temp = Lum * 255 '** Satuaration of 0 means it is gray, so all colors are a % of the maximum.
Red = Temp
Green = Temp
Blue = Temp
else
if Lum <= 0.5 then '** Haven't a clue about the rest of this, I just know it works. lol
rm2 = Lum + Lum * Sat
else
rm2 = Lum + Sat - Lum * Sat
end if
rm1 = 2 * Lum - rm2
Temp = rm1
Red = FindColor(Temp, rm2, Hue + 120)
Temp = rm1
Green = FindColor(Temp, rm2, Hue)
Temp = rm1
Blue = FindColor(Temp, rm2, Hue - 120)
end if
Red = Cint(Red) '** Stick it all together into a single hex string.
Temp = Hex(Red)
if len(Temp) < 2 then
Temp = "0" + Temp
end if
Temp2 = Temp
Temp = Hex(Green)
if len(Temp) < 2 then
Temp = "0" + Temp
end if
Temp2 = Temp2 + Temp
Temp = Hex(Blue)
if len(Temp) < 2 then
Temp = "0" + Temp
end if
Temp2 = Temp2 + Temp
HSLtoRGB = Temp2
end function
function FindColor (rm1, rm2, rh)
if rh > 360 then
rh = rh - 360
else
if rh < 0 then
rh = rh + 360
end if
end if
if rh < 60 then
rm1 = rm1 + (rm2 - rm1) * rh / 60
else
if rh < 180 then
rm1 = rm2
else
if rh < 240 then
rm1 = rm1 + (rm2 - rm1) * (240 - rh) / 60
end if
end if
end if
FindColor = rm1 * 255
end function
function ValidateColor(color)
if instr(color,"#") then '** The simple case, lets see if it is a straight #.
temp = replace(cl,"#","&h")
if isnumeric(temp) then
output = color '** It was, so return it unchanged.
else
output = "Error!" '** Oops. Somethings wrong, so return an error.
end if
else
a = world.ColourNameToRGB(color) '** It may be a name so lets try to get the #.
if a <> -1 then '** Is it a good color? Bad names return #FFFFFF,
'** so if we didn't want white...
output = color '** Yep, so lets return it unchanged.
else
output = "Error!" '** Oops we don't know this color, return an error.
end if
end if
ValidateColor = output
end function
]]>
</script>
</muclient>
This should do what you want and more. ;)
With respect to the one probably confusing change:
LMax = LMax * abs(LMax >= CHP) + CHP * abs(LMax < CHP)
The above may look strange, but it is basically a way to use math to do:
if LMax < CHP then
LMax = CHP
end if
It is however slightly faster, because it uses math to do it. Not real important, but I picked up the habit of using the trick a while back when programing on Apple II computers, where ironically it also made the program shorter by 3-4 bytes (this was a big deal on 64k systems lol).
For a better explaination consider this:
LMax = 10
CHP = 5
then >
LMax = 10 * abs(10 >= 5) + 5 * abs(10 < 5)
LMax = 10 * 1 + 5 * 0 -> 10
LMax = 5
CHP = 15
then >
LMax = 5 * abc(5 >= 15) + 10 * abs(5 < 15)
LMax = 5 * 0 + 15 * 1 -> 15
Either way you get the higher value. You have to use this trick because VBScript, which the plugin uses, doesn't have a Min() or Max() function. :p |