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 ➜ Problem with triggers

Problem with triggers

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


Posted by Fonikz   (5 posts)  Bio
Date Fri 20 Mar 2015 12:15 AM (UTC)

Amended on Fri 20 Mar 2015 12:25 AM (UTC) by Fonikz

Message
I'm playing Age of Chaos, and the prompt/display command does not offer your max hp/mana/move so I'm having to pull that from the score command. I'm trying to put together an HP bar eventually.

The line I'm trying to trigger is
You have 66(66)[+136] hit, 92(92)[+98] mana and 97(97)[+141] movement points.


And for some reason I can't get anything to trigger correctly.

Here are the triggers I'm trying, and so far I'm just focusing on the first '66' because that's where I'm getting hung. This works:

^You have ..\((\d+)\)\[\+\d+\] hit, ..\((\d+)\)\[\+\d+\] mana and ..\((\d+)\)\[\+\d+\] movement points\.


And this works:
^You have .+\((\d+)\)\[\+\d+\] hit, ..\((\d+)\)\[\+\d+\] mana and ..\((\d+)\)\[\+\d+\] movement points\.


But this does not work:

^You have 66\((\d+)\)\[\+\d+\] hit, ..\((\d+)\)\[\+\d+\] mana and ..\((\d+)\)\[\+\d+\] movement points\.


And this does not work:

^You have \d+\((\d+)\)\[\+\d+\] hit, ..\((\d+)\)\[\+\d+\] mana and ..\((\d+)\)\[\+\d+\] movement points\.


As well as this does not work:

^You have \d\d\((\d+)\)\[\+\d+\] hit, ..\((\d+)\)\[\+\d+\] mana and ..\((\d+)\)\[\+\d+\] movement points\.


What on earth am I doing wrong here?
Top

Posted by Nick Gammon   Australia  (23,171 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 20 Mar 2015 07:31 AM (UTC)
Message
Quote:

But this does not work:


^You have 66\((\d+)\)\[\+\d+\] hit, ..\((\d+)\)\[\+\d+\] mana and ..\((\d+)\)\[\+\d+\] movement points\.



I tested that and it worked for me.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,171 posts)  Bio   Forum Administrator
Date Reply #2 on Fri 20 Mar 2015 07:32 AM (UTC)

Amended on Fri 20 Mar 2015 07:33 AM (UTC) by Nick Gammon

Message
Be cautious with your testing, there is a leading space here:


 You have 66(66)[+136] hit, 92(92)[+98] mana and 97(97)[+141] movement points.


It worked for me if I omitted the leading space.

- Nick Gammon

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

Posted by Fonikz   (5 posts)  Bio
Date Reply #3 on Fri 20 Mar 2015 02:05 PM (UTC)

Amended on Fri 20 Mar 2015 08:49 PM (UTC) by Nick Gammon

Message
Well now my stats have changed, but I'm still not getting it to trigger correctly.

You have 281(281)[+98] hit, 197(197)[+46] mana and 97(97)[+110] movement points.

This is my new line, and this works:

^You have (\d+)\((\d+)\)\[\+\d+\] hit, (\d+)\((\d+)\)\[\+\d+\] mana and (\d+)\((\d+)\)\[\+\d+\] movement points\.


But this does not work:
^You have \d+\((\d+)\)\[\+\d+\] hit, \d+\((\d+)\)\[\+\d+\] mana and \d+\((\d+)\)\[\+\d+\] movement points\.


I don't necessarily want my current health to be wildcards, I just need to grab my max values from that line. My current values will come from my regular prompt line.


[EDIT] Escaped forum codes, then reverted because that seemed to make it worse.
Top

Posted by Nick Gammon   Australia  (23,171 posts)  Bio   Forum Administrator
Date Reply #4 on Fri 20 Mar 2015 08:48 PM (UTC)
Message
Can you post the actual trigger please?

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.


I'm confused about whether or not you are "escaping" forum codes, which affects the number of backslashes we see.

MUSHclient has a menu item to do that for you.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,171 posts)  Bio   Forum Administrator
Date Reply #5 on Fri 20 Mar 2015 09:20 PM (UTC)
Message
Here is my version. I copied your prompt, changed the numbers to asterisks, hit the "convert to regular expression" button and fixed up the wildcards a bit:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="^You have (\d+)\((\d+)\)\[([+-]\d+)\] hit\, (\d+)\((\d+)\)\[([+-]\d+)\] mana and (\d+)\((\d+)\)\[([+-]\d+)\] movement points\.$"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>
%%1 = %1
%%2 = %2
%%3 = %3
%%4 = %4
%%5 = %5
%%6 = %6
%%6 = %7
%%7 = %8
%%8 = %9

</send>
  </trigger>
</triggers>


Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


Test results:


You have 281(281)[+98] hit, 197(197)[+46] mana and 97(97)[+110] movement points.
%1 = 281
%2 = 281
%3 = +98
%4 = 197
%5 = 197
%6 = +46
%6 = 97
%7 = 97
%8 = +110

- Nick Gammon

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

Posted by Fonikz   (5 posts)  Bio
Date Reply #6 on Fri 20 Mar 2015 10:45 PM (UTC)
Message
Okay, now that's working for me. I was trying to simplify it by only grabbing the max values (%2, %5, and %8 from your example) but I can collect all 9 as wildcards and pull what I need just as easily.

Now I'm on to my next adventure, and that is modifying your health_bar script to utilize these max values and store them as variables for the DoGauge to use. Here's what I've got so far, but it's still not working just yet.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient [
 <!ENTITY trigger_match 
 "^\&lt;(\d+)H (\d+)M (\d+)V \d+X \d+:\d+:\d+ \d+S\&gt;" > 
]>

<!-- Saved on Monday, April 28, 2003, 9:53 AM -->
<!-- MuClient version 3.41 -->

<!-- Plugin "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:

 <66H 92M 97V 7893X 15:51:31 100S>

AoC does not have max points in the prompt, we have to pull them from "score" command:

 You have 66(66)[+136] hit, 92(92)[+98] mana and 97(97)[+141] movement points.

-->

<muclient>
<plugin
 name="Health_Bar"
 author="Nick Gammon"
 id="a2af5216d68563401888e01e"
 language="VBscript"
 purpose="Shows HP, Mana, Movement points in a colour bar"
 date_written="2003-04-28 09:50:05"
 date_modified="2003-04-28 12:40:05"
 requires="3.29"
 version="1.1"
 >
<description trim="y">
<![CDATA[
Install this plugin to show an info bar with HP, Mana, 
and Movement points shown as a bar (between 0 and 10 blocks).

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.

To see this message, type: Health_Bar:help

]]>
</description>

</plugin>


<!-- Triggers -->

<triggers>
 <trigger
 enabled="y"
 match="&trigger_match;"
 name="InfoBar"
 regexp="y"
 script="DoPrompt"
 sequence="100"
 >
 </trigger>

 <trigger
 enabled="y"
 match="^You have (\d+)\((\d+)\)\[([+-]\d+)\] hit\, (\d+)\((\d+)\)\[([+-]\d+)\] mana and (\d+)\((\d+)\)\[([+-]\d+)\] movement points\.$"
 name="MaxValues"
 regexp="y"
 script="SetMaxValues"
 sequence="100"
 >
 </trigger>
</triggers>

<!-- 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

 if iMax > 0 then
 pc = CInt ((CInt (iCurrent) / CInt (iMax)) * 10)
 end if
'
' 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 DoPrompt (sName, sLine, wildcards)

 InfoClear

'
' World name
'

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

 DoGauge " HP: ", wildcards (1), maxhp, "darkgreen", "maroon"
 DoGauge " Mana: ", wildcards (2), maxmana, "mediumblue", "mediumblue"
 DoGauge " Move: ", wildcards (3), maxmove, "gold", "gold"

end sub

sub SetMaxValues (sName, sLine, wildcards)

 maxhp = wildcards (2)
 maxmana = wildcards (5)
 maxmove = wildcards (8)

 send "tell self Max values set wildcards (2) wildcards (5) wildcards (8)"

end sub

'
' Do this once
'
ShowInfoBar vbTrue


]]>
</script>


<!-- Plugin help -->

<aliases>
 <alias
 script="OnHelp"
 match="Health_Bar:help"
 enabled="y"
 >
 </alias>
</aliases>

<script>
<![CDATA[
Sub OnHelp (sName, sLine, wildcards)
 world.Note world.GetPluginInfo (world.GetPluginID, 3)
End Sub
]]>
</script> 

</muclient>
[\code]
Top

Posted by Fonikz   (5 posts)  Bio
Date Reply #7 on Fri 20 Mar 2015 11:10 PM (UTC)
Message
Update: I did it! I didn't realize that with vbscript, the scope of variables was limited to the routine they were called in. I moved my variable declarations outside the two subs and now it's all working! It's been a long time since I've done any scripting, and back then it was all C++ and Java. Thanks for all your help.
Top

Posted by Nick Gammon   Australia  (23,171 posts)  Bio   Forum Administrator
Date Reply #8 on Sat 21 Mar 2015 12:52 AM (UTC)
Message
I advise against VBscript, honestly.

You can convert to Lua easily enough, and then you have a much more powerful and easy to use language at your disposal. Most of the examples we post these days are in Lua.

- Nick Gammon

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

Posted by Fonikz   (5 posts)  Bio
Date Reply #9 on Mon 30 Mar 2015 05:42 PM (UTC)
Message
Now I'm having a different issue and this one seems like it should be extremely straightforward.


Here's what I'm trying to match:

It is 3 o'clock am, on the Day of Valor.


Here's my trigger:

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="Time"
   match="^It is (.*?) o\'clock (.*?)\, on (.*?)\.$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable ("time", %1)
SetVariable ("ampm", %2)</send>
  </trigger>
</triggers>


And here's my error:

Error number: 0
Event:        Run-time error
Description:  [string "Trigger: "]:2: bad argument #2 to 'SetVariable' (string expected, got nil)

stack traceback:

	[C]: in function 'SetVariable'

	[string "Trigger: "]:2: in main chunk
Called by:    Immediate execution
Top

Posted by Nick Gammon   Australia  (23,171 posts)  Bio   Forum Administrator
Date Reply #10 on Mon 30 Mar 2015 08:57 PM (UTC)
Message
Template:faq=32 Please read the MUSHclient FAQ - point 32.


You need quotes.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


31,751 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.