<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient [
  <!ENTITY trigger_match 
   "^\&lt;\-?(\d+)\/(\d+) hp \-?(\d+)\/(\d+) m \-?(\d+)\/(\d+) mv\&gt;(.*?)$" 
  > 
]>
<!-- Saved on Saturday, August 16, 2003, 7:11 AM -->
<!-- MuClient version 3.42 -->

<!-- Plugin "Super_Health_Bar" generated by Plugin Wizard -->
<!--
You will probably need to customise the trigger to match your MUD.

See ENTITY line near top of file. The above trigger will match on:

  <54/1000 hp 90/100 m 600/750 mv>

A simpler trigger would be:

  &lt;*/*hp */*m */*mv&gt;

-->

<muclient>
<plugin
   name="Super_Health_Bar"
   author="Nick Gammon"
   id="4637b3ca32d84f4b5ea6743b"
   language="VBscript"
   purpose="Health, Mana, Movement bar implemented with external VB program"
   date_written="2003-08-16 07:08:12"
   requires="3.42"
   version="1.0"
   save_state="y" 
   >
<description trim="y">
<![CDATA[
Uses a small Visual Basic program to display your current health, 
mana and movement points in a separate window.

You need your prompt line to display the appropriate information,
naturally. I used this in SMAUG:

prompt <%h/%H hp %m/%M m %v/%V mv>
fprompt <%h/%H hp %m/%M m %v/%V mv>

"prompt" sets the normal prompt, "fprompt" sets the fight prompt.

Customise the plugin if you want to match a different sort of prompt line.

]]>
</description>

</plugin>


<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   match="&trigger_match;"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

On Error Resume Next

if not isempty (barobject) then
  if not (barobject is nothing) then
    barobject.SetMaxHP %2
    barobject.SetHP %1
    barobject.SetMaxMana %4
    barobject.SetMana %3
    barobject.SetMaxMove %6
    barobject.SetMove %5
  end if
end if

</send>
  </trigger>
</triggers>

<!--  Timers -->

<timers>
  <timer 
    script="CheckPrompt" 
    enabled="y" 
    second="1" 
  >
  </timer>
</timers>


<!--  Script  -->


<script>
<![CDATA[
'
' global variable which is the HP bar Visual Basic COM object
'
dim barobject

barobject = empty

'
'  Central spot for showing errors, so we can easily customise colours
'
sub ShowError (sMessage)
  world.ColourNote "white", "red", sMessage 
end sub


'
' This world has been connected (to the MUD)
'
sub OnPluginConnect
dim X, Y, width

if isempty (barobject) then
  set barobject = nothing
end if

if barobject is nothing then
  On Error Resume Next

  set barobject = createobject ("MUSHclient_bar.Bar")

  If Err.Number <> 0 Then
    ShowError Err.Description
    ShowError "Cannot execute bar display program"
    ShowError "Check it is installed."
    Exit Sub
  End If

  On Error GoTo 0

'
'  reposition it (from value saved last time)
'

  X = GetVariable ("X")
  Y = GetVariable ("Y")
  width = GetVariable ("width")

  if not IsEmpty (X) and not IsEmpty (Y) then
    barobject.SetPosition CInt (X), CInt (Y)
  else
    Note "First time used - using default screen position"
  end if

  if not IsEmpty (width) then
    barobject.SetWidth CInt (width)
  end if

  barobject.SetTitle world, world.WorldName
end if

end sub

'
' This world has been disconnected (from the MUD)
'
sub OnPluginDisconnect

On Error Resume Next

'
'  release bar window - remember position
'

if not isempty (barobject) then
  if not barobject is nothing then
    SetVariable "X", barobject.GetX
    SetVariable "Y", barobject.GetY
    SetVariable "width", barobject.GetWidth
    set barobject = nothing
  end if 
end if 

end sub

sub CheckPrompt (sName)
Dim regEx, Matches, Match, sLine, iNumber

'
'  Find line number of last line in buffer
'
  iNumber = world.GetLinesInBufferCount

' ignore lines with a newline at the end

  if world.GetLineInfo (iNumber, 3) then exit sub

' ignore world.note lines

  if world.GetLineInfo (iNumber, 4) then exit sub

' ignore player input lines

  if world.GetLineInfo (iNumber, 5) then exit sub

'
' So far we have a line that is MUD output (not note or command)
'  and it doesn't have a newline, so it is probably a prompt
'

' get text of line

  sLine = world.GetLineInfo (iNumber, 1)

'
' Make a regular expression to match on the line:
'
'  
  Set regEx = New RegExp

'
'  exit CDATA block so we can use the trigger entity
'
]]>

  regEx.Pattern = "&trigger_match;"

<![CDATA[

'
'  Execute regular expression
'

  Set Matches = regEx.Execute (sLine)

'
'  Exit if no match
'
 
  if Matches.Count = 0 then  exit sub


  Set Match = Matches.Item (0)

  Set regEx = Nothing
  Set Matches = Nothing

'
'  Update the bar
'

  On Error Resume Next

  if not isempty (barobject) then
    if not (barobject is nothing) then
      barobject.SetMaxHP CInt (Match.SubMatches (1))
      barobject.SetHP CInt (Match.SubMatches (0))
      barobject.SetMaxMana CInt (Match.SubMatches (3))
      barobject.SetMana CInt (Match.SubMatches (2))
      barobject.SetMaxMove CInt (Match.SubMatches (5))
      barobject.SetMove CInt (Match.SubMatches (4))
    end if
  end if

  Set Match = Nothing

end sub

'
'  Called if the user closes the bar window
'

sub barclosed (arg)
 OnPluginDisconnect
end sub

]]>


</script>


</muclient>
