Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Countdown Timer

Countdown Timer

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


Posted by Rene   (46 posts)  Bio
Date Sat 09 Dec 2017 10:32 PM (UTC)
Message
Hello, I want my colour trigger to have a countdown timer so it does go off too many times in a row, say a 5 second wait.

The line to play the sound is:

PlaySound (0, IsSound, false, 0, 0)

I assume I want some kind of for statement beforehand with a timer, but I don't know where to start.
Thanks!
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Sun 10 Dec 2017 12:04 AM (UTC)
Message
You can use the Lua function os.time to find the current time in seconds.

What I would do is store that in a global variable, in your trigger, if the variable is not already set. Something like this:


<triggers>
  <trigger
   enabled="y"
   match="foo"
   send_to="12"
   sequence="100"
  >
  <send>

-- if 10 seconds are up forget about when it last fired and zero the counter
if recentTimeTriggerFired then
  if os.difftime (os.time (), recentTimeTriggerFired) &gt;= 10 then
    timesTriggerNoticed = 0
  end -- if over 10 seconds since last time

  -- IF less than 5 seconds have elapsed
  -- AND it has fired more than 3 times
  -- THEN play the sound

  if os.difftime (os.time (), recentTimeTriggerFired) &lt;= 5 and
     timesTriggerNoticed &gt;= 3 then
     check (PlaySound (0, "tada.wav"))
     timesTriggerNoticed = 0
  end -- end of 3 times in a row with the most recent less than 5 seconds ago
end -- if it fired before

recentTimeTriggerFired = os.time ()
timesTriggerNoticed = (timesTriggerNoticed or 0) + 1

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




Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


12,490 views.

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

Go to topic:           Search the forum


[Go to top] top

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