Gammon Forum
Entire forum
MUSHclient
General
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 (22,975 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) >= 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) <= 5 and
timesTriggerNoticed >= 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>
|
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.
8,895 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
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.