Every now and again someone wants to make a trigger that matches on the prompt line, which MUSHclient doesn't do directly, because its trigger matching is deferred until a newline is received.
This can be annoying if you want to make triggers to answer the initial questions in a MUD (eg. "What race do you want ..."), or to have a prompt line immediately update a hit point status line.
There is a way, using the fairly recent GetLineInfo script function. Basically the method is to use a timer, the timer calls a script, the script gets the very last line in the output buffer, checks to see if it has a newline, and if not, runs a regular expression on it to see if it matches whatever you are trying to match on.
Depending on how quickly you want the information to be processed you might make a 1-second timer (of course, this would have a bit of overhead), or maybe a 5 or 10-second timer would do.
An example of doing this is below, it updates the status line based on a Dawn Of Time prompt line. To use it, just make a simple timer that calls "CheckPrompt" script every few seconds.
This can be annoying if you want to make triggers to answer the initial questions in a MUD (eg. "What race do you want ..."), or to have a prompt line immediately update a hit point status line.
There is a way, using the fairly recent GetLineInfo script function. Basically the method is to use a timer, the timer calls a script, the script gets the very last line in the output buffer, checks to see if it has a newline, and if not, runs a regular expression on it to see if it matches whatever you are trying to match on.
Depending on how quickly you want the information to be processed you might make a 1-second timer (of course, this would have a bit of overhead), or maybe a 5 or 10-second timer would do.
An example of doing this is below, it updates the status line based on a Dawn Of Time prompt line. To use it, just make a simple timer that calls "CheckPrompt" script every few seconds.
sub CheckPrompt (sName)
Dim regEx, Matches, Match, sLine, iNumber
Dim hp, m, xp, mv
'
' 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 a line like this:
'
' [EW 10:10pm 5/5hp 100/100m 94mv 996xp>
'
Set regEx = New RegExp
regEx.Pattern = "(\d+)/\d+hp (\d+)/\d+m (\d+)mv (\d+)xp"
'
' 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
'
' Pull out the sub-matches (individual numbers)
'
hp = CInt (Match.SubMatches (0))
m = CInt (Match.SubMatches (1))
mv = CInt (Match.SubMatches (2))
xp = CInt (Match.SubMatches (3))
Set Match = Nothing
'
' Update the status line
'
world.SetStatus "hp = " & hp & " m = " & m & _
" mv = " & mv & " xp = " & xp
end sub