Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Colour triggers?

Colour triggers?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Aduial   (19 posts)  Bio
Date Sat 02 Aug 2003 10:00 PM (UTC)
Message
How should a trigger for highlighting a word look like?
And how do I make my prompt change the color of the hp/ep when they get lower/higher? (for example when they're 230 to have them in blue, 229-150 green, 150-80 yellow, 80-0 red)
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 02 Aug 2003 10:07 PM (UTC)
Message
To highlight a single word is easy, just match on that word, check "regular expression" and set "change colour to" whatever.

To change the prompt colour, you would use a more complex regular expression. If you post exact examples (copy and paste) of the various levels we may be able to help better. (For instance do low ones have leading zeros, like 009 or is it 9?)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Aduial   (19 posts)  Bio
Date Reply #2 on Sun 03 Aug 2003 08:58 AM (UTC)
Message
It's like this as full: HP:230 EP:230
Then it will be: HP:229 EP:230 or HP:230 EP:229 (so the hp must be in blue and the ep in green)
Then HP:144 EP:190 (here hp must be yellow, and ep green)
The 0 is just 0.
Top

Posted by Shadowfyr   USA  (1,790 posts)  Bio
Date Reply #3 on Mon 04 Aug 2003 05:43 AM (UTC)
Message
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
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #4 on Tue 05 Aug 2003 06:18 AM (UTC)
Message
It can be done with regular expressions and no scripting, but they look a bit messy and are fiddly to change. However here is an example:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="HP\:\b((1[01234]\d)|([89]\d))\b"
   name="yellow"
   regexp="y"
   sequence="100"
  >
  </trigger>
  <trigger
   custom_colour="3"
   enabled="y"
   match="HP\:\b((2[012]\d)|(1[56789]\d))\b"
   name="green"
   regexp="y"
   sequence="100"
  >
  </trigger>
  <trigger
   custom_colour="4"
   enabled="y"
   match="HP\:\b((2[3456789]\d)|([3456789]\d{2})|(\d{4,}))\b"
   name="blue"
   regexp="y"
   sequence="100"
  >
  </trigger>
  <trigger
   custom_colour="1"
   enabled="y"
   match="HP\:\b(([01234567]\d)|(\d))\b"
   name="red"
   regexp="y"
   sequence="100"
  >
  </trigger>
</triggers>


The red one, for example, looks for a number looking like this:

1.
2.
3.
4.
5.
6.
7.

(where the dot represents any digit). This therefore matches 10 to 79. It also matches a single digit on its own, thus matching 0 to 9.

The blue one looks for 2 followed by 3,4,5,6,7,8,9 followed by a digit, thus matching on 230, 231, 245, 299 etc. It also looks for any 4 digit number.

Have fun.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Aduial   (19 posts)  Bio
Date Reply #5 on Fri 08 Aug 2003 10:49 AM (UTC)
Message
Ok I did this with the triggers and regular expressions. Now here's how my other question looks like:

=HP:220 EP:230=(colored just fine) Groundskeeper glares stonily into space.
then the next prompt that appears is without color:
=HP:230 EP:230= (without colour) (then a messege appears next to it:) Uruk-hai guard growls fiercely.
and then it colours itself. isn't there way to have it colored yet when it appears itself, and not just when something else appears?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #6 on Sat 09 Aug 2003 01:20 AM (UTC)
Message
This has been discussed quite a few times before. Basically MUSHclient matches on triggers when the newline appears and not before. However you can work around it, see:

http://www.gammon.com.au/forum/?bbsubject_id=1898

The simplest solution is to change the MUD prompt, if you can, to include a newline at the end.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Scypio   Poland  (50 posts)  Bio
Date Reply #7 on Sun 05 Sep 2004 03:03 PM (UTC)
Message
set prompt $HE>\n should be enough
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


26,389 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.