An addition of variables trigger/script

Posted by Alisdair on Thu 24 Apr 2003 09:21 AM — 6 posts, 19,541 views.

Canada #0
I've been reading file after file and post after post to try and find something relavent to my problem, but so far nothing. What I'm try to accomplish is a trigger or script that will add up 5 numbers and give a total.

[Str: 47  Int: 36  Wis: 32  Dex: 60  Con: 45]
Keep these stats? (Y/N) 


What I want is to be able to add up those 5 numbers and get a total of at least 250. And I'd like it to simply send "N" to world if it gets anything less, but stop if it gets a total of 250 or greater. Any suggestions?
Australia Forum Administrator #1
Yes, you can do that easily enough with one trigger. This trigger below uses a regular expression to match on your line, adds up the 5 figures, and if it reaches 250 sends Y and disables itself, otherwise it sends N.

You need a recent version of MUSHclient, as it uses inline scripting, version 3.39 is now released.


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="^\[Str\:\s+(\d+)\s+Int\:\s+(\d+)\s+Wis\:\s+(\d+)\s+Dex\:\s+(\d+)\s+Con\:\s+(\d+)\]$"
   name="initialtest"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>if %1 + %2 + %3 + %4 + %5 &gt;= 250 then
  send &quot;Y&quot;
  enabletrigger &quot;initialtest&quot;, 0
  note &quot;Found it!&quot;
else
  send &quot;N&quot;
end if</send>
  </trigger>
</triggers>


Make sure scripting is enabled or the script won't do anything. :)
Amended on Thu 24 Apr 2003 11:32 AM by Nick Gammon
Canada #2
Wow, thanks a bunch Nick :)
Canada #3
Ok, this is weird for whatever reason, but with the trigger, the output gets a little screwy, and ends up that the trigger stops.

Here's what I mean:

[Str: 44  Int: 40  Wis: 38  Dex: 50  Con: 43]
N
Keep these stats? (Y/N) [Str: 44  Int: 47  Wis: 40  Dex: 53  Con: 45]


That happens right after the trigger fires. Any solutions?
Amended on Thu 24 Apr 2003 04:44 PM by Alisdair
Australia Forum Administrator #4
You need to modify the trigger match text slightly to allow for optional extra stuff at the start, like this:

^.*\[Str\:\s+(\d+)\s+Int\:\s+(\d+)\s+Wis\:\s+(\d+)\s+Dex\:\s+(\d+)\s+Con\:\s+(\d+)\]$
Australia Forum Administrator #5
You probably need to make sure the trigger is enabled next time, by either taking out the line that disables it (and hoping that text never appears during game play), or matching on something that appears right at the start, eg. "Enter you character name") and making another trigger that enables it.

It would need to do this:

enabletrigger "initialtest", 1