Multi-Line Auto Roller

Posted by Nobble The Coding Newbie on Wed 07 Jul 2004 03:47 AM — 19 posts, 72,193 views.

#0
MUSHclient Version: 3.5
MUD: brokenseals.net

Syntax:

Strength : 14
Intelligence : 21
Wisdom : 11
Dexterity : 12
Constitution : 12

Do you wish keep these stats (y/n)?

I'm trying to figure out how to create an autoroller for a mud called brokenseals. I've been messing with some code from previous posts, but I haven't figured out how to do it yet! Argh! Thanks for any help anyone can give.

PS: [I've been working with triggers, but would a script be better? I'm a noob though so please don't flame me =)
Australia Forum Administrator #1
Nowadays you can make a single multi-line trigger. They are a bit fiddly to look at, but pretty straightforward. You basically match on what you are expecting to see, replacing line breaks with \n and the variable numbers with (\d+) - things in brackets are saved as wildcards.

\d+ means "one or more digits"

The ?P<blah> syntax gives the wildcards a name, which you can then test in the send box.

Something like this, although I haven't tested it:


Match: 

Strength : (?P<str>\d+)\n
Intelligence : (?P<int>\d+)\n
Wisdom : (?P<wis>\d+)\n
Dexterity : (?P<dex>\d+)\n
Constitution : (?P<con>\d+)\n\z

Regular expression: checked
Multi-line: checked
Lines to match: 6

Send: (something like)

total = %<str> + %<int> + %<wis> + %<dex> + %<con>

if total < 40 then
  send "no"
else
  send "yes"
end if

Amended on Wed 07 Jul 2004 03:55 AM by Nick Gammon
#2
Ok, I havent tested it yet, but could you guys take a look at it to make sure it's ok?

Syntax:

Strength : 14
Intelligence : 21
Wisdom : 11
Dexterity : 12
Constitution : 12

Do you wish keep these stats (y/n)?


My Test Code:

<triggers>
<trigger
enabled="y"
lines_to_match="6"
match="(?x)
^\s*Strength\:\s*(?P<str>\d+)\n
\s*Intelligence\:\s*(?P<int>\d+)\n
\s*Wisdom\:\s*(?P<wis>\d+)\n
\s*Dexterity\:\s*(?P<dex>\d+)\n
\s*Constitution\:\s*(?P<con>\d+)\n
\s*Charisma\:\s*(?P&lt;cha&gt;\d+)*$"
multi_line="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>

if %<str>; 20 or _
%<int>; 20 or _
%<wis>; 20 or _
%<dex>; 20 or _
%<con>; 20 then
ColourNote "white", "blue", "stats too low"
Send "N"
else
ColourNote "white", "blue", "accepted stats"
Send "Y"
end if

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


PS: Used some of your code on a previous post ^^
Australia Forum Administrator #3
From your initial posting you need a space after "Strength" and before the colon.

To test this sort of thing, add the trigger, and then press Shift+Ctrl+F12 to bring up the "Debug simulated world input" screen.

Then paste in an example (like from your first post here) and see if the trigger fires, and if the calculations are correct.

If not, look carefully at the trigger to see why. You probably want a blank line before and after the text to make sure the trigger fires properly.
Australia Forum Administrator #4
Also, this looks wrong:


if %<str>; 20 or _
%<int>; 20 or _
%<wis>; 20 or _
%<dex>; 20 or _
%<con>; 20 then
ColourNote "white", "blue", "stats too low"
Send "N"
else
ColourNote "white", "blue", "accepted stats"
Send "Y"
end if


I think you mean:


if %<str> < 20 or _
%<int> < 20 or _
%<wis> < 20 or _
%<dex> < 20 or _
%<con> < 20 then
ColourNote "white", "blue", "stats too low"
Send "N"
else
ColourNote "white", "blue", "accepted stats"
Send "Y"
end if

#5
Thanks for help =) I was working on it after I posted and fixed a few bugs. I'll post the whole thing when I get it working.
#6
Argh, got stuck with a stupid error that I can't see.

ERROR: Line 13: Element name must start with a letter or an underscore, but starts with a " " (problem in this line)

CODE:

<triggers>
<trigger
enabled="y"
lines_to_match="5"
match="^\s*Strength\s*\:\s*(?P<str>\d+)\n\s*Intelligence\s*\:\s*(?P<int>\d+)\n\s*Wisdom\s*\:\s*(?P<wis>\d+)\n\s*Dexterity\s*\:\s*(?P<dex>\d+)\n\s*Constitution\s*\:\s*(?P<con>\d+)"
multi_line="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>

if %<str> < 20 or _
%<int> < 20 or _
%<wis> < 20 or _
%<dex> < 20 or _
%<con> < 20 then
ColourNote "white", "blue", "stats too low"
Send "N"
else
ColourNote "white", "blue", "accepted stats"
Send "Y"
end if

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

PS: I noticed someone stated that I should add a small pause before each reroll so as not to become a bandwith eating monster =)... How would I do this?
Amended on Wed 07 Jul 2004 07:33 AM by Nobble The Coding Newbie
Australia Forum Administrator #7
If you are trying to paste that in, you need to change the < to &lt; and > to &gt;.

eg.

<str> becomes &lt;str&gt;

Alternatively, manually add a trigger (in the GUI) and then paste the text from the appropriate parts into the box in the dialog.
#8
[EDIT]MUSHclient -> File -> Import -> Clipboard is how I'm trying to add it.[/EDIT]

Ok, I'm getting the same error (same line also), but here is the updated code. Also, how would I add a wait to the reroll so it does not attack the server?
I was thinking it would need to go

ColourNote "white", "blue", "stats too low"
Send "N"
HERE

but I'm not sure how to add a wait. Anyway, here is the full code.

(Thanks for all the help. Especially since it's 2:40am CST)

CODE:

<triggers>
<trigger
enabled="y"
lines_to_match="5"
match="^\s*Strength\s*\:\s*(?P&lt;str&gt;\d+)\n\s*Intelligence\s*\:\s*(?P&lt;int&gt;\d+)\n\s*Wisdom\s*\:\s*(?P&lt;wis&gt;\d+)\n\s*Dexterity\s*\:\s*(?P&lt;dex&gt;\d+)\n\s*Constitution\s*\:\s*(?P&lt;con&gt;\d+)"
multi_line="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>

if %&lt;str&gt; < 20 or _
%&lt;int&gt; < 20 or _
%&lt;wis&gt; < 20 or _
%&lt;dex&gt; < 20 or _
%&lt;con&gt; < 20 then
ColourNote "white", "blue", "stats too low"
Send "N"
else
ColourNote "white", "blue", "accepted stats"
Send "Y"
end if

</send>
</trigger>
</triggers>
USA #9
Change the sends, to doafters.

world.doafter 1, "Y"
world.doafter 1, "N"

The number is time in seconds. So you can change it to suit your needs.

You wouldnt need to really wait with the note, although you could do that as well.
Amended on Wed 07 Jul 2004 08:17 AM by Flannel
Australia Forum Administrator #10
Quote:

if %&lt;str&gt; < 20 or _


You missed one there. That is:

if %&lt;str&gt; &lt; 20 or _

#11
Ok thanks for all the help guys. It works like a charm. Here is the following code. (note: I had to enabel scripts on the scripts to run it)

"Note for other Newbies: the match=" is all one line. Use the symbols to make it look like they syntax you need, then make it all one line. Also, I think you would need to change the lines_to_match="#" if you want to change it to suit your needs."

CODE:

<triggers>
<trigger
enabled="y"
lines_to_match="5"
match="^\s*Strength\s*\:\s*(?P&lt;str&gt;\d+)\n\s*Intelligence\s*\:\s*(?P&lt;int&gt;\d+)\n\s*Wisdom\s*\:\s*(?P&lt;wis&gt;\d+)\n\s*Dexterity\s*\:\s*(?P&lt;dex&gt;\d+)\n\s*Constitution\s*\:\s*(?P&lt;con&gt;\d+)"
multi_line="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>

if %&lt;str&gt; &lt; 20 or _
%&lt;int&gt; &lt; 20 or _
%&lt;wis&gt; &lt; 20 or _
%&lt;dex&gt; &lt; 20 or _
%&lt;con&gt; &lt; 20 then
ColourNote "white", "blue", "stats too low"
world.doafter 1, "N"
else
ColourNote "white", "blue", "accepted stats"
world.doafter 1, "Y"
end if

</send>
</trigger>
</triggers>
#12
alrighty, I play on a mud called Dark-Legacy, im working on one very similar, and ive just developed mine from yours.

Firstly an example of what im matching to:


You may now roll for your character's stats.
You may roll as often as you like.


    Strength: 10 (Average)
   Dexterity: 22 (Extremely nimble)
Constitution: 11 (Average)
Intelligence: 16 (Very smart)
      Wisdom: 11 (Average)
    Charisma: 21 (Exquisite)
        Luck: 11 (Average)

Keep? (Y/N)

    Strength: 10 (Average)
   Dexterity: 18 (Very nimble)
Constitution: 12 (Average)
Intelligence: 11 (Average)
      Wisdom: 16 (Wise)
    Charisma: 19 (Attractive)
        Luck: 15 (Lucky)

Keep? (Y/N)

    Strength: 13 (Hardy)
   Dexterity: 19 (Very nimble)
Constitution: 10 (Average)
Intelligence: 12 (Average)
      Wisdom: 12 (Average)
    Charisma: 19 (Attractive)
        Luck: 17 (Very lucky)

Keep? (Y/N)


And, this is what I've got as a trigger as a development
from his, I have scripting enabled, it sends to script,
matches the correct number of lines, I dont know what kind
of script this is... Also, I wanted it to calculate the
total of what it gets for stats, and post it on the screen.
My Reasoning for having a total AND the stats is so that I can setup a baseline for what I want, and then set up a target stat setting.

<triggers>
  <trigger
   enabled="y"
   lines_to_match="7"
   match="^\s*Strength:\s*(?P&lt;str&gt;\d+)\s*(?P&lt;avstr&gt;\d+)\n\s*Dexterity:\s*(?P&lt;dex&gt;\d+)\s*(?P&lt;avdex&gt;\d+)\nConstitution:\s*(?P&lt;con&gt;\d+)\s*(?P&lt;avcon&gt;\d+)\nIntelligence\:\s*(?P&lt;int&gt;\d+)\s*(?P&lt;avint&gt;\d+)\n\s*Wisdom\:\s*(?P&lt;wis&gt;\d+)\s*(?P&lt;avwis&gt;\d+)\n\s*Charisma\:\s*(?P&lt;cha&gt;\d+)\s*(?P&lt;avcha&gt;\d+)\n\s*Luck\:\s*(?P&lt;lck&gt;\d+)\s*(?P&lt;avlck&gt;\d+)"
   multi_line="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

if %&lt;str&gt; &lt; 13 or _
%&lt;int&gt; &lt; 15 or _
%&lt;wis&gt; &lt; 15 or _
%&lt;dex&gt; &lt; 15 or _
%&lt;con&gt; &lt; 15 or _
%&lt;cha&gt; &lt; 5 or _
%&lt;lck&gt; &lt; 10 then
ColourNote "white", "blue", "stats too low"
world.doafter 1, "N"
else
ColourNote "white", "red", "accepted stats"
world.doafter 1, "Y"
end if

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



Now, to get it to add the total (i also want the total
to be part of the deciding factor, then would it be this(?)) And curious to find out how to get it to post the total:


<send>

total = %&lt;str&gt; + %&lt;int&gt; + %&lt;dex&gt; + %&lt;con&gt; + %&lt;cha&gt; + %&lt;lck&gt;

if %&lt;str&gt; &lt; 13 or _
%&lt;int&gt; &lt; 15 or _
%&lt;wis&gt; &lt; 15 or _
%&lt;dex&gt; &lt; 15 or _
%&lt;con&gt; &lt; 15 or _
%&lt;cha&gt; &lt; 5 or _
%&lt;lck&gt; &lt; 10 also
total < 107
ColourNote "white", "blue", "stats too low"
world.doafter 1, "N"
else
ColourNote "white", "red", "accepted stats"
world.doafter 1, "Y"
end if

</send>
Amended on Fri 21 Jan 2005 07:45 PM by Verdammt
Australia Forum Administrator #13
I would use the word "and" instead of "also", and assuming you are using VBscript I think you need a "then" after the if test.

What do you mean by "post" the total? Display it?
#14
as in to post it like the debug mode would I suppose that'd be display haha... yeah :/
Australia Forum Administrator #15
You are already doing ColourNote, that displays it. You could use straight Note to save specifying colours.
#16
no, what I meant was, what would I do to call up the total value?

Edit: bah, I still can't get it to fire... if you think you can give me a hand nick, I'd appreciate it a lot.

The IP and Port are dark-legacy.com//9898

and here's what I have as a trigger.

<triggers>
<trigger
enabled="y"
lines_to_match="7"
match="^\s*Strength:\s*(?P&lt;str&gt;\d+)\s*(?P&lt;avstr&gt;\d+)\n\s*Dexterity:\s*(?P&lt;dex&gt;\d+)\s*(?P&lt;avdex&gt;\d+)\nConstitution:\s*(?P&lt;con&gt;\d+)\s*(?P&lt;avcon&gt;\d+)\nIntelligence\:\s*(?P&lt;int&gt;\d+)\s*(?P&lt;avint&gt;\d+)\n\s*Wisdom\:\s*(?P&lt;wis&gt;\d+)\s*(?P&lt;avwis&gt;\d+)\n\s*Charisma\:\s*(?P&lt;cha&gt;\d+)\s*(?P&lt;avcha&gt;\d+)\n\s*Luck\:\s*(?P&lt;lck&gt;\d+)\s*(?P&lt;avlck&gt;\d+)"
multi_line="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>

total = %&lt;str&gt; + %&lt;int&gt; + %&lt;dex&gt; + %&lt;con&gt; + %&lt;cha&gt; + %&lt;lck&gt;

if %&lt;str&gt; &lt; 13 or _
%&lt;int&gt; &lt; 15 or _
%&lt;wis&gt; &lt; 15 or _
%&lt;dex&gt; &lt; 15 or _
%&lt;con&gt; &lt; 15 or _
%&lt;cha&gt; &lt; 5 or _
%&lt;lck&gt; &lt; 10 and
total &lt; 107 then
ColourNote "white", "blue", "stats too low"
world.doafter 1, "N"
else
ColourNote "white", "red", "accepted stats"
world.doafter 1, "Y"
end if

</send>
</trigger>
</triggers>
Amended on Tue 01 Feb 2005 12:12 PM by Verdammt
Australia Forum Administrator #17
Can you paste an example of what it sends that you are trying to match on?
#18
I had already done so in a previous topic, but here it is again:

You may now roll for your character's stats.
You may roll as often as you like.


Strength: 10 (Average)
Dexterity: 22 (Extremely nimble)
Constitution: 11 (Average)
Intelligence: 16 (Very smart)
Wisdom: 11 (Average)
Charisma: 21 (Exquisite)
Luck: 11 (Average)

Keep? (Y/N)

Strength: 10 (Average)
Dexterity: 18 (Very nimble)
Constitution: 12 (Average)
Intelligence: 11 (Average)
Wisdom: 16 (Wise)
Charisma: 19 (Attractive)
Luck: 15 (Lucky)

Keep? (Y/N)

Strength: 13 (Hardy)
Dexterity: 19 (Very nimble)
Constitution: 10 (Average)
Intelligence: 12 (Average)
Wisdom: 12 (Average)
Charisma: 19 (Attractive)
Luck: 17 (Very lucky)

Keep? (Y/N)