Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- only edit stuff below here
- ----------
- local m_pets = "mypets" -- these four things must be the same on each persons addon
- local m_queue = "letsqueue"
- local m_pop = "poppinfresh"
- local m_no = "know"
- local m_channel = "PARTY" -- channel to broadcast msg
- local m_target = nil -- only use this for m_channel == 'WHISPER' or 'CHANNEL' for chat messages
- local include_pet_names = true -- include pet names in the broadcast message, only really useful as a visual aid
- local use_addon_msg = false -- using addon messages instead of chat messages
- local m_addon_prefix = "DIXBUTT" -- prefix to register
- local max_decline_count = 5 -- if we have to decline a battle more than this number, just enter it to get the person out of the queue
- -- either manually forfiet or afk (afking prolly dodgy)
- local a_cmd = "startomg" -- /command to start
- ----------
- -- only edit stuff above here
- local addon_name = ...
- local popped = 0
- local popped_ok = false
- local nextupdate = 0
- local decline_count = 0
- local enabled = false
- local leader = false
- local events_chat = {
- "CHAT_MSG_ADDON",
- "CHAT_MSG_CHANNEL",
- "CHAT_MSG_EMOTE",
- "CHAT_MSG_GUILD",
- "CHAT_MSG_INSTANCE_CHAT",
- "CHAT_MSG_INSTANCE_CHAT_LEADER",
- "CHAT_MSG_OFFICER",
- "CHAT_MSG_PARTY",
- "CHAT_MSG_PARTY_LEADER",
- "CHAT_MSG_RAID",
- "CHAT_MSG_RAID_LEADER",
- "CHAT_MSG_RAID_WARNING",
- "CHAT_MSG_SAY",
- "CHAT_MSG_WHISPER",
- "CHAT_MSG_YELL",
- }
- local function doprint(s)
- DEFAULT_CHAT_FRAME:AddMessage(addon_name .. ": " .. s)
- end
- local function isok()
- if not enabled then return false end
- if C_PetBattles.IsInBattle() then return false end -- if we're in a battle, don't bother
- if not C_PetJournal.IsFindBattleEnabled() or not C_PetJournal.IsJournalUnlocked() then return false end -- if we can't even queue, dont bother
- return true
- end
- local function dosend(m)
- if use_addon_msg then
- if not IsAddonMessagePrefixRegistered(m_addon_prefix) then
- if not RegisterAddonMessagePrefix(m_addon_prefix) then
- doprint("Error registering prefix: " .. m_addon_prefix)
- enabled = false
- end
- else
- SendAddonMessage(m_addon_prefix, m, m_channel, m_target)
- end
- else
- SendChatMessage(m, m_channel, nil, m_target)
- end
- end
- local function onceyoupop(us)
- if GetTime() - popped < 2 then
- nextupdate = GetTime() + 10
- popped_ok = false
- C_PetBattles.AcceptQueuedPVPMatch()
- else
- popped = GetTime()
- popped_ok = true
- if us then
- dosend(m_pop)
- end
- end
- end
- local z = CreateFrame("Button", nil, UIParent, "PetBattleActionButtonTemplate")
- z.Icon:SetTexture([[Interface\Icons\INV_Pet_PetTrap]])
- z:SetSize(200, 200)
- z:SetPoint("CENTER")
- z:SetScript("OnClick", function() C_PetBattles.ForfeitGame() end)
- z:Hide()
- local function getpets()
- local levels = ""
- local names = ""
- local count25 = 0
- for i = 1, 3 do
- local petID, ability1ID, ability2ID, ability3ID, locked = C_PetJournal.GetPetLoadOutInfo(i)
- local speciesID, customName, level, xp, maxXp, displayID, isFavorite, name, icon, petType, creatureID, sourceText, description, isWild, canBattle, tradable, unique = C_PetJournal.GetPetInfoByPetID(petID)
- if level == 25 then
- count25 = count25 + 1
- end
- levels = levels .. level .. " "
- names = names .. name .. ", "
- end
- if count25 < 3 then
- if include_pet_names and not use_addon_msg then -- dont include when using addon channel, sorta redundant
- return strtrim(levels) .. " (" .. strtrim(names, " ,")
- else
- return strtrim(levels)
- end
- else
- return nil
- end
- end
- local f = CreateFrame("Frame")
- f:RegisterEvent("PET_BATTLE_QUEUE_PROPOSE_MATCH")
- for _,v in pairs(events_chat) do -- all the events we should need for chat
- f:RegisterEvent(v)
- end
- f:SetScript("OnEvent", function(self, event, ...)
- if not isok() then return end
- if event == "PET_BATTLE_QUEUE_PROPOSE_MATCH" then
- onceyoupop(true)
- elseif strfind(event, "CHAT_MSG_") then
- local msg, sender
- if event == "CHAT_MSG_ADDON" then
- local prefix
- prefix, msg, sender = ...
- if prefix ~= m_addon_prefix then
- return
- end
- else
- msg, sender = ...
- end
- if sender == UnitName('player') then return end
- msg = strtrim(msg)
- --
- if msg == m_pop then
- onceyoupop()
- elseif strmatch(msg, m_pets .. " .*") then
- if msg == m_pets .. " " .. m_no then
- enabled = false
- return
- end
- local levels = { strsplit(' ', strsub(msg, strlen(m_pets) + 2), 4) } -- creating table, prolly not a great idea
- for i = 1, 3 do
- local j = tonumber(levels[i])
- local petID, ability1ID, ability2ID, ability3ID, locked = C_PetJournal.GetPetLoadOutInfo(i)
- local speciesID, customName, level, xp, maxXp, displayID, isFavorite, name, icon, petType, creatureID, sourceText, description, isWild, canBattle, tradable, unique = C_PetJournal.GetPetInfoByPetID(petID)
- for diff = 0, 2 do -- try to put in a pet as close to the level as possible
- if abs(level - j) > diff then
- local _, count = C_PetJournal.GetNumPets(PetJournal.isWild)
- for n = 1, count do -- iterate all our pets
- local e_petID, e_speciesID, e_isOwned, e_customName, e_level, e_favorite, e_isRevoked, e_name, e_icon, e_petType, e_creatureID, e_sourceText, e_description, e_isWildPet, e_canBattle = C_PetJournal.GetPetInfoByIndex(n, PetJournal.isWild)
- if e_canBattle and e_petID ~= petID and abs(e_level - j) <= diff then
- C_PetJournal.SetPetLoadOutInfo(i, e_petID)
- return
- end
- end
- end
- end
- if abs(level - j) > 2 then
- dosend(m_pets .. " " .. m_no)
- enabled = false
- return
- end
- end
- -- all pets have checked out
- if GetTime() > nextupdate then
- popped_ok = false
- C_PetBattles.StartPVPMatchmaking()
- local pets = getpets()
- if pets then
- dosend(m_queue .. " " .. pets .. ")")
- end
- end
- elseif strmatch(msg, m_queue .. " .*") then
- popped_ok = false
- C_PetBattles.StartPVPMatchmaking()
- end
- end
- end)
- f:SetScript("OnUpdate", function(self, ...)
- if not enabled then return end
- if not PetJournal then PetJournal_LoadUI() end
- C_PetJournal.ClearSearchFilter()
- if C_PetBattles.IsInBattle() then
- decline_count = 0
- popped_ok = false
- nextupdate = GetTime() + 10
- z:Show()
- return
- else
- z:Hide()
- end
- if C_PetBattles.GetPVPMatchmakingInfo() then
- if popped_ok and GetTime() - popped > 2 then
- decline_count = decline_count + 1
- if max_decline_count > 0 and decline_count > max_decline_count then -- accept the pvp match just to get the person out of the queue, afk or manually abandon out
- C_PetBattles.AcceptQueuedPVPMatch()
- return
- end
- if C_PetBattles.GetPVPMatchmakingInfo() == "proposal" then
- C_PetBattles.DeclineQueuedPVPMatch()
- else
- C_PetBattles.StopPVPMatchmaking()
- end
- popped_ok = false
- end
- return
- end
- if not isok() then return end
- if leader and GetTime() > nextupdate then
- nextupdate = GetTime() + 2
- local pets = getpets()
- if pets then
- dosend(m_pets .. " " .. pets .. ")")
- end
- end
- end)
- _G["SLASH_" .. addon_name .. "1"] = '/' .. a_cmd;
- SlashCmdList[addon_name] = function(...)
- enabled = not enabled
- if enabled and use_addon_msg and not IsAddonMessagePrefixRegistered(m_addon_prefix) then
- if not RegisterAddonMessagePrefix(m_addon_prefix) then
- doprint("Error registering prefix: " .. m_addon_prefix)
- enabled = false
- end
- end
- local msg = ...
- leader = msg and strlen(msg) > 0
- doprint((enabled and "enabled" or "disabled") .. ", leader: " .. tostring(leader))
- end
Advertisement
Add Comment
Please, Sign In to add comment