Posted by
| Nick Gammon
Australia (23,046 posts) Bio
Forum Administrator |
Message
| I have been mucking around trying to do a "super" health bar - one that uses an external program to display a fancier health bar. It is sort-of working, so I will present it here in the hope someone can make it work perfectly.
The general idea - which works on my development PC (Windows NT 4) - is to write a small VB program (not VBscript) which is invoked from MUSHclient and which draws a nice health bar with multiple lines. See the screen shot in the next post for the general idea.
However I am finding that when attempting to run it on other PCs I get strange behaviour, like missing VB DLLs, and other things. However you may be able to make it work, especially if you have VB installed.
First, the plugin which calls the health bar program - this is similar to the earlier health bar plugin, however it has the enhancement of the 1-second timer that will do a match on the last line, even if there is no newline, so it should work even if the prompt does not have a newline on it.
Super_Health_Bar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient [
<!ENTITY trigger_match
"^\<\-?(\d+)\/(\d+) hp \-?(\d+)\/(\d+) m \-?(\d+)\/(\d+) mv\>(.*?)$"
>
]>
<!-- 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:
<*/*hp */*m */*mv>
-->
<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>
Next, the VB project.
There is a reference in it to the MUSHclient.tlb file (which comes with MUSHclient). You will probably need to change that to be where you actually have that file.
MUSHclient_bar.vbp
Type=OleExe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINNT\System32\StdOle2.Tlb#OLE Automation
Reference=*\G{00025E01-0000-0000-C000-000000000046}#5.0#0#C:\Program Files\Common Files\Microsoft Shared\DAO\DAO360.DLL#Microsoft DAO 3.6 Object Library
Reference=*\G{11DFC5E7-AD6F-11D0-8EAE-00A0247B3BFD}#1.0#0#C:\Program Files\MUSHclient\scripts\MUSHclient.tlb#MUSHclient
Object={6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0; COMCTL32.OCX
Class=Bar; Bar.cls
Form=Gauge.frm
Module=Globals; Globals.bas
Startup="(None)"
ExeName32="MUSHclient_bar.exe"
Command32=""
Name="MUSHclient_bar"
HelpContextID="0"
CompatibleMode="0"
CompatibleEXE32="MUSHclient_bar.exe"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="Gammon Software Solutions"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=1
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
Next, the "bar" class that is called from MUSHclient.
Bar.cls
VERSION 1.0 CLASS
BEGIN
MultiUse = 0 'False
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "Bar"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Sub SetHP(value As Integer)
If value < 0 Then value = 0
Gauge.HPbar.value = value
End Sub
Sub SetMaxHP(value As Integer)
Gauge.HPbar.Max = value
End Sub
Sub SetMove(value As Integer)
If value < 0 Then value = 0
Gauge.Movebar.value = value
End Sub
Sub SetMaxMove(value As Integer)
Gauge.Movebar.Max = value
End Sub
Sub SetMana(value As Integer)
If value < 0 Then value = 0
Gauge.Manabar.value = value
End Sub
Sub SetMaxMana(value As Integer)
Gauge.Manabar.Max = value
End Sub
Sub SetPosition(X As Integer, Y As Integer)
Gauge.Left = X
Gauge.Top = Y
End Sub
Sub SetWidth(width As Integer)
Gauge.width = width
End Sub
'
' remember calling world in case they close the bar window
'
Sub SetTitle(callingworld As Object, title As String)
Gauge.Caption = title
Set theworld = callingworld
End Sub
Function GetX()
GetX = Gauge.Left
End Function
Function GetY()
GetY = Gauge.Top
End Function
Function GetWidth()
GetWidth = Gauge.width
End Function
Private Sub Class_Initialize()
Gauge.Show
End Sub
Private Sub Class_Terminate()
End
End Sub
Next, the form that you actually see with 3 progress bars on it...
Gauge.frm
VERSION 5.00
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX"
Begin VB.Form Gauge
Caption = "Health Bar"
ClientHeight = 870
ClientLeft = 60
ClientTop = 345
ClientWidth = 9090
LinkTopic = "Form1"
ScaleHeight = 870
ScaleWidth = 9090
StartUpPosition = 3 'Windows Default
Begin ComctlLib.ProgressBar HPbar
Height = 255
Left = 720
TabIndex = 0
Top = 0
Width = 8295
_ExtentX = 14631
_ExtentY = 450
_Version = 327682
Appearance = 1
End
Begin ComctlLib.ProgressBar Movebar
Height = 255
Left = 720
TabIndex = 2
Top = 600
Width = 8295
_ExtentX = 14631
_ExtentY = 450
_Version = 327682
Appearance = 1
End
Begin ComctlLib.ProgressBar Manabar
Height = 255
Left = 720
TabIndex = 1
Top = 300
Width = 8295
_ExtentX = 14631
_ExtentY = 450
_Version = 327682
Appearance = 1
End
Begin VB.Label movement
Alignment = 1 'Right Justify
Caption = "Move"
Height = 255
Left = 0
TabIndex = 5
Top = 600
Width = 615
End
Begin VB.Label mana
Alignment = 1 'Right Justify
Caption = "Mana"
Height = 255
Left = 0
TabIndex = 4
Top = 300
Width = 615
End
Begin VB.Label HP
Alignment = 1 'Right Justify
Caption = "HP"
Height = 255
Left = 0
TabIndex = 3
Top = 0
Width = 615
End
End
Attribute VB_Name = "Gauge"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Form_Resize()
HPbar.width = width - 900
Manabar.width = width - 900
Movebar.width = width - 900
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not IsEmpty(theworld) Then
If Not theworld Is Nothing Then
theworld.ColourNote "white", "red", "Health Bar has been closed"
theworld.CallPlugin "4637b3ca32d84f4b5ea6743b", "barclosed", ""
End If
End If
End Sub
Finally a file with a single global variable in it.
Globals.bas
Attribute VB_Name = "Globals"
Public theworld As world
Save these 4 files to disk under the indicated names, and open the MUSHclient_bar.vbp file in Visual Basic, and then compile.
All of the above files - the plugin, the 4 files, and the compiled executable - are in the file:
http://www.gammon.com.au/mushclient/HealthBar.zip
What you could try to do is:
- Get the above zip file
- Put the plugin (Super_Health_Bar.xml) in your plugins directory
- Execute the program (MUSHclient_bar.exe) - this will hopefully "register" it with Windows
- Install the plugin into MUSHclient
- Connect to your world - with luck, the health bar will appear
Features
The health bar displays 3 progress bars - health, mana, movement.
You can resize it and the progress bars will resize accordingly. The plugin will remember the width for next time.
You can move it and the location on the screen will be remembered by the plugin for next time.
You can use a trigger to individually set the HP, Max HP, movement, max movement, mana and max mana.
eg.
SetHP 22
SetMaxHP 100
SetMove 40
SetMaxMove 88
SetMana 1000
SetMaxMana 2000
You can move it and set its width:
SetPosition 500, 8080
SetWidth 1000
You can set the window title and tell it which world is calling it:
SetTitle world, "SMAUG"
You can get the X and Y coordinates, and with:
X = GetX
Y = GetY
width = GetWidth
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|