View Single Post
08/12/14, 11:07 PM   #3
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
There are a bunch of functions for getting time in the game. Look at the API under the global section: http://wiki.esoui.com/API#Global
I didn't test any of this -- But it should point you in the right direction
You could call a function on intialize to get the time you start playing. Needed to check and see if you started playing before 3am or after 3am.
Lua Code:
  1. -- call it on initialize & save the time you start playing --
  2. local function LogTime()
  3.     -- Capture start playing time --
  4.     myAddon.StartTime = GetSecondsSinceMidnight()
  5. end

You could then use the following and register it to some event that happens frequently so its checked often.
Lua Code:
  1. function myAddon.TimeAlert()
  2.     local iSecSinceMidnight = GetSecondsSinceMidnight()
  3.  
  4.     -- 3 am = 3 hours past midnight, 3 hours * 60 min/hour * 60 sec/min = 10800 seconds --
  5.    
  6.     -- If you start playing at 10pm we dont want the alarm going off yet, so we check the start time: --
  7.     -- (If you started playing After 3am) and (its earlier than you started playing, then its the next day) and (its after 3am now) --
  8.     -- or (you started playing before 3am) and (its now after 3am)
  9.     if (((myAddon.StartTime > 10800) and (iSecSinceMidnight < myAddon.StartTime) and (iSecSinceMidnight > 10800) ) or
  10.     ((myAddon.StartTime < 10800) and (iSecSinceMidnight > 10800))) then
  11.         -- do whatever you want your alarm to be --
  12.  
  13.         -- Create a window to pop-up, unhide it at 3am --
  14.         myAddon.popUpWindow:SetHidden(false)
  15.        
  16.         -- Display a chat Message --
  17.         d("It's 3 A.M.")
  18.        
  19.         -- Play some sound:  5 times, once every second to make sure you here it --
  20.         for i = 1, 5 do
  21.             zo_callLater(function() PlaySound(SOUNDS.GENERAL_ALERT_ERROR) end, (i*1000))
  22.         end
  23.     end
  24. end

You could also do what was suggested & take that same information & do a timer. I've never messed with anything like that except timing something for a few seconds. I don't know how accurate a zo_callLater would be for an extended period of time or if it has a time limit on it (it may not work if set for several hours I have no clue). Theres probably a better way to set a timer, but the rest of it should point you in the right direction to get the information you need to set a timer.
Lua Code:
  1. -- call it on initialize & get the time you start playing --
  2. function myAddon.LogTime()
  3.     -- Capture start playing time --
  4.     local iStartTimeSecs = GetTimeStamp()
  5.     local iAlertTime = 10800
  6.    
  7.     -- If you started after 3am --
  8.     if iStartTimeSecs > 10800 then
  9.         -- Calculate the number of seconds left in the day --
  10.         -- 24 hours/day * 60 min/hour * 60 sec/min = 86400 sec/day --
  11.         local iNumSecsTillMidnight = (86400 - iStartTimeSecs)
  12.         -- and add it to the number of seconds after midnight (for your alarm) --
  13.         iAlertTime = iAlertTime + iNumSecsTillMidnight
  14.     end
  15.  
  16.     -- I have no idea how accurate this would be or if it would even work over an extended period of time --
  17.     zo_callLater(function() myAddon.PlayAlert() end, (iAlertTime*1000))
  18. end
  19.  
  20. function myAddon.PlayAlert()
  21.     -- Do whatever, same as above --
  22. end

Last edited by circonian : 08/12/14 at 11:12 PM.
  Reply With Quote