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, 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.
 Entire forum ➜ MUSHclient ➜ Plugins ➜ Status line from prompt, using new partial-line plugin callback

Status line from prompt, using new partial-line plugin callback

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


Pages: 1 2  

Posted by Nick Gammon   Australia  (23,070 posts)  Bio   Forum Administrator
Date Fri 13 Feb 2004 06:06 AM (UTC)

Amended on Fri 13 Feb 2004 06:07 AM (UTC) by Nick Gammon

Message
The small plugin below illustrates using how you can update the status line (or do something else with it if you want) based on incoming text from the MUD *before* receiving a newline.

This has been asked for so often in the past, it is nice to be able to release a working example.

You need MUSHclient version 3.44 which is the first to support the new plugin callback OnPluginPartialLine.

You will probably need to customise the regular expression it matches on (or change your prompt) to get it to work for you, but this is a minor detail.

What it does is inspect incoming text and if it matches the regular expression, immediately update the status line.

You could use a variation of it to warn you (with world.ColourNote for instance) if your HP are running low.




<?xml version="1.0" encoding="US-ASCII"?>

<!DOCTYPE muclient [
  <!ENTITY regexp_match 
   "^\&lt;\-?(\d+)\/(\d+) hp \-?(\d+)\/(\d+) m \-?(\d+)\/(\d+) mv\&gt;(.*?)$" 
  > 
]>

<!-- Saved on Friday, February 13, 2004, 4:48 PM -->
<!-- MuClient version 3.44 -->

<!--
You will probably need to customise the regular expression to match your MUD.

See ENTITY line near top of file. The above regular expression will match on:

  <54/1000 hp 90/100 m 600/750 mv>

A simpler regular expression would be:

  &lt;*/*hp */*m */*mv&gt;

-->

<!-- Plugin "Status_Bar_Prompt" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Status_Bar_Prompt"
   author="Nick Gammon"
   id="ff9331b06c15ab21046be001"
   language="VBscript"
   purpose="Updates the status bar from the prompt"
   date_written="2004-02-13 16:41:24"
   requires="3.44"
   version="1.0"
   >

</plugin>


<!--  Script  -->


<script>
<![CDATA[
sub OnPluginPartialLine (sText)
Dim regEx, Matches, Match

'
' 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 = "&regexp_match;"

<![CDATA[

'
'  Execute regular expression
'

  Set Matches = regEx.Execute (sText)

'
'  Exit if no match
'
 
  if Matches.Count = 0 then  
    Set regEx = Nothing
    Set Matches = Nothing
	exit sub
  end if

  Set Match = Matches.Item (0)

  Set regEx = Nothing
  Set Matches = Nothing

'
'  Update the status line
'

  SetStatus "Hp = " & Match.SubMatches (0) & _
            "/" & Match.SubMatches (1) & _
            ", Mana = " & Match.SubMatches (2) & _
            "/" & Match.SubMatches (3) & _
            ", Move = " & Match.SubMatches (4) & _
            "/" & Match.SubMatches (5)

  Set Match = Nothing

end sub
]]>
</script>

</muclient>


- Nick Gammon

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

Posted by Irzadi   (7 posts)  Bio
Date Reply #1 on Fri 13 Feb 2004 04:55 PM (UTC)
Message
Great work, Nick.
Bye the way, is there any way to call a subroutine defined in my script file from a plugin ? So basically, I dont want to just display the value that I get from prompt in my statusbar. I also want to do things with them, so I've made a subroutine that is called by trigger whenever I get the prompt. But it seems I cant call it from the plugin.

PS I almost never use plugins so please bear with me.
Top

Posted by Nick Gammon   Australia  (23,070 posts)  Bio   Forum Administrator
Date Reply #2 on Sat 14 Feb 2004 12:07 AM (UTC)
Message
Well, this plugin basically *is* a subroutine. Just edit the plugin and make it do what you want.

You can call subroutines from triggers in plugins, but they all have to be in the same plugin. The idea is that a plugin is self-contained. Having the main world call a plugin, or vice-versa, goes against the modular concept of plugins.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,070 posts)  Bio   Forum Administrator
Date Reply #3 on Sat 14 Feb 2004 03:04 AM (UTC)
Message
Below is a variant of it that updates the info bar (using coloured bars) rather than writing to the status line:


<?xml version="1.0" encoding="US-ASCII"?>

<!DOCTYPE muclient [
  <!ENTITY regexp_match 
   "^\&lt;\-?(\d+)\/(\d+) hp \-?(\d+)\/(\d+) m \-?(\d+)\/(\d+) mv\&gt;(.*?)$" 
  > 
]>

<!-- Saved on Friday, February 13, 2004, 4:48 PM -->
<!-- MuClient version 3.44 -->

<!--
You will probably need to customise the regular expression to match your MUD.

See ENTITY line near top of file. The above regular expression will match on:

  <54/1000 hp 90/100 m 600/750 mv>

A simpler trigger would be:

  &lt;*/*hp */*m */*mv&gt;

-->

<!-- Plugin "Status_Bar_Prompt" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Status_Bar_Prompt"
   author="Nick Gammon"
   id="ff9331b06c15ab21046be001"
   language="VBscript"
   purpose="Updates the status bar from the prompt"
   date_written="2004-02-13 16:41:24"
   requires="3.44"
   version="1.0"
   >

</plugin>


<!--  Script  -->


<script>
<![CDATA[
sub DoGauge (sPrompt, iCurrent, iMax, sGoodColour, sBadColour)
dim pc, count

'
'  Do prompt in black Arial
'
  InfoColour "black"
  InfoFont "Arial", 10, 0
  Info sPrompt

'
'  Use Webdings for gauge (black square)
'

  InfoFont "Webdings", 10, 0

  pc = CInt ((CInt (iCurrent) / CInt (iMax)) * 10)

'
'  Below 20% warn by using different colour
'

  if pc < 2 then
    InfoColour sBadColour
  else
    InfoColour sGoodColour
  end if

'
'  Draw active part of gauge
'
  for count = 0 to pc
    Info "g"
  next  

'
'  Draw rest of gauge in grey (ie. unfilled bit)
'

  InfoColour "dimgray"
  while count <= 10
    count = count + 1
    Info "g"
  wend

end sub

sub OnPluginPartialLine (sText)
Dim regEx, Matches, Match

'
' 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 = "&regexp_match;"

<![CDATA[

'
'  Execute regular expression
'

  Set Matches = regEx.Execute (sText)

'
'  Exit if no match
'
 
  if Matches.Count = 0 then  
    Set regEx = Nothing
    Set Matches = Nothing
	exit sub
  end if

  Set Match = Matches.Item (0)

  Set regEx = Nothing
  Set Matches = Nothing

  InfoClear

'
'  World name
'

  InfoFont "Arial", 12, 1  ' 12 point Arial *bold*
  InfoColour "purple"
  Info GetInfo (2)  ' world name

  DoGauge "  HP: ", Match.SubMatches (0), Match.SubMatches (1), "darkgreen", "maroon"
  DoGauge "  Mana: ", Match.SubMatches (2), Match.SubMatches (3), "mediumblue", "mediumblue"
  DoGauge "  Move: ", Match.SubMatches (4), Match.SubMatches (5), "gold", "gold"

  Set Match = Nothing

end sub

'
'  Do this once
'
ShowInfoBar vbTrue


]]>
</script>

</muclient>

- Nick Gammon

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

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #4 on Sat 14 Feb 2004 07:57 AM (UTC)
Message
Couldnt you use CallPlugin? (to call something from your world via plugin?)
you can do it between plugins, and I know its been mentioned about using the main world, I just dont remember what you use as a pluginID. Maybe Im just imagining things, but I thought this was doable.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Nick Gammon   Australia  (23,070 posts)  Bio   Forum Administrator
Date Reply #5 on Sat 14 Feb 2004 07:47 PM (UTC)
Message
Yes, you could use CallPlugin, but why bother?

You would need to write a second plugin, then the first plugin needs to be modified anyway, to call the second plugin. Then you need to make sure that both plugins are loaded, and in the right order. Then you need to check in the first plugin that the second plugin is in fact there.

Seems simpler to me to just modify the plugin. My second plugin above shows that idea. It calls another subroutine inside the same plugin.

- Nick Gammon

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

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #6 on Sat 14 Feb 2004 09:25 PM (UTC)
Message
Eh, I think you missed my point.
Isnt there something you can make the 'pluginId' field in CallPlugin to call from the main world?

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Nick Gammon   Australia  (23,070 posts)  Bio   Forum Administrator
Date Reply #7 on Sat 14 Feb 2004 10:15 PM (UTC)
Message
No, CallPlugin calls other plugins.

Each plugin executes in its own script space, the main world script space is not available to plugins.

CallPlugin was implemented to let plugin writers write a "utility" plugin that does things that might want to be shared between plugins.


Quote:

So basically, I dont want to just display the value that I get from prompt in my statusbar. I also want to do things with them, so I've made a subroutine that is called by trigger whenever I get the prompt. But it seems I cant call it from the plugin.


My response to that requirement is to simply move the script subroutine into either the plugin I demonstrated below, or, if you want to keep them separate, into another plugin and then use CallPlugin to call it in the other plugin.


- Nick Gammon

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

Posted by Johnathan Allen   (49 posts)  Bio
Date Reply #8 on Sat 21 Feb 2004 07:48 AM (UTC)

Amended on Sat 21 Feb 2004 07:49 AM (UTC) by Johnathan Allen

Message
Using OnPluginPartialLine in an application similar to the second plugin you posted, I get a 'bounce', or a lag in line display. If I uninstall the plugin I'm using, the text I recieve flows smoothly on the screen. If I reinstall it, there seems to be lag generated by the call. I'm using a 900mhz pentium with 512 mb of ram, on win2k pro, with nothing but MUSHclient running (I've got less than 90mb of mem usage) on a 1.5mb cable connection. I'm wondering if anyone else is getting this.
Top

Posted by Nick Gammon   Australia  (23,070 posts)  Bio   Forum Administrator
Date Reply #9 on Sat 21 Feb 2004 08:26 AM (UTC)
Message
I hadn't noticed it when I tested, but potentially anything that does extra work for every line received could slow things down.

When you say "similar" is the regular expression more complex?

Try removing parts, like, keep the plugin but make it exit before doing the regular expression.

One problem is that the regular expression is a COM object that is instantiated in every call, that might be slow. If that is the part that is slow, you could put the line:

Set regEx = New RegExp

into global scope (with other relevant changes) so the regular expression object always exists.

- Nick Gammon

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

Posted by Johnathan Allen   (49 posts)  Bio
Date Reply #10 on Sat 21 Feb 2004 08:37 AM (UTC)
Message
Actually, the regex is simpler:

  <!ENTITY regexp_match 
   "^(.*?)\<(.*?)hp (.*?)sp (.*?)st\>(.*?)" 
  >


I have that line you suggested already:

<!--  Script  -->

<script>
<![CDATA[

sub OnPluginPartialLine (sText)
Dim regEx, Matches, Match

'
' 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 = "&regexp_match;"

<![CDATA[

'
'  Execute regular expression
'

  Set Matches = regEx.Execute (sText)
Top

Posted by Nick Gammon   Australia  (23,070 posts)  Bio   Forum Administrator
Date Reply #11 on Sat 21 Feb 2004 11:05 AM (UTC)
Message
I meant to move it outside the sub, and to remove the line that sets it to nothing.

- Nick Gammon

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

Posted by Johnathan Allen   (49 posts)  Bio
Date Reply #12 on Sun 22 Feb 2004 06:22 AM (UTC)
Message
Like this?


<![CDATA[
sub OnPluginPartialLine (sText)
Dim regEx, Matches, Match
]]>

  Set regEx = New RegExp

  regEx.Pattern = "&regexp_match;"

<![CDATA[

'
'  Execute regular expression
'

  Set Matches = regEx.Execute (sText)
'
'  Exit if no match
'
 
  if Matches.Count = 0 then  
    Set regEx = Nothing
    Set Matches = Nothing
	exit sub
  end if

  Set Match = Matches.Item (0)

  InfoClear

DoPrompt

End Sub
Top

Posted by Nick Gammon   Australia  (23,070 posts)  Bio   Forum Administrator
Date Reply #13 on Sun 22 Feb 2004 06:55 AM (UTC)
Message
I meant this... Change this:




sub OnPluginPartialLine (sText)
Dim regEx, Matches, Match

'
' Make a regular expression to match on the line:
'
'  
  Set regEx = New RegExp

...



to



Dim regEx

'
' Make a regular expression to match on the line:
'
'  
  Set regEx = New RegExp

sub OnPluginPartialLine (sText)
Dim  Matches, Match



The line "set regex = New RegExp" is the one I mentioned to "move outside the sub". That is, put that line outside the "sub ... end sub" sequence.

Also, delete the line "set regex = nothing"


- Nick Gammon

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

Posted by Johnathan Allen   (49 posts)  Bio
Date Reply #14 on Sun 22 Feb 2004 07:21 AM (UTC)
Message
Thank you.
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.


64,723 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

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.