Advertisement
Kagalive

Untitled

Aug 28th, 2023
1,125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.80 KB | None | 0 0
  1. local frame = CreateFrame("Frame", "PlayerGoldFrame", UIParent)
  2. frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  3. frame:SetSize(250, 75)
  4. frame:EnableMouse(true)
  5. frame:SetMovable(true)
  6. frame:RegisterForDrag("LeftButton")
  7. frame:Show()
  8.  
  9. frame.bgTexture = frame:CreateTexture(nil, "BACKGROUND")
  10. frame.bgTexture:SetAllPoints(frame)
  11. frame.bgTexture:SetColorTexture(0, 0, 0, 0.5)
  12.  
  13. local totalGoldLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  14. totalGoldLabel:SetPoint("TOP", frame, "TOP", 0, -10)
  15. totalGoldLabel:SetText("Total Gold:")
  16.  
  17. local goldGainedLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  18. goldGainedLabel:SetPoint("CENTER", frame, "CENTER", 0, 0)
  19. goldGainedLabel:SetText("Gold Gained:")
  20.  
  21. local goldSpentLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  22. goldSpentLabel:SetPoint("BOTTOM", frame, "BOTTOM", 0, 10)
  23. goldSpentLabel:SetText("Gold Spent:")
  24.  
  25. local prevGold = GetMoney()
  26.  
  27. local addonName = "PlayerGoldAddon"
  28. local addonData = {}
  29.  
  30. local function UpdateGold()
  31.     local playerGold = GetMoney()
  32.     local goldDiff = playerGold - prevGold
  33.  
  34.     totalGoldLabel:SetText("Total Gold: " .. GetCoinTextureString(playerGold))
  35.    
  36.     if goldDiff > 0 then
  37.         addonData.goldGained = (addonData.goldGained or 0) + goldDiff
  38.         goldGainedLabel:SetText("Gold Gained: " .. GetCoinTextureString(addonData.goldGained))
  39.         goldSpentLabel:SetText("Gold Spent: " .. GetCoinTextureString(addonData.goldSpent or 0))
  40.     elseif goldDiff < 0 then
  41.         addonData.goldSpent = (addonData.goldSpent or 0) - goldDiff
  42.         goldGainedLabel:SetText("Gold Gained: " .. GetCoinTextureString(addonData.goldGained or 0))
  43.         goldSpentLabel:SetText("Gold Spent: " .. GetCoinTextureString(addonData.goldSpent))
  44.     else
  45.         goldGainedLabel:SetText("Gold Gained: " .. GetCoinTextureString(addonData.goldGained or 0))
  46.         goldSpentLabel:SetText("Gold Spent: " .. GetCoinTextureString(addonData.goldSpent))
  47.     end
  48.  
  49.     prevGold = playerGold
  50. end
  51.  
  52. local function UpdateAddonData()
  53.     if not addonData.goldGained then
  54.         addonData.goldGained = 0
  55.     end
  56.     if not addonData.goldSpent then
  57.         addonData.goldSpent = 0
  58.     end
  59. end
  60.  
  61. frame:RegisterEvent("PLAYER_MONEY")
  62. frame:SetScript("OnEvent", function()
  63.     UpdateGold()
  64.     UpdateAddonData()
  65. end)
  66. UpdateGold()
  67. UpdateAddonData()
  68.  
  69. frame:SetScript("OnDragStart", function(self)
  70.     self:StartMoving()
  71. end)
  72. frame:SetScript("OnDragStop", function(self)
  73.     self:StopMovingOrSizing()
  74. end)
  75.  
  76. SLASH_PLAYERGOLD1 = "/playergold"
  77. SlashCmdList["PLAYERGOLD"] = function()
  78.     frame:SetShown(not frame:IsShown())
  79. end
  80.  
  81. local addonFrame = CreateFrame("Frame")
  82. addonFrame:RegisterEvent("PLAYER_LOGOUT")
  83. addonFrame:SetScript("OnEvent", function()
  84.     SaveVariables(addonName, addonData)
  85. end)
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement