Advertisement
Guest User

Untitled

a guest
Mar 19th, 2012
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.94 KB | None | 0 0
  1. SafeQueueDB = SafeQueueDB or { announce = "self", enabled = true, minimap = "on" }
  2. local queueTime
  3. local queue = 0
  4. local button2 = StaticPopupDialogs["CONFIRM_BATTLEFIELD_ENTRY"].button2
  5. local remaining = 0
  6.  
  7. local function SafeQueue_MiniMapButton(self, button)
  8.     if SafeQueueDB.minimap == "off" or not IsRaidLeader() then return end
  9.     if (button == "RightButton") then
  10.         for i=1, GetMaxBattlefieldID() do
  11.             local status, _, _, _, _, _, registeredMatch = GetBattlefieldStatus(i)
  12.             if (registeredMatch == 1) then
  13.                 if (status == "queued") then
  14.                     DropDownList1:Hide()
  15.                     AcceptBattlefieldPort(i, 1)
  16.                     AcceptBattlefieldPort(i, 0)
  17.                 end
  18.                 break
  19.             end
  20.         end
  21.     end
  22. end
  23.  
  24. local function SafeQueue_Print(msg)
  25.     DEFAULT_CHAT_FRAME:AddMessage("|cff33ff99SafeQueue|r: " .. msg)
  26. end
  27.  
  28. local function SafeQueue_PrintTimeWaited()
  29.     if SafeQueueDB.announce == "off" then return end
  30.     local secs, str, mins = floor(GetTime() - queueTime), "Queue popped "
  31.     if secs < 1 then
  32.         str = str .. "instantly!"
  33.     else
  34.         str = str .. "after "
  35.         if secs >= 60 then
  36.             mins = floor(secs/60)
  37.             str = str .. mins .. "m "
  38.             secs = secs%60
  39.         end
  40.         if secs%60 ~= 0 then
  41.             str = str .. secs .. "s"
  42.         end
  43.     end
  44.     if SafeQueueDB.announce == "self" then
  45.         SafeQueue_Print(str)
  46.     elseif SafeQueueDB.announce == "raid" then
  47.         if GetRealNumRaidMembers() > 0 then
  48.             SendChatMessage(str, "RAID")
  49.         else
  50.             SendChatMessage(str, "PARTY")
  51.         end
  52.     elseif SafeQueueDB.announce == "party" then
  53.         SendChatMessage(str, "PARTY")
  54.     end
  55. end
  56. local function SafeQueue_Timer()
  57.     local secs = GetBattlefieldPortExpiration(queue)
  58.     if secs > 0 and SafeQueueDB.enabled == true then
  59.         local p = StaticPopup_Visible("CONFIRM_BATTLEFIELD_ENTRY")
  60.         if p then
  61.             local color
  62.             if remaining ~= secs then
  63.                 remaining = secs
  64.                 if secs > 20 then
  65.                     color = "f20ff20"
  66.                 elseif secs > 10 then
  67.                     color = "fffff00"
  68.                 else
  69.                     color = "fff0000"
  70.                 end
  71.                 _G[p .. "Text"]:SetText(string.gsub(
  72.                     _G[p .. "Text"]:GetText(),
  73.                     ".+ to enter",
  74.                     "You have |cf"..color.. SecondsToTime(secs) .. "|r to enter"))
  75.             end
  76.         end
  77.     end
  78. end
  79.  
  80. local function SafeQueue_Update()
  81.     local queued
  82.     for i=1, GetMaxBattlefieldID() do
  83.         local status, _, _, _, _, _, registeredMatch = GetBattlefieldStatus(i)
  84.         if registeredMatch == 1 then
  85.             if status == "queued" then
  86.                 queued = true
  87.                 if not queueTime then queueTime = GetTime() end
  88.             elseif status == "confirm" then
  89.                 if queueTime then
  90.                     SafeQueue_PrintTimeWaited()
  91.                     queueTime = nil
  92.                     remaining = 0
  93.                     queue = i
  94.                 end                
  95.             end
  96.             break
  97.         end
  98.     end
  99.     if not queued and queueTime then queueTime = nil end
  100. end
  101.  
  102. local function SafeQueue_Enable()
  103.     frame:RegisterEvent("UPDATE_BATTLEFIELD_STATUS")
  104.     StaticPopupDialogs["CONFIRM_BATTLEFIELD_ENTRY"].button2 = nil
  105.     StaticPopupDialogs["CONFIRM_BATTLEFIELD_ENTRY"].hideOnEscape = false
  106. end
  107.  
  108. local function SafeQueue_Disable()
  109.     frame:UnregisterEvent("UPDATE_BATTLEFIELD_STATUS")
  110.     StaticPopupDialogs["CONFIRM_BATTLEFIELD_ENTRY"].button2 = button2
  111.     StaticPopupDialogs["CONFIRM_BATTLEFIELD_ENTRY"].hideOnEscape = true
  112. end
  113.  
  114. local function SafeQueue_Command(msg)
  115.     msg = msg or ""
  116.     local cmd, arg = string.split(" ", msg, 2)
  117.     cmd = string.lower(cmd or "")
  118.     arg = string.lower(arg or "")
  119.     if cmd == "enable" then
  120.         if SafeQueueDB.enabled == false then
  121.             SafeQueue_Enable()
  122.             SafeQueueDB.enabled = true 
  123.         end
  124.         SafeQueue_Print("|cff00ff00Enabled|r")
  125.     elseif cmd == "disable" then
  126.         if SafeQueueDB.enabled == true then
  127.             SafeQueue_Disable()
  128.             SafeQueueDB.enabled = false
  129.         end
  130.         SafeQueue_Print("|cffff0000Disabled|r")
  131.     elseif cmd == "safeleave" then
  132.         if arg == "on" then
  133.             SafeQueueDB.minimap = "on"
  134.         elseif arg == "off" then
  135.             SafeQueueDB.minimap = "off"
  136.         end
  137.         SafeQueue_Print("SafeLeave is " .. SafeQueueDB.minimap)
  138.     elseif cmd == "announce" then
  139.         if arg == "off" or arg == "self" or arg == "party" or arg == "raid" then
  140.             SafeQueueDB.announce = arg
  141.             SafeQueue_Print("Announce set to " .. arg)
  142.         else
  143.             SafeQueue_Print("Announce set to " .. SafeQueueDB.announce)
  144.             SafeQueue_Print("Announce types are \"off\", \"self\", \"party\", and \"raid\"")
  145.         end
  146.     else
  147.         local status
  148.         if SafeQueueDB.enabled == true then status = "|cff00ff00Enabled|r" else status = "|cffff0000Disabled|r" end
  149.         DEFAULT_CHAT_FRAME:AddMessage("|cff33ff99SafeQueue v1.26|r")
  150.         SafeQueue_Print(status)
  151.         SafeQueue_Print("/sq enable")
  152.         SafeQueue_Print("/sq disable")
  153.         SafeQueue_Print("/sq announce : " .. SafeQueueDB.announce)
  154.         SafeQueue_Print("/sq safeleave : " .. SafeQueueDB.minimap)
  155.     end
  156. end
  157.  
  158. frame = CreateFrame("Frame", nil, UIParent)
  159. frame:SetScript("OnEvent", SafeQueue_Update)
  160. frame:SetScript("OnUpdate", SafeQueue_Timer)
  161. if SafeQueueDB.enabled == true then SafeQueue_Enable() end
  162.  
  163. MiniMapBattlefieldFrame:HookScript("OnClick", SafeQueue_MiniMapButton);
  164.  
  165. SlashCmdList["SafeQueue"] = SafeQueue_Command
  166. SLASH_SafeQueue1 = "/safequeue"
  167. SLASH_SafeQueue2 = "/sq"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement