06-18-11, 06:28 AM | #1 |
Some help with code for Arena Points
Im having a bit trouble figuring out how to get this to work correctly.
The problem is that it doesn't update correctly. A normal /rl fix it. Tryed different OnEvent, without luck. Also, does anyone know a good way to handle the if not in the different arena team sizes? Here is the code, it's kinda bit's from random sources. Code:
if Viks["datatext"].Arena and Viks["datatext"].Arena > 0 then local Stat = CreateFrame("Frame") Stat:EnableMouse(true) Stat:SetFrameStrata("BACKGROUND") Stat:SetFrameLevel(3) local Text = LBottom:CreateFontString(nil, "OVERLAY") --Set font based on where. if Viks["datatext"].Arena >= 9 then Text:SetTextColor(unpack(Viks["media"].pxcolor1)) Text:SetFont(Viks["media"].pxfontHeader, Viks["media"].pxfontHsize, Viks["media"].pxfontHFlag) else Text:SetTextColor(unpack(Viks["media"].pxcolor1)) Text:SetFont(Viks["media"].pxfont, Viks["media"].pxfontsize, Viks["media"].pxfontFlag) end PP(Viks["datatext"].Arena, Text) dispConquestPoints = false local conquestPoints = 0 local ArenaTeams={} local MaxPoints = 0 local PotentialCap = 0 local stringItem = "" local capFromTeam = "" Stat:SetScript("OnMouseDown", function() if InCombatLockdown() then return end if IsShiftKeyDown() then TogglePVPFrame() PVPFrameTab1:Click() else TogglePVPFrame() PVPFrameTab2:Click() end end) DataTextTooltipAnchor = function(self) local panel = self:GetParent() local anchor = "ANCHOR_CURSOR" local xoff = 0 local yoff = 20 return anchor, panel, xoff, yoff end local function CalculatePoints(rating) local rating = tonumber(rating) local cap = nil if rating then if rating >= 3000 then cap = 3000 elseif rating < 3000 and rating > 1500 then cap = math.floor(1.4326 * (1511.26 / (1 + 1639.28 / exp(0.00412 * rating))) + 850.15) else cap = 1343 end else cap = 0 end return cap end local function OnEvent(self, event, ...) local conquestLocalized, conquestPoints = GetCurrencyInfo(390) local personalBGRating, ratedBGreward, pointsThisWeek, maxPointsThisWeek, weeklyWins, weeklyPlayed = GetPersonalRatedBGInfo(); MaxPoints=0 for i =1,3 do local teamName, teamSize, teamRating, weekPlayed, weekWins, seasonPlayed, seasonWins, playerPlayed, seasonPlayerPlayed, teamRank, playerRating = GetArenaTeam(i) if(teamName~=nil) then ArenaTeams[i] = {} ArenaTeams[i]["Size"] = teamSize ArenaTeams[i]["Name"] = teamName ArenaTeams[i]["Rating"] = teamRating PotentialCap = CalculatePoints(teamRating) ArenaTeams[i]["Points"] = PotentialCap if(PotentialCap>MaxPoints) and pointsThisWeek > 0 and playerPlayed > 0 then MaxPoints = PotentialCap capFromTeam = ArenaTeams[i]["Size"].."v"..ArenaTeams[i]["Size"] else MaxPoints = 0 end end end -- Checks for Rated BG potential Cap if MaxPoints == 0 and pointsThisWeek > 0 then MaxPoints = CalculatePoints(personalBGRating) capFromTeam = "Rated BG" else MaxPoints = 1343 capFromTeam = "No games played" end if dispConquestPoints then stringItem = conquestPoints else stringItem = MaxPoints end -- All values have been picked up, let's start displaying it. -- Showing the text local dummy = CreateFrame("FRAME", "FooAddonFrame"); dummy:RegisterEvent("PLAYER_ENTERING_WORLD"); local function eventHandler(self, event, ...) for i = 1,3 do if(ArenaTeams[i]~=nil) then Text:SetText("|cff0063C7"..ArenaTeams[1]["Size"].."v"..ArenaTeams[1]["Size"]..": ".."|r".."|cffFFFFFF"..ArenaTeams[1]["Rating"].."|r".." ".."|cff0063C7"..ArenaTeams[2]["Size"].."v"..ArenaTeams[2]["Size"]..": ".."|r".."|cffFFFFFF"..ArenaTeams[2]["Rating"].."|r") dummy:Show() end end end dummy:SetScript("OnEvent", eventHandler); -- Adding the tooltip Text:SetText("No Arena") Stat:SetAllPoints(Text) Stat:SetScript("OnEnter", function() local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text) GameTooltip:SetOwner(panel, anchor, xoff, yoff) GameTooltip:ClearLines() if not InCombatLockdown() then GameTooltip:AddLine("|cffffff00".."Arena Teams".."|r") GameTooltip:AddLine("-------------------------", 1, 1, 1) for i = 1,3 do if(ArenaTeams[i]~=nil) then GameTooltip:AddDoubleLine("["..ArenaTeams[i]["Size"].."v"..ArenaTeams[i]["Size"].."] <"..ArenaTeams[i]["Name"]..">", "("..ArenaTeams[i]["Rating"]..") ["..ArenaTeams[i]["Points"].."]", 1, 1, 1, 1, 1, 1) Text:SetText("|cff0063C7"..ArenaTeams[1]["Size"].."v"..ArenaTeams[1]["Size"]..": ".."|r".."|cffFFFFFF"..ArenaTeams[1]["Rating"].."|r".." ".."|cff0063C7"..ArenaTeams[2]["Size"].."v"..ArenaTeams[2]["Size"]..": ".."|r".."|cffFFFFFF"..ArenaTeams[2]["Rating"].."|r") end end GameTooltip:AddLine(" ") GameTooltip:AddLine("|cffffff00"..PVP_RATED_BATTLEGROUND.."|r") if personalBGRating > 0 then GameTooltip:AddLine("-------------------------", 1, 1, 1) GameTooltip:AddDoubleLine("Personal Rating", "("..personalBGRating..") ["..CalculatePoints(personalBGRating).."]", 1, 1, 1, 1, 1, 1) end GameTooltip:AddLine(" ") GameTooltip:AddLine("|cffffff00"..conquestLocalized.."|r") GameTooltip:AddLine("-------------------------", 1, 1, 1) GameTooltip:AddDoubleLine("Current", pointsThisWeek.."/"..maxPointsThisWeek, 1, 1, 1, 1, 1, 1) GameTooltip:AddLine(" ") if db.dispConquestPoints then GameTooltip:AddDoubleLine("Next week's cap is from '"..capFromTeam.."'.", MaxPoints, 1, 1, 1, 1, 1, 1) else GameTooltip:AddDoubleLine(conquestLocalized, conquestPoints, 1, 1, 1, 1, 1, 1) end GameTooltip:AddLine("-------------------------", 1, 1, 1) GameTooltip:AddLine("|cffffff00".."Click to toggle Conquest/Signup") GameTooltip:AddLine("|cffffff00".."Shift-Click to toggle PVP Frame") end GameTooltip:Show() end) Stat:SetScript("OnLeave", function() GameTooltip:Hide() end) end Stat:RegisterEvent("PLAYER_ENTERING_WORLD") Stat:RegisterEvent("PLAYER_LOGIN") Stat:RegisterEvent("ARENA_TEAM_UPDATE") Stat:SetScript("OnEvent", OnEvent) end Code:
if not Viks["datatext"].Talents or Viks["datatext"].Talents == 0 then return end DataTextTooltipAnchor = function(self) local panel = self:GetParent() local anchor = "ANCHOR_CURSOR" local xoff = 0 local yoff = 20 return anchor, panel, xoff, yoff end local ADDON_NAME, ns = ... local oUF = ns.oUF or oUF ns._Objects = {} ns._Headers = {} local Stat = CreateFrame("Frame") Stat:SetFrameStrata("BACKGROUND") Stat:SetFrameLevel(3) Stat:EnableMouse(true) local Text = LBottom:CreateFontString(nil, "OVERLAY") if Viks["datatext"].Talents >= 9 then Text:SetTextColor(unpack(Viks["media"].pxcolor1)) Text:SetFont(Viks["media"].pxfontHeader, Viks["media"].pxfontHsize, Viks["media"].pxfontHFlag) else Text:SetTextColor(unpack(Viks["media"].pxcolor1)) Text:SetFont(Viks["media"].pxfont, Viks["media"].pxfontsize, Viks["media"].pxfontFlag) end PP(Viks["datatext"].Talents, Text) local function HasDualSpec() if GetNumTalentGroups() > 1 then return true end end local function OnEvent(self) if not GetPrimaryTalentTree() then Text:SetText("No talents") return end local tree1 = select(5,GetTalentTabInfo(1)) local tree2 = select(5,GetTalentTabInfo(2)) local tree3 = select(5,GetTalentTabInfo(3)) local primaryTree = GetPrimaryTalentTree() Text:SetText("|cffFFFFFF"..tree1.."|r".."/".."|cffFFFFFF"..tree2.."|r".."/".."|cffFFFFFF"..tree3.."|r") self:SetAllPoints(Text) end Stat:RegisterEvent("PLAYER_ENTERING_WORLD") Stat:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED") Stat:SetScript("OnEvent", OnEvent) Stat:SetScript("OnMouseDown", function() if InCombatLockdown() then return end if IsShiftKeyDown() then if not HasDualSpec() then return end SetActiveTalentGroup(GetActiveTalentGroup() == 1 and 2 or 1) else if not IsAddOnLoaded("Blizzard_TalentUI") then LoadAddOn("Blizzard_TalentUI") end ToggleFrame(PlayerTalentFrame) end end) Stat:SetScript("OnEnter", function() if InCombatLockdown() then return end local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text) GameTooltip:SetOwner(panel, anchor, xoff, yoff) GameTooltip:ClearLines() local primary = GetPrimaryTalentTree(false,false,GetActiveTalentGroup()) local primaryone = select(5,GetTalentTabInfo(1)) local primarytwo = select(5,GetTalentTabInfo(2)) local primarythree = select(5,GetTalentTabInfo(3)) GameTooltip:AddLine("Current Spec: "..select(2,GetTalentTabInfo(primary)).." - "..primaryone.."/"..primarytwo.."/"..primarythree) if HasDualSpec() then local secondary = GetActiveTalentGroup() == 1 and 2 or 1 local secondaryone = select(5,GetTalentTabInfo(1,false,false, secondary)) local secondarytwo = select(5,GetTalentTabInfo(2,false,false, secondary)) local secondarythree = select(5,GetTalentTabInfo(3,false,false, secondary)) GameTooltip:AddLine("Shift click to swap to "..select(2,GetTalentTabInfo(GetPrimaryTalentTree(false,false,(secondary)))).." - "..secondaryone.."/"..secondarytwo.."/"..secondarythree) end GameTooltip:Show() end) Stat:SetScript("OnLeave", function() GameTooltip:Hide() end) |
|
06-23-11, 12:23 PM | #2 |
Solved the problems with tallents, but still totaly stuck on the arena part.
It's just basicly gona show arena size and there points. When i move mouse over the text get's updated correctly. Im sure the code is messy and show plenty of bad ways todo stuff. But learning as i go. |
|
WoWInterface » Developer Discussions » Lua/XML Help » Some help with code for Arena Points |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|