View Single Post
03-19-24, 09:23 AM   #10
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113
Originally Posted by Xrystal View Post
That is because you didn't use the the localization version.

L.Running, MyRegion[id].name

L.Running is using the localization version
MyRegion[id].name is using the English version

What you need to do is use that English version as a key to the localized version.
Try L[MyRegion[id].name]
Hi, thanks for the tip. That's right?

Lua Code:
  1. local addonName, addon = ...
  2. local L, MyRegion
  3. local RegionTimes = {
  4.     [1] = {
  5.         startTime = 1679572800,
  6.         totalDuration = 14400, -- complete session time 4 hours repeating
  7.         sub_sessionDuration = 3600, -- 1 hour
  8.         waitTime = 3300, -- 55 minutes
  9.         eventtime = 300, -- 5 minutes implied but..
  10.         [1] = { -- sub-sessions
  11.             name = "A",
  12.         },
  13.         [2] = {
  14.             name = "B",
  15.         },
  16.         [3] = {
  17.             name = "C",
  18.         },
  19.         [4] = {
  20.             name = "D",
  21.         },
  22.     },
  23. }
  24.  
  25. --[[ TEST TIMES ONLY: over 4 minutes instead of 4 hours ]]--
  26.  
  27. --[[
  28. RegionTimes[1].totalDuration = 240 -- 4 minutes
  29. RegionTimes[1].sub_sessionDuration = 60 -- 1 minute
  30. RegionTimes[1].waitTime = 55 -- seconds
  31. RegionTimes[1].eventtime = 5 -- seconds
  32. ]]--
  33.  
  34. --[[ END TEST TIMES ]]--
  35.  
  36. local Localizations = {
  37.     enUS = {
  38.         Waiting = "%s before event %s starts",
  39.         Running = "Event: |cFF35BE21%s|r\n%s remaining",
  40.         A = "Name of event A",
  41.         B = "Name of event B",
  42.         C = "Name of event B",
  43.         D = "Name of event B",
  44.     },
  45.      deDE = {
  46.         Waiting = "%s verbleibende Zeit bis zur Veranstaltung %s",
  47.         Running = "Ereignis: |cFF35BE21%s|r\n%s Kommen",
  48.         A = "Freiflächen",
  49.         B = "Grüne",
  50.         C = "Rote",
  51.         D = "Weiß",
  52.     },
  53. }
  54.  
  55. ------------------------------------------------------------------------------------------------------
  56. -- These might be converted to Saved Variables so each character can determine
  57. -- wether or not to play a sound, the alert times and colors and sound to play.
  58. -- If so then most of the code below will have to move into an event handler for
  59. -- the PLAYER_LOGIN or PLAYER_ENTERING_WORLD event.
  60. local useColor = true
  61. local useSound = true
  62. local alert1 = 600 -- Alarm 1 set to 5 minutes before event
  63. local alert1Color = "|cffffff00" -- Yellow
  64. local alert2 = 30 -- Alarm 2 set to 30 seconds before event
  65. local alert2Color = "|cffff0000" -- Red
  66. local soundKit = 32585 -- Alarm sound
  67. ------------------------------------------------------------------------------------------------------
  68.  
  69. local function printTime(timetotrun, inevent)
  70.     local hideSeconds = timetotrun >= 120
  71.     local msg = L.Waiting
  72.     local msgColor = "|cffffffff"
  73.     if inevent then
  74.         msg = L.Running
  75.     else
  76.         if useColor and timetotrun <= alert2 then
  77.             msgColor = alert2Color
  78.         elseif timetotrun <= alert1 then
  79.             if useSound and not ZAMTimer_4_Events.Alerted then
  80.                 ZAMTimer_4_Events.Alerted = true
  81.                 PlaySound(soundKit, "Master")
  82.             end
  83.             if useColor then
  84.                 msgColor = alert1Color
  85.             end
  86.         end
  87.     end
  88.     f.text:SetText(format(msg, msgColor, SecondsToTime(timetotrun, hideSeconds)))
  89. end
  90.  
  91. ZAMTimer_4_Events.Alerted = false
  92.  
  93. local function OnUpdate(self, elapsed)
  94.     self.Elapsed = self.Elapsed - elapsed
  95.     if self.Elapsed > 0 then -- Only check once per second
  96.         return
  97.     end
  98.     self.Elapsed = 1 -- reset the timeout (we've counted down 1 second)
  99.     local serverTime = GetServerTime()
  100.     local remainingTime = (MyRegion.startTime - serverTime) % MyRegion.totalDuration
  101.     local base = math.ceil(remainingTime / MyRegion.sub_sessionDuration)
  102.     local hourRemaining = MyRegion.sub_sessionDuration - ((base * MyRegion.sub_sessionDuration) - remainingTime)
  103.     local id = 4 - (base - 1)
  104.     if id == 5 then
  105.         id = 1
  106.     end
  107.     local msg
  108.     if hourRemaining > MyRegion.waitTime then
  109.         msg = format(L.Running, L[MyRegion[id].name], SecondsToTime(hourRemaining - MyRegion.waitTime, false))
  110.     else
  111.         id = id == 4 and 1 or id + 1
  112.         msg = format(L.Waiting, SecondsToTime(hourRemaining, false), L[MyRegion[id].name])
  113.     end
  114.     self.Text:SetText(msg)
  115.     self:SetSize(self.Text:GetWidth() + 10, self.Text:GetHeight() + 10)
  116. end
  117.  
  118. local Backdrop = {
  119.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  120. }
  121.  
  122. local f = CreateFrame("Button", "ZAMTimer_4_Events", UIParent, "BackdropTemplate")
  123. f:SetWidth(255)                                          
  124. f:SetHeight(30)
  125. f:SetPoint("CENTER")
  126. f:SetBackdrop(Backdrop)
  127. f:SetClampedToScreen(true)
  128. f:EnableMouse(true)
  129. f:SetMovable(true)
  130. f:SetUserPlaced(true)
  131. f:RegisterForDrag("LeftButton")
  132. f:RegisterForClicks("AnyUp")
  133. f.Text = f:CreateFontString(nil, "OVERLAY", "GameTooltipText")
  134. f.Text:SetPoint("CENTER")
  135. f.Elapsed = 0 -- Set starting timeout (0 second)
  136. f:SetScript("OnDragStart",function(self)
  137.     self:StartMoving()
  138. end)
  139. f:SetScript("OnDragStop",function(self)  
  140.     self:StopMovingOrSizing()
  141. end)
  142.  
  143. f:RegisterEvent("PLAYER_LOGIN")
  144. f:SetScript("OnEvent", function(self)
  145.     local locale = GetLocale()
  146.     L = Localizations[locale] or Localizations.enUS -- Default to enUS if locale doesn't exist in the table
  147.     MyRegion = RegionTimes[GetCurrentRegion()] or RegionTimes[1] -- Default to region 1 (US) if it doesn't exist in the table
  148.     f:SetScript("OnUpdate", OnUpdate)
  149. end)
  150.  
  151. SLASH_ZAM4TIMER1 = "/z4" -- toggle hiding/showing the ZAMTimer_4_Events frame using just /z4
  152. SlashCmdList.ZAM4TIMER = function(msg)
  153.     ZAMTimer_4_Events.Elapsed = 0 -- set the "clock" to re-calculate when shown.
  154.     ZAMTimer_4_Events:SetShown(not ZAMTimer_4_Events:IsShown()) -- hide/show the frame
  155. end

yes it worked.

The remaining question is how to attach a sound/color alert. (Just pasting a piece of code didn't work)

Last edited by Hubb777 : 03-19-24 at 09:50 PM.
  Reply With Quote