Wikia

WoWWiki

USERAPI PLAYER MONEY

Redirected from USEREVENT PLAYER MONEY

104,288pages on
this wiki
Talk0
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)

Around Wikia's network

Random Wiki