[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Trigger for "lottery cards" help?!

Trigger for "lottery cards" help?!

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


Posted by Fizban   (1 post)  [Biography] bio
Date Thu 07 Sep 2006 07:18 PM (UTC)
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Thu 07 Sep 2006 09:34 PM (UTC)

Amended on Thu 07 Sep 2006 09:41 PM (UTC) by Nick Gammon

Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Thu 07 Sep 2006 09:42 PM (UTC)
Message
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>

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] 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.


9,831 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]