Fandom

WoWWiki

USERAPI PLAYER MONEY

104,635pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

This page documents a user-defined function that you can copy and paste into your addon. Replace <PREFIX> with your AddOn's prefix to avoid conflicts between different versions of these functions.
User defined functions < PLAYER MONEY

Output when you gain or lose money and the amount to the chat frame.

Code Edit

local function FormatMoney(money)
    local ret = ""
    local gold = floor(money / (COPPER_PER_SILVER * SILVER_PER_GOLD));
    local silver = floor((money - (gold * COPPER_PER_SILVER * SILVER_PER_GOLD)) / COPPER_PER_SILVER);
    local copper = mod(money, COPPER_PER_SILVER);
    if gold > 0 then
        ret = gold .. " gold "
    end
    if silver > 0 or gold > 0 then
        ret = ret .. silver .. " silver "
    end
    ret = ret .. copper .. " copper"
    return ret
end

local frame = CreateFrame("Frame")
frame:RegisterEvent("PLAYER_MONEY")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:SetScript("OnEvent", function(self, event, ...)
    local tmpMoney = GetMoney()
    if self.CurrentMoney then
        self.DiffMoney = tmpMoney - self.CurrentMoney
    else
        self.DiffMoney = 0
    end
    self.CurrentMoney = tmpMoney
    if self.DiffMoney > 0 then
        ChatFrame1:AddMessage("You gained" .. FormatMoney(self.DiffMoney) .. ".")
    elseif self.DiffMoney < 0 then
        ChatFrame1:AddMessage("You lost" .. FormatMoney(self.DiffMoney * -1) .. ".")
    end
end)

Also on Fandom

Random Wiki