WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Need a little guidance... (https://www.wowinterface.com/forums/showthread.php?t=59859)

Sharpedge 04-24-24 07:05 PM

Need a little guidance...
 
The little snippet below works for the most part. The problem that I am having is that the Solo Shuffle Rating will only show if you are in a match. Once you leave the match is says "N/A". I know that it is using this C_PvP.GetPVPActiveMatchPersonalRatedInfo().....But I cannot for the life of me find anything that will actually show it outside of a match. Can anyone send me in the right direction on this?

Code:

local function UpdatePvPStatsFrame()
    local conquestInfo = C_CurrencyInfo.GetCurrencyInfo(Constants.CurrencyConsts.CONQUEST_CURRENCY_ID)
    local weeklyProgress = C_WeeklyRewards.GetConquestWeeklyProgress()
    local honorInfo = C_CurrencyInfo.GetCurrencyInfo(HONOR_CURRENCY_ID)
    local lifetimeHonorableKills, _ = GetPVPLifetimeStats()
    local honorLevel = UnitHonorLevel("player")
    local currentConquestPoints = conquestInfo.quantity
    local conquestCap = weeklyProgress.maxProgress or 1350

    if conquestCap == 1250 then
        conquestCap = 1350
    end
 
    local pvpRatingInfo = C_PvP.GetPVPActiveMatchPersonalRatedInfo()
    local soloShuffleRating = pvpRatingInfo and pvpRatingInfo.personalRating or "N/A"

    pvpStatsFrame.honorableKillsValue:SetText(lifetimeHonorableKills)
    pvpStatsFrame.conquestValue:SetText(currentConquestPoints)
    pvpStatsFrame.conquestCapValue:SetText(currentConquestPoints .. " / " .. conquestCap)
    pvpStatsFrame.honorValue:SetText(honorInfo.quantity)
    pvpStatsFrame.honorLevelValue:SetText(honorLevel)
    pvpStatsFrame.soloShuffleRatingValue:SetText(soloShuffleRating) 
end

pvpStatsFrame:RegisterEvent("CURRENCY_DISPLAY_UPDATE")
pvpStatsFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
pvpStatsFrame:RegisterEvent("WEEKLY_REWARDS_UPDATE")
pvpStatsFrame:RegisterEvent("PVP_RATED_STATS_UPDATE")
pvpStatsFrame:SetScript("OnEvent", UpdatePvPStatsFrame)
pvpStatsFrame:SetScript("OnShow", UpdatePvPStatsFrame)


Xrystal 04-24-24 07:58 PM

This might be what you are looking for while not in an active match

https://warcraft.wiki.gg/wiki/API_GetPersonalRatedInfo

Sharpedge 04-24-24 08:03 PM

Thanks man, I'll take a peek at it.

Sharpedge 04-25-24 11:50 AM

Welp, it is kinda working lol. I did use the GetPersonalRatedInfo. See the code below:

Code:

local CONQUEST_CURRENCY_ID = 1602
local HONOR_CURRENCY_ID = 1792

-- Main GUI Frame
local IncCallout = CreateFrame("Frame", "IncCalloutMainFrame", UIParent, "BackdropTemplate")
IncCallout:SetSize(225, 240) 
IncCallout:SetPoint("CENTER")
IncCallout:SetMovable(true)
IncCallout:EnableMouse(true)
IncCallout:RegisterForDrag("LeftButton")
IncCallout:SetScript("OnDragStart", IncCallout.StartMoving)
IncCallout:SetScript("OnDragStop", IncCallout.StopMovingOrSizing)

local closeButton = CreateFrame("Button", nil, IncCallout, "UIPanelCloseButton")
closeButton:SetPoint("TOPRIGHT", IncCallout, "TOPRIGHT", -5, -5)
closeButton:SetSize(24, 24) 
closeButton:SetScript("OnClick", function()
    IncCallout:Hide() 
end)

closeButton:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
    GameTooltip:SetText("Close the Window", nil, nil, nil, nil, true)
    GameTooltip:Show()
end)
closeButton:SetScript("OnLeave", function()
    GameTooltip:Hide()
end)

-- Create the PVP Stats window frame
local pvpStatsFrame = CreateFrame("Frame", "PVPStatsFrame", UIParent, "BasicFrameTemplateWithInset")
pvpStatsFrame:SetSize(220, 200)
pvpStatsFrame:SetPoint("CENTER")
pvpStatsFrame:SetMovable(true)
pvpStatsFrame:EnableMouse(true)
pvpStatsFrame:RegisterForDrag("LeftButton")
pvpStatsFrame:SetScript("OnDragStart", pvpStatsFrame.StartMoving)
pvpStatsFrame:SetScript("OnDragStop", pvpStatsFrame.StopMovingOrSizing)
pvpStatsFrame:Hide()

pvpStatsFrame.title = pvpStatsFrame:CreateFontString(nil, "OVERLAY")
pvpStatsFrame.title:SetFontObject("GameFontHighlight")
pvpStatsFrame.title:SetPoint("TOP", pvpStatsFrame, "TOP", 0, -7)
pvpStatsFrame.title:SetText("PVP Stats")

local LEFT_MARGIN = -70
local VERTICAL_GAP = -15

local function createStatLabelAndValue(parent, labelText, previousElement, yOffset, textColor)
    local label = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    label:SetPoint("TOPLEFT", previousElement, "BOTTOMLEFT", previousElement == parent.title and LEFT_MARGIN or 0, yOffset)
    label:SetText(labelText)
    label:SetTextColor(unpack(textColor))
   
    local value = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    value:SetPoint("LEFT", label, "RIGHT", 5, 0)
    value:SetTextColor(1, 0.84, 0)
    return label, value
end

-- Creating labels and values with custom colors for each category
pvpStatsFrame.honorableKillsLabel, pvpStatsFrame.honorableKillsValue = createStatLabelAndValue(pvpStatsFrame, "Lifetime Honorable Kills:", pvpStatsFrame.title, VERTICAL_GAP, {0, 1, 0})  -- Green
pvpStatsFrame.conquestLabel, pvpStatsFrame.conquestValue = createStatLabelAndValue(pvpStatsFrame, "Conquest Points:", pvpStatsFrame.honorableKillsLabel, VERTICAL_GAP, {0, 0.75, 1})  -- Light blue
pvpStatsFrame.honorLabel, pvpStatsFrame.honorValue = createStatLabelAndValue(pvpStatsFrame, "Honor Points:", pvpStatsFrame.conquestLabel, VERTICAL_GAP, {1, 0.5, 0})  -- Orange
pvpStatsFrame.honorLevelLabel, pvpStatsFrame.honorLevelValue = createStatLabelAndValue(pvpStatsFrame, "Honor Level:", pvpStatsFrame.honorLabel, VERTICAL_GAP, {0.58, 0, 0.82})  -- Purple
pvpStatsFrame.conquestCapLabel, pvpStatsFrame.conquestCapValue = createStatLabelAndValue(pvpStatsFrame, "Conquest Cap:", pvpStatsFrame.honorLevelLabel, VERTICAL_GAP, {1, 0, 0})  -- Red
pvpStatsFrame.soloShuffleRatingLabel, pvpStatsFrame.soloShuffleRatingValue = createStatLabelAndValue(pvpStatsFrame, "Solo Shuffle Rating:", pvpStatsFrame.conquestCapLabel, VERTICAL_GAP, {1, 0.84, 0})  -- Gold color for value)

local SOLO_SHUFFLE_INDEX = 7 

local lastPlayerName = nil 

local function RefreshPvPStats()
    local conquestInfo = C_CurrencyInfo.GetCurrencyInfo(Constants.CurrencyConsts.CONQUEST_CURRENCY_ID)
    local weeklyProgress = C_WeeklyRewards.GetConquestWeeklyProgress()
    local honorInfo = C_CurrencyInfo.GetCurrencyInfo(HONOR_CURRENCY_ID)
    local lifetimeHonorableKills, _ = GetPVPLifetimeStats()
    local honorLevel = UnitHonorLevel("player")
    local currentConquestPoints = conquestInfo.quantity
    local conquestCap = weeklyProgress.maxProgress or 1350

    if conquestCap == 1250 then
        conquestCap = 1350
    end

    local rating = GetPersonalRatedInfo(SOLO_SHUFFLE_INDEX)
    local soloShuffleRating = rating or "N/A"

    pvpStatsFrame.honorableKillsValue:SetText(lifetimeHonorableKills)
    pvpStatsFrame.conquestValue:SetText(currentConquestPoints)
    pvpStatsFrame.conquestCapValue:SetText(currentConquestPoints .. " / " .. conquestCap)
    pvpStatsFrame.honorValue:SetText(honorInfo.quantity)
    pvpStatsFrame.honorLevelValue:SetText(honorLevel)
    pvpStatsFrame.soloShuffleRatingValue:SetText(soloShuffleRating)
end

pvpStatsFrame:RegisterEvent("PVP_RATED_STATS_UPDATE")
pvpStatsFrame:SetScript("OnEvent", function(self, event)
    if event == "PVP_RATED_STATS_UPDATE" then
        RefreshPvPStats()
    end
end)

pvpStatsFrame:RegisterEvent("PLAYER_LOGIN")
pvpStatsFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
pvpStatsFrame:RegisterEvent("CURRENCY_DISPLAY_UPDATE")
pvpStatsFrame:RegisterEvent("WEEKLY_REWARDS_UPDATE")
pvpStatsFrame:SetScript("OnEvent", UpdatePvPStatsFrame)
pvpStatsFrame:SetScript("OnShow", RefreshPvPStats)  ]

So here is where I think I messed up or left out something. I can log in, click on the PVP Stat button on my GUI and it shows the Solo Shuffle Rating as 0. So then I go to Group Finder/Player vs Player, and leave that open. I then open the PVP Stat window again and it shows the correct rating. If I log out, and then into another toon it's the same senario.

I have just shown this part of my code. If needed I can post the entire thing. The changes are not on my Github. And it's like 1500 lines.I just think I'm missing something for it to have this type of behaviour.

Xrystal 04-25-24 01:34 PM

So it works as expected after opening the PvP related Blizzard frame ?

If that is the case, then sounds like there is a Blizzard addon that needs to be set as required in the toc file.

One that springs to mind is Blizzard_PVPUI. Give that a whirl and see if doing your stuff after that addon is loaded improves things.

Sharpedge 04-25-24 02:46 PM

That didn't help. So back to the drawing board lol. It is probably something real simple too lol.

EDIT: I ran this when I first logged in and it shows the rating at 0. But just as soon as I went Group Finder/Player vs Player and did a /reload it showed the right rating. So something is going on here. Also whenever I switch to another toon it will show the previous toons rating.

Code:

local function TestPvPIndices()
    for i = 1, 10 do 
        local rating, seasonBest, weeklyBest, seasonPlayed, seasonWon, weeklyPlayed, weeklyWon, cap = GetPersonalRatedInfo(i)
        if rating then
            print("Index " .. i .. ":")
            print("  Current Rating: " .. rating)
            print("  Season Best: " .. seasonBest)
            print("  Weekly Best: " .. weeklyBest)
            print("  Season Played: " .. seasonPlayed)
            print("  Season Won: " .. seasonWon)
            print("  Weekly Played: " .. weeklyPlayed)
            print("  Weekly Won: " .. weeklyWon)
            print("  Cap: " .. cap)
        else
            print("Index " .. i .. ": No data available")
        end
    end
end

TestPvPIndices()


Xrystal 04-25-24 08:24 PM

Aha ..

Looking through the PVPUI code and I noticed they had these functions that don't appear ones created in the file.

RequestRatedInfo - https://warcraft.wiki.gg/wiki/API_RequestRatedInfo
RequestPVPOptionsEnabled - No Page on Wiki Yet.
Possible Event: "PVP_TYPES_ENABLED"
RequestPVPRewards - No Page on Wiki Yet
Possible Event: "PVP_REWARDS_UPDATE"
RequestRandomBattlegroundInstanceInfo - https://warcraft.wiki.gg/wiki/API_Re...ndInstanceInfo

I would have thought they would have successfully got the information for you when the ConquestFrame was loaded up when the addon was activated. But maybe it is when the frame is shown that the work happens.

Here's the file in question
https://github.com/Gethe/wow-ui-sour...VPUI.lua#L1192

Hopefully some of that helps you, if you haven't figured it out yet.

Sharpedge 04-25-24 08:56 PM

Naw, I haven't figured it out just yet. But I do think it's a issue for sure. I installed another addon that shows rating and was basically doing the same thing as mine. My little PvP Stat window is just an extension of my addon Incoming-BG. All of the other pvp stats update in real-time, but of course not Solo Shuffle.

If I do figure it out I will post what I find.

Fizzlemizz 04-25-24 10:06 PM

The Blizzard_PVPUI is marked as LOD. Have you tried checking it is actually loaded after you've clicked the stat button and, if not then loading it, before the button does anything else (or before you stat. window loads)?

After loading the PVP UI Blizz. does
Code:

C_Timer.After(1, function() TopBannerManager_Show(PvPObjectiveBannerFrame, { name=bannerName, description=bannerDescription }); end);
Which would indicate you might need a similar timer in order to get the required information from the server into the cache.

Sharpedge 04-26-24 10:23 AM

This is what I have done:

Code:

local function UpdatePvPStatsFrame()
    if not IsAddOnLoaded("Blizzard_PVPUI") then
        LoadAddOn("Blizzard_PVPUI")
    end

    C_Timer.After(2, function()  -- Delay for 2 seconds to ensure the AddOn is fully loaded and ready
        local conquestInfo = C_CurrencyInfo.GetCurrencyInfo(Constants.CurrencyConsts.CONQUEST_CURRENCY_ID)
        local weeklyProgress = C_WeeklyRewards.GetConquestWeeklyProgress()
        local honorInfo = C_CurrencyInfo.GetCurrencyInfo(HONOR_CURRENCY_ID)
        local lifetimeHonorableKills, _ = GetPVPLifetimeStats()
        local honorLevel = UnitHonorLevel("player")
        local currentConquestPoints = conquestInfo.quantity
        local conquestCap = weeklyProgress.maxProgress or 1350

        if conquestCap == 1250 then
            conquestCap = 1350
        end

        local rating = GetPersonalRatedInfo(SOLO_SHUFFLE_INDEX)
        local soloShuffleRating = rating or "N/A"

        pvpStatsFrame.honorableKillsValue:SetText(lifetimeHonorableKills)
        pvpStatsFrame.conquestValue:SetText(currentConquestPoints)
        pvpStatsFrame.conquestCapValue:SetText(currentConquestPoints .. " / " .. conquestCap)
        pvpStatsFrame.honorValue:SetText(honorInfo.quantity)
        pvpStatsFrame.honorLevelValue:SetText(honorLevel)
        pvpStatsFrame.soloShuffleRatingValue:SetText(soloShuffleRating) 
    end)
end

pvpStatsFrame:RegisterEvent("CURRENCY_DISPLAY_UPDATE")
pvpStatsFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
pvpStatsFrame:RegisterEvent("WEEKLY_REWARDS_UPDATE")
pvpStatsFrame:SetScript("OnEvent", UpdatePvPStatsFrame)
pvpStatsFrame:SetScript("OnShow", UpdatePvPStatsFrame)

With that it does fix the issue of showing the correct rating. BUT, if you go Group Finder/Player vs Player the "Rated" and "PreMade Group" is still grayed out and cannot be clicked. The only way to resolve that is with a /reload, and everything works just fine.

Fizzlemizz 04-26-24 12:25 PM

Stealing from Blizz. code, add this to your timer before the other code:
Lua Code:
  1. local canUseRated = C_PvP.CanPlayerUseRatedPVPUI();
  2. local canUsePremade = C_LFGInfo.CanPlayerUsePremadeGroup();
  3. if canUseRated then
  4.     PVPQueueFrame_SetCategoryButtonState(PVPQueueFrame.CategoryButton2, true);
  5.     PVPQueueFrame.CategoryButton2.tooltip = nil;
  6. end
  7. if canUsePremade then
  8.     PVPQueueFrame.CategoryButton3.tooltip = nil;
  9.     PVPQueueFrame_SetCategoryButtonState(PVPQueueFrame.CategoryButton3, true);
  10. end

Sharpedge 04-26-24 12:47 PM

Quote:

Originally Posted by Fizzlemizz (Post 343796)
Stealing from Blizz. code, add this to your timer before the other code:
Lua Code:
  1. local canUseRated = C_PvP.CanPlayerUseRatedPVPUI();
  2. local canUsePremade = C_LFGInfo.CanPlayerUsePremadeGroup();
  3. if canUseRated then
  4.     PVPQueueFrame_SetCategoryButtonState(PVPQueueFrame.CategoryButton2, true);
  5.     PVPQueueFrame.CategoryButton2.tooltip = nil;
  6. end
  7. if canUsePremade then
  8.     PVPQueueFrame.CategoryButton3.tooltip = nil;
  9.     PVPQueueFrame_SetCategoryButtonState(PVPQueueFrame.CategoryButton3, true);
  10. end

You are a freakin' genius. Thank you for the fix. I don't think I would of ever found that. I really appreciate it.


All times are GMT -6. The time now is 06:09 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI