Timers reset on reconnect / connect

Posted by Amoxil on Sat 24 Aug 2024 12:05 PM — 2 posts, 5,599 views.

#0
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
Amended on Sat 24 Aug 2024 12:11 PM by Amoxil
Australia Forum Administrator #1
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).

Template:function=GetTimerInfo
GetTimerInfo

The documentation for the GetTimerInfo script function is available online. It is also in the MUSHclient help file.



Put that figure into a variable (SetVariable), and make sure you save your world file (to save the variable).

Template:function=SetVariable
SetVariable

The documentation for the SetVariable script function is available online. It is also in the MUSHclient help file.



Template:function=Save
Save

The documentation for the Save script function is available online. It is also in the MUSHclient help file.



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.