WoW:USERAPI PLAYER MONEY
Jump to navigation
Jump to search
This page documents a <i>user-defined function</i> that you can copy and paste into your addon. Replace PREFIX with your addon or lib prefix to avoid conflicts between different versions of these functions.
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)