Code:
local PetBattleFix = CreateFrame("Frame")
_G.PetBattleFix = PetBattleFix
local REVIVE_SPELL = 125439
local REVIVE_ITEM = 86143
function PetBattleFix.init()
if PetBattleFix.hadInit then return end
if InCombatLockdown() then print("Error! PetBattleFix.init() called in combat lockdown. This should never happen.") return end
local spellName,_, spellIcon = GetSpellInfo(REVIVE_SPELL)
local itemName,_,_,_,_,_,_,_,_, itemIcon = GetItemInfo(REVIVE_ITEM)
if not (spellName and spellIcon and itemName and itemIcon) then
print("One of the following informations is not present for some reason. Aborting:")
print("spellName: "..spellName)
print("spellIcon: "..spellIcon)
print("itemName: "..itemName)
print("itemIcon: "..itemIcon)
return
end
local postClick = function(self) self:Hide() C_PetBattles.StartPVPMatchmaking() end
PetBattleFix.Knopf1 = CreateFrame("BUTTON", nil, UIParent, "SecureActionButtonTemplate")
PetBattleFix.Knopf1:SetPoint("CENTER", UIParent, "CENTER")
PetBattleFix.Knopf1:SetSize(40,40)
PetBattleFix.Knopf1:SetAttribute("unit", "player")
PetBattleFix.Knopf1:SetAttribute("type", "spell")
PetBattleFix.Knopf1:SetAttribute("name",spellName)
PetBattleFix.Knopf1.Icon = PetBattleFix.Knopf1:CreateTexture("Icon","ARTWORK")
PetBattleFix.Knopf1.Icon:SetTexture(spellIcon)
PetBattleFix.Knopf1.Icon:SetAllPoints()
PetBattleFix.Knopf1.Border = PetBattleFix.Knopf1:CreateTexture("Border","OVERLAY","ActionBarFlyoutButton-IconFrame")
PetBattleFix.Knopf1:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress")
PetBattleFix.Knopf1:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square","ADD")
PetBattleFix.Knopf1:SetScript("PostClick", postClick)
PetBattleFix.Knopf1:Hide()
PetBattleFix.Knopf2 = CreateFrame("BUTTON", nil, PetBattleFix, "SecureActionButtonTemplate")
PetBattleFix.Knopf2:SetPoint("CENTER", UIParent, "CENTER")
PetBattleFix.Knopf2:SetSize(40,40)
PetBattleFix.Knopf2:SetAttribute("unit", "player")
PetBattleFix.Knopf2:SetAttribute("type", "item")
PetBattleFix.Knopf2:SetAttribute("name", itemName)
PetBattleFix.Knopf2.Icon = PetBattleFix.Knopf2:CreateTexture("Icon","ARTWORK")
PetBattleFix.Knopf2.Icon:SetTexture(itemIcon)
PetBattleFix.Knopf2.Icon:SetAllPoints()
PetBattleFix.Knopf2.Border = PetBattleFix.Knopf2:CreateTexture("Border","OVERLAY","ActionBarFlyoutButton-IconFrame")
PetBattleFix.Knopf2:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress")
PetBattleFix.Knopf2:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square","ADD")
PetBattleFix.Knopf2:SetScript("PostClick", postClick)
PetBattleFix.Knopf2:Hide()
PetBattleFix.hadInit = true
end
PetBattleFix:SetScript("OnEvent",function(self,event,msg)
--[[if msg ~= (ERR_PETBATTLE_QUEUE_ALREADY_QUEUED) then
print('|cffff0000'..msg..'|r')
end--]]
if msg:match(ERR_PETBATTLE_QUEUE_QUEUED) then
local team = ""
for loop=1, 3 do
local petID, _, _, _, _ = C_PetJournal.GetPetLoadOutInfo(loop)
local _, _, _, _, _, _, _, _, petIcon, _, _, _, _, _, _, _, _ = C_PetJournal.GetPetInfoByPetID(petID)
local link = C_PetJournal.GetBattlePetLink(petID)
team = team .. "|T" .. petIcon .. ":12:12|t" .. link .. ' '
end
print('with team '..team)
elseif msg:match(ERR_PETBATTLE_QUEUE_SLOT_EMPTY) then
-- make it stick open when even number of pets are missing
TogglePetJournal(2)
elseif msg:match(ERR_PETBATTLE_QUEUE_OPPONENT_DECLINED) or msg:match(ERR_PETBATTLE_QUEUE_PROPOSAL_DECLINED) then
print('You have been requeued!')
C_PetBattles.StartPVPMatchmaking()
elseif msg:match(ERR_PETBATTLE_QUEUE_SLOT_DEAD) then
if InCombatLockdown() then
print("You'd have to revive pet(s), but you are in combat so we can't give you any neat buttons, sadly ;(")
return
end
if not PetBattleFix.hadInit then PetBattleFix.init() end
local start, duration, enable = GetSpellCooldown(REVIVE_SPELL)
local itemCount = GetItemCount(REVIVE_ITEM)
if start == 0 then
PetBattleFix.Knopf1:Show()
PetBattleFix.Knopf2:Hide()
elseif itemCount > 0 then
PetBattleFix.Knopf1:Hide()
PetBattleFix.Knopf2:Show()
else
PetBattleFix.Knopf1:Hide()
PetBattleFix.Knopf2:Hide()
print(("You'd have to revive pet(s), but you don't have any %s in your inventory and %s is on cooldown."):format((select(2,GetItemInfo(REVIVE_ITEM))),GetSpellLink(REVIVE_SPELL))
end
else
return end
end
end)
PetBattleFix:RegisterEvent('UI_ERROR_MESSAGE')
print('PetBattleFix for nuubs loaded!')