Problem with triggers

Posted by Fonikz on Fri 20 Mar 2015 12:15 AM — 11 posts, 34,580 views.

#0
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?
Amended on Fri 20 Mar 2015 12:25 AM by Fonikz
Australia Forum Administrator #1
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.
Australia Forum Administrator #2
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.
Amended on Fri 20 Mar 2015 07:33 AM by Nick Gammon
#3
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.
Amended on Fri 20 Mar 2015 08:49 PM by Nick Gammon
Australia Forum Administrator #4
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.
Australia Forum Administrator #5
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
#6
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]
#7
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.
Australia Forum Administrator #8
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.
#9
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
Australia Forum Administrator #10
Template:faq=32
Please read the MUSHclient FAQ - point 32.


You need quotes.