Trigger for "lottery cards" help?!

Posted by Fizban on Thu 07 Sep 2006 07:18 PM — 3 posts, 14,595 views.

#0
On my MUD we have these "scratch cards" that using triggers for you can scratch everyone elses as the give them to you.
I have the triggers working for now but I am trying to write a multiline trigger in this fashion:

(person) gives you a (type) scratch card
i then have to input, scratch card as a command
if it wins, i need to be able to give the (person)
their winnings after i have entered a command
I can't figure out how to link the first line to an input line later on

I hope this is not to vague, im not a programmer, so I dont know how the trigger is "written"
Thanx for the help.
Australia Forum Administrator #1
It helps to see actual MUD output so we can see exactly what the triggers will be, so I have to guess a bit. This single trigger should do it:


<triggers>
  <trigger
   enabled="y"
   match="* gives you a * type scratch card"
   send_to="12"
   sequence="100"
  >
  <send>

do local t = coroutine.create (function (t)

-- scratch the card

Send "scratch %2 card"

local line, wildcards = waitforregexp (t, 
          "^(Your card wins! You get (?P&lt;gold&gt;.+) gold.|Your card loses\\.)$")

-- check for win or loss

if string.find (line, "wins") then
  local gold = wildcards.gold  -- amount won
  Send ("say You won " .. gold .. " gold!")
  Send ("give " .. gold .. " to %1" )
else
  Send ("say Bad luck, your card lost.")
end  -- if

end) assert (coroutine.resume (t, t)) end

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



For a discussion of how it works, see:

http://www.gammon.com.au/forum/?id=4957

You need the "wait" functions described on that page to make it work. They ship in the exampscript.lua file that comes with MUSHclient, so just make that your script file (or more safely, make a copy of it and make the copy your script file).

The above stuff gets copied and pasted into the trigger configuration list, see this post for how to do that:

http://www.gammon.com.au/forum/?id=4777

How it works ...

  • The trigger itself matches on the thing that starts the sequence off, I guessed it would be like this:


    John gives you a frizzle type scratch card


    You need to amend the trigger to get it to match exactly, or nothing will happen.
  • The trigger starts up a coroutine (the first line in the trigger - the reason for that is explained in the post I mentioned. Effectively a coroutine can pause and wait for further input.
  • It then sends the scratch command:


    scratch frizzle card

  • It waits on a regular expression which matches either the win or lose message from the MUD.

    In this case I am expecting either:


    Your card wins! You get 55 gold.

    or

    Your card loses.


    Again you need to modify that regexp to match what you really get.

    It then checks which regular expression matched by checking for the word "wins" in the matching line. If it was a win, it sends a message to the player, and a "give" command.

    If it is a loss, it simply send a message to the player.

    All of these need to be tweaked to match what the exact message format should be.


That's it basically. The coroutine idea simplifies somewhat a multi-line response like this.
Amended on Thu 07 Sep 2006 09:41 PM by Nick Gammon
Australia Forum Administrator #2
If you wait for MUSHclient 3.80 the trigger is a bit simplified. The "wait" stuff is in a separate file, which you "require" (so you don't need the script file), and the script itself is a bit simpler:


<triggers>
  <trigger
   enabled="y"
   match="* gives you a * type scratch card"
   send_to="12"
   sequence="100"
  >
  <send>

require "wait"

wait.make (function ()

-- scratch the card

Send "scratch %2 card"

local line, wildcards = wait.regexp ( 
       "^(Your card wins! You get (?P&lt;gold&gt;.+) gold.|Your card loses\\.)$")

-- check for win or loss

if string.find (line, "wins") then
  local gold = wildcards.gold  -- amount won
  Send ("say You won " .. gold .. " gold!")
  Send ("give " .. gold .. " to %1" )
else
  Send ("say Bad luck, your card lost.")
end  -- if

end) 
</send>
  </trigger>
</triggers>