Thread Tools Display Modes
12-28-10, 07:29 AM   #1
Quokka
A Chromatic Dragonspawn
 
Quokka's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2005
Posts: 196
Gold

We have a problem and just can't find out why it's not working

It will always show the Char. Total amount as Earned.
But Earned should be 0 if logging in or /rl.

Can anyone help us?

Thanks

Code:
local cColor = SVConfig["classy"][SVRoot.myclass]
local cr,cg,cb = cColor[1], cColor[2], cColor[3]
local ir,ig,ib = (1-(cr*0.8)),(1-(cg*0.8)),(1-(cb*0.8))
local names
if SVRoot.L == "ruRU" then
	names = {
	["free"] = "Свободно:",
	["gold"] = "Всего денег:"}
else
	names = {
	["free"] = "Bags Used/Total:",
	["gold"] = "Total money:"}
end

local bag = CreateFrame ("StatusBar","svUIBags",UIParent)
	bag:SetWidth(110)
	bag:SetHeight(12)
	bag:EnableMouse(true)
	
local loltex = bag:CreateTexture (nil,"OVERLAY")
	loltex:SetTexture (SVParts.media.colorbar)
	loltex:SetGradient("HORIZONTAL",cr*0.5,cg*0.5,cb*0.5,cr,cg,cb)
	bag:SetStatusBarTexture(loltex)
	
local bagbg = SVMod.SuperPanel(bag,0,0,0,0)
	bagbg:SetPoint("TOPLEFT",-4,4)
	bagbg:SetPoint("BOTTOMRIGHT",4,-4)
	bagbg.bg2:SetGradient("HORIZONTAL",ir*0.5,ig*0.3,ib*0.3,ir*0.9,ig*0.7,ib*0.7)
	
local name = bag:CreateFontString (nil,"OVERLAY")
	name:SetFont(SVParts["fonts"].super,18,"OUTLINE")
	name:SetJustifyH("RIGHT")
	name:SetPoint("TOPRIGHT",6,-4)
	name:SetTextColor(cr+0.3,cg+0.3,cb+0.3)
	name:SetShadowOffset(2,3)
	name:SetShadowColor(0,0,0,0.8)
BagName=name
local title = bag:CreateFontString (nil,"OVERLAY")
	title:SetFont(SVParts["fonts"].Bold,SuperSet.font_sizes.datapanel,"OUTLINE")
	title:SetPoint("TOPLEFT",-6,8)
	title:SetJustifyH("LEFT")
	title:SetText("Bags Free: ")


local Profit	= 0
local Spent		= 0
local OldMoney	= 0
local Tokenz = {}
local Tokename = {}
local free,total,used = 0, 0, 0	
local myPlayerRealm = GetCVar("realmName");

local function Hex(color)
	return string.format('|cff%02x%02x%02x', color.r * 255, color.g * 255, color.b * 255)
end

local function GetColor()
	if not cColor then return end
	local r,g,b = cColor.r, cColor.g, cColor.b
	return r, g, b	
end

local function formatMoney(money)
	local gold = floor(math.abs(money) / 10000)
	local silver = mod(floor(math.abs(money) / 100), 100)
	local copper = mod(floor(math.abs(money)), 100)
	if gold ~= 0 then
		return format("%s".."|cffffcc00g|r ".."%s".."|cffc0c0c0s|r ".."%s".."|cff996633c|r", gold, silver, copper)
	elseif silver ~= 0 then
		return format("%s".."|cffc0c0c0s|r ".."%s".."|cff996633c|r", silver, copper)
	else
		return format("%s".."|cff996633c|r", copper)
	end
end

local function FormatTooltipMoney(money)
	local gold, silver, copper = abs(money / 10000), abs(mod(money / 100, 100)), abs(mod(money, 100))
	local cash = ""
	cash = format("%d".."|cffffcc00g|r ".." %d".."|cffc0c0c0s|r ".." %d".."|cff996633c|r", gold, silver, copper)		
	return cash
end	

local function update()
	Tokenz[1] = "---"
	Tokename[1] = "---"
	for i = 1, MAX_WATCHED_TOKENS do
		local name, count, _, _, _ = GetBackpackCurrencyInfo(i)
		if name and count then
			Tokename[i] = name
			Tokenz[i] = count
		end
	end
end

local function OnEvent(self, event)
	free,total,used = 0, 0, 0
	for i = 0, NUM_BAG_SLOTS do
		free, total = free + GetContainerNumFreeSlots(i), total + GetContainerNumSlots(i)
	end
	self:SetMinMaxValues(0,total)
	used = total - free
	BagName:SetText(free)
	self:SetValue(used)

	if event == "PLAYER_ENTERING_WORLD" then
		OldMoney = GetMoney()
	end
		
	local NewMoney	= GetMoney()
	local Change = NewMoney-OldMoney -- Positive if we gain money
		
	if OldMoney>NewMoney then		-- Lost Money
		Spent = Spent - Change
	else							-- Gained Moeny
		Profit = Profit + Change
	end
	
	local myPlayerName  = UnitName("player");
	local nc1,nc2,nc3 = cColor[1], cColor[2], cColor[3];
	if (MakeMoneyMoney == nil) then MakeMoneyMoney = {}; end
	if (MakeMoneyMoney[myPlayerRealm]==nil) then MakeMoneyMoney[myPlayerRealm]={}; end
	if (MakeMoneyMoney[myPlayerRealm][myPlayerName] == nil) then MakeMoneyMoney[myPlayerRealm][myPlayerName] = {}; end
	MakeMoneyMoney[myPlayerRealm][myPlayerName] = {["money"]=GetMoney(),["red"]=nc1,["green"]=nc2,["blue"]=nc3,};
			
	OldMoney = NewMoney
	
	update()
	bag:UnregisterEvent("PLAYER_LOGIN")
end

bag:RegisterEvent("PLAYER_LOGIN")
bag:RegisterEvent("BAG_UPDATE")
bag:RegisterEvent("PLAYER_MONEY")
bag:RegisterEvent("SEND_MAIL_MONEY_CHANGED")
bag:RegisterEvent("SEND_MAIL_COD_CHANGED")
bag:RegisterEvent("PLAYER_TRADE_MONEY")
bag:RegisterEvent("TRADE_MONEY_CHANGED")
bag:RegisterEvent("PLAYER_ENTERING_WORLD")

hooksecurefunc("BackpackTokenFrame_Update", update)
bag:SetScript("OnEvent", OnEvent)
bag:SetScript("OnMouseDown", function() OpenAllBags() end)
bag:SetScript("OnEnter", function(self)
	GameTooltip:SetOwner(self, "ANCHOR_CURSOR");
	GameTooltip:ClearLines()
	GameTooltip:AddDoubleLine(names.free,free.."/"..total,1,1,1,1,1,1)
	GameTooltip:AddDoubleLine(Tokename[1]..":",Tokenz[1],1,0.5,0,1,1,0.1)
	for i = 2, #Tokenz do
		GameTooltip:AddDoubleLine(Tokename[i]..":",Tokenz[i],1,0.5,0,1,1,0.1)
	end
	GameTooltip:AddLine' '
	GameTooltip:AddLine("Session:")
			GameTooltip:AddDoubleLine("Earned:", formatMoney(Profit), 1, 1, 1, 1, 1, 1)
			GameTooltip:AddDoubleLine("Spent:", formatMoney(Spent), 1, 1, 1, 1, 1, 1)
			if Profit < Spent then
				GameTooltip:AddDoubleLine("Deficit:", formatMoney(Profit-Spent), 1, 0, 0, 1, 1, 1)
			elseif (Profit-Spent)>0 then
				GameTooltip:AddDoubleLine("Profit:", formatMoney(Profit-Spent), 0, 1, 0, 1, 1, 1)
			end				
			GameTooltip:AddLine' '								
			
			local totalGold = 0	
			GameTooltip:AddLine("Character:")			
			local thisRealmList = MakeMoneyMoney[myPlayerRealm];
			for k,v in pairs(thisRealmList) do
				local name = k
				local moneyz,r,g,b
				if type(v) ~= "table" then 
					moneyz,r,g,b = 0,1,1,1
				else
					moneyz,r,g,b = v.money,v.red,v.green,v.blue
				end
				GameTooltip:AddDoubleLine(name, FormatTooltipMoney(moneyz), r, g, b, 1, 1, 1)
				totalGold=totalGold+moneyz;
			end 
			GameTooltip:AddLine' '
			GameTooltip:AddLine("Server:")
			GameTooltip:AddDoubleLine("Total", FormatTooltipMoney(totalGold), 0, 1, 0, 1, 1, 1)
			
	GameTooltip:Show()

end)
	
bag:SetScript("OnLeave", function(self)
	GameTooltip:Hide()
end)

-- reset gold data
local function RESETGOLD()
	local myPlayerRealm = GetCVar("realmName");
	local myPlayerName  = UnitName("player");
	
	MakeMoneyMoney = {}
	MakeMoneyMoney[myPlayerRealm]={}
	MakeMoneyMoney[myPlayerRealm][myPlayerName] = GetMoney();
end
SLASH_RESETGOLD1 = "/resetgold"
SlashCmdList["RESETGOLD"] = RESETGOLD
	
bag:Hide()	
SuperStat.make(bag,"Bags")
__________________
  Reply With Quote
12-28-10, 07:58 AM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
I had a similar problem but not sure if it is the same.
GetMoney() returns 0 before PLAYER_ENTERING_WORLD and only after that
it returns the right value ... that means you have to ignore values gathered
before this event.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
12-28-10, 07:59 AM   #3
Nightspirit
A Cyclonian
 
Nightspirit's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2009
Posts: 44
I think there are multiple way of correcting this:

1) Most straight to the point: Find a way to not store "Profit".
2) Unset "Profit" when player enters the world.
3) Unset "Profit" when player leaves world.

Whatever fits you best.
__________________
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Gold

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off