Guest User

Untitled

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