Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, 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.
Entire forum
➜ MUSHclient
➜ General
➜ Timers reset on reconnect / connect
Timers reset on reconnect / connect
|
You need to log onto the forum to reply or create new threads.
Refresh page
Posted by
| Amoxil
(1 post) Bio
|
Date
| Sat 24 Aug 2024 12:05 PM (UTC) Amended on Sat 24 Aug 2024 12:11 PM (UTC) by Amoxil
|
Message
| Is there any way to stop this happening (for daily reminders, where the next reminder is affected by game actions so not always at the same time (e.g. 24 hours from typing give gold to sally), but at the same interval from game output)?
Or a way to make a timer go off at a specific date (so it wouldn't matter that it gets reset on reconnect) starting from the receiving of an output from the game?
That would be better so don't have to keep mushclient / computer turned on all the time (and better for the environment :))
I noticed you can pull the Unix epoch time for an existing timer, so theoretically you could make a new timer with 23:59:59 offset then immediately query the Unix epoch time of when the timer will fire, and then delete that and make a new timer at that Unix epoch time, but I can't find any way in scripting to make a new timer at a specific Unix epoch time or to convert the Unix epoch time into an hours/minutes/seconds time
Thank you anyone | Top |
|
Posted by
| Nick Gammon
Australia (23,070 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sun 25 Aug 2024 05:00 AM (UTC) Amended on Sun 25 Aug 2024 05:03 AM (UTC) by Nick Gammon
|
Message
| It can be done with a bit of scripting. Basically you want to have some sort of reminder about a cooldown being over, after x hours of game time, not elapsed time, is that it?
What you could do is have a script function called "OnDisconnect" which is a function name you can put into the "Disconnect" field of the scripting configuration.
In that function you can find out how long until your timer fires using GetTimerInfo("foo", 13).
Put that figure into a variable (SetVariable), and make sure you save your world file (to save the variable).
Then when the world connects again (the "Connect" script) delete the old timer and make a new one with the appropriate amount of seconds to go, as read from that variable.
Something like this should do it:
-- add a timer named "foo" with supplied hour, minutes, seconds
-- or seconds only which will be converted to hours, minutes, seconds
function AddMyTimer (hour, minute, second)
require "addxml"
if second > 59 or not hour or not minute then
hours = math.floor (seconds / 3600)
seconds = seconds - (hours * 3600)
minutes = math.floor (seconds / 60)
seconds = seconds - (minutes * 60)
else
seconds = second
end -- if
addxml.timer {
enabled = 'y',
name = "foo",
active_closed = 'n',
at_time = 'n',
hour = hours,
minute = minutes,
second = seconds,
send = 'Event has occurred!',
send_to = sendto.output,
one_shot = 'y'
}
Note (string.format ("Timer added to expire in %02d:%02d:%02d (HH:MM:SS)",
hours, minutes, seconds))
end -- AddMyTimer
function OnDisconnect ()
SetVariable ("timer_seconds_to_go", math.floor (GetTimerInfo("foo", 13)))
Save () -- force save of world file
end -- OnDisconnect
function OnConnect ()
seconds = tonumber (GetVariable ("timer_seconds_to_go"))
if not seconds or seconds <= 0 then
return
end -- if timer not needed
-- correct timer expiry time
AddMyTimer (0, 0, seconds)
end -- OnConnect
Put the above into your Lua script file, and in the Scripting configuration add "OnConnect" to the "connect" field, and "OnDisconnect" to the "disconnect" field.
The script file is just a text file, and then browse for that file and make it your script file. |
- 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.
483 views.
You need to log onto the forum to reply or create new threads.
Refresh page
top