View Single Post
12-22-18, 11:21 AM   #4
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Rilgamon View Post
Check which value throws the error in 558 and make sure it has a value before you use it.
You're not clear if you want to only see the same faction listed or list and sum up both.
My code of zz_Money shows only the same faction. So perhaps you can check it for what you want to do.
Thanks This Helped some.

So here is the current plugin code for the Bags/Money:
Code:
	if db.bags then
		local bagsPlugin = CreateFrame('Frame', nil, Datapanel)
		bagsPlugin:EnableMouse(true)
		bagsPlugin:SetFrameStrata('BACKGROUND')
		bagsPlugin:SetFrameLevel(3)

		local Text = bagsPlugin:CreateFontString(nil, 'OVERLAY')
		Text:SetFont(db.font, db.fontSize,'THINOUTLINE')
		PlacePlugin(db.bags, Text)

		local Profit	= 0
		local Spent		= 0
		local OldMoney	= 0
		local myPlayerName  = UnitName('player');
		local myPlayerRealm = GetRealmName();
		local myPlayerFaction = UnitFactionGroup('player')
			
		local function formatMoney(c)
			local str = ""
			if not c or c < 0 then 
				return str 
			end
			
			if c >= 10000 then
				local g = math.floor(c/10000)
				c = c - g*10000
				str = str..BreakUpLargeNumbers(g).."|cFFFFD800g|r "
			end
			if c >= 100 then
				local s = math.floor(c/100)
				c = c - s*100
				str = str..s.."|cFFC7C7C7s|r "
			end
			if c >= 0 then
				str = str..c.."|cFFEEA55Fc|r"
			end
			
			return str
		end
		
		local function OnEvent(self, event)
			local totalSlots, freeSlots = 0, 0
			local itemLink, subtype, isBag
			for i = 0,NUM_BAG_SLOTS do
				isBag = true
				if i > 0 then
					itemLink = GetInventoryItemLink('player', ContainerIDToInventoryID(i))
					if itemLink then
						subtype = select(7, GetItemInfo(itemLink))
						if (subtype == 'Mining Bag') or (subtype == 'Gem Bag') or (subtype == 'Engineering Bag') or (subtype == 'Enchanting Bag') or (subtype == 'Herb Bag') or (subtype == 'Inscription Bag') or (subtype == 'Leatherworking Bag') or (subtype == 'Fishing Bag')then
							isBag = false
						end
					end
				end
				if isBag then
					totalSlots = totalSlots + GetContainerNumSlots(i)
					freeSlots = freeSlots + GetContainerNumFreeSlots(i)
				end
				Text:SetText(hexa.."Bags: "..hexb.. freeSlots.. '/' ..totalSlots)
					if freeSlots < 6 then
						Text:SetTextColor(1,0,0)
					elseif freeSlots < 10 then
						Text:SetTextColor(1,0,0)
					elseif freeSlots > 10 then
						Text:SetTextColor(1,1,1)
					end
				self:SetAllPoints(Text)
				
			end
			--if event == "PLAYER_LOGIN" then
				--OldMoney = GetMoney()
			--end
			
			local NewMoney = GetMoney()

			db['Currency'] = db['Currency'] or {}
			db['Currency'][myPlayerRealm] = db['Currency'][myPlayerRealm] or {}
			db['Currency'][myPlayerRealm][myPlayerFaction] = db['Currency'][myPlayerRealm][myPlayerFaction] or {}
			db['Currency'][myPlayerRealm][myPlayerFaction][myPlayerName] = db['Currency'][myPlayerRealm][myPlayerFaction][myPlayerName] or NewMoney

			OldMoney = db['Currency'][myPlayerRealm][myPlayerFaction][myPlayerName] or NewMoney

			local Change = NewMoney - OldMoney

			if (OldMoney > NewMoney) then
				Spent = Spent - Change
			else
				Profit = Profit + Change
			end			
			
			self:SetAllPoints(Text)	
			
			db['Currency'][myPlayerRealm][myPlayerFaction][myPlayerName] = NewMoney
			
				
		end

		bagsPlugin:RegisterEvent("PLAYER_MONEY")
		bagsPlugin:RegisterEvent("SEND_MAIL_MONEY_CHANGED")
		bagsPlugin:RegisterEvent("SEND_MAIL_COD_CHANGED")
		bagsPlugin:RegisterEvent("PLAYER_TRADE_MONEY")
		bagsPlugin:RegisterEvent("TRADE_MONEY_CHANGED")
		bagsPlugin:RegisterEvent("PLAYER_LOGIN")
		bagsPlugin:RegisterEvent("BAG_UPDATE")
		
		bagsPlugin:SetScript('OnMouseDown', 
			function()
				if db.bag ~= true then
					ToggleAllBags()
				else
					ToggleBag(0)
				end
			end
		)
		bagsPlugin:SetScript('OnEvent', OnEvent)	
		bagsPlugin:SetScript("OnEnter", function(self)
			local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
			GameTooltip:SetOwner(panel, anchor, xoff, yoff)
			GameTooltip:ClearLines()
			GameTooltip:AddDoubleLine(hexa..PLAYER_NAME.."'s"..hexb.."|cffffd700 Currency|r", formatMoney(OldMoney), 1, 1, 1, 1, 1, 1)
			GameTooltip:AddLine' '			
			GameTooltip:AddLine("This 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's: ")
			local thisRealmList = db['Currency'][myPlayerRealm];
			if db['Currency'][myPlayerRealm][myPlayerFaction] == ('Alliance') then
				for k,v in pairs(thisRealmList) do
					GameTooltip:AddLine('Alliance:')
					GameTooltip:AddDoubleLine(k, formatMoney(v), 1, 1, 1, 1, 1, 1)
					totalGold = totalGold + v;
				end
			elseif db['Currency'][myPlayerRealm][myPlayerFaction] == ('Horde') then
				for k,v in pairs(thisRealmList) do
					GameTooltip:AddLine('Horde:')
					GameTooltip:AddDoubleLine(k, formatMoney(v), 1, 1, 1, 1, 1, 1)
					totalGold = totalGold + v;
				end
			elseif db['Currency'][myPlayerRealm][myPlayerFaction] == ('Neutral') then
				for k,v in pairs(thisRealmList) do
					GameTooltip:AddLine('Neutral:')
					GameTooltip:AddDoubleLine(k, formatMoney(v), 1, 1, 1, 1, 1, 1)
					totalGold = totalGold + v;
				end
			end	

			GameTooltip:AddLine' '
			GameTooltip:AddLine("Server:")
			GameTooltip:AddDoubleLine("Total: ", formatMoney(totalGold), 1, 1, 1, 1, 1, 1)

			for i = 1, GetNumWatchedTokens() do
				local name, count, extraCurrencyType, icon, itemID = GetBackpackCurrencyInfo(i)
				if name and i == 1 then
					GameTooltip:AddLine(" ")
					GameTooltip:AddLine(CURRENCY..":")
				end
				local r, g, b = 1,1,1
				if itemID then r, g, b = GetItemQualityColor(select(3, GetItemInfo(itemID))) end
				if name and count then GameTooltip:AddDoubleLine(name, count, r, g, b, 1, 1, 1) end
			end
			GameTooltip:AddLine' '
			GameTooltip:AddLine("|cffeda55fClick|r to Open Bags")			
			GameTooltip:Show()
		end)
		
		bagsPlugin:SetScript("OnLeave", function() GameTooltip:Hide() end)			

	end
and this code creates the first post image:
Code:
	if db.bags then
		local bagsPlugin = CreateFrame('Frame', nil, Datapanel)
		bagsPlugin:EnableMouse(true)
		bagsPlugin:SetFrameStrata('BACKGROUND')
		bagsPlugin:SetFrameLevel(3)

		local Text = bagsPlugin:CreateFontString(nil, 'OVERLAY')
		Text:SetFont(db.font, db.fontSize,'THINOUTLINE')
		PlacePlugin(db.bags, Text)

		local Profit	= 0
		local Spent		= 0
		local OldMoney	= 0
		local myPlayerRealm = GetRealmName();
		
		
		local function formatMoney(c)
			local str = ""
			if not c or c < 0 then 
				return str 
			end
			
			if c >= 10000 then
				local g = math.floor(c/10000)
				c = c - g*10000
				str = str..BreakUpLargeNumbers(g).."|cFFFFD800g|r "
			end
			if c >= 100 then
				local s = math.floor(c/100)
				c = c - s*100
				str = str..s.."|cFFC7C7C7s|r "
			end
			if c >= 0 then
				str = str..c.."|cFFEEA55Fc|r"
			end
			
			return str
		end
		
		local function OnEvent(self, event)
			local totalSlots, freeSlots = 0, 0
			local itemLink, subtype, isBag
			for i = 0,NUM_BAG_SLOTS do
				isBag = true
				if i > 0 then
					itemLink = GetInventoryItemLink('player', ContainerIDToInventoryID(i))
					if itemLink then
						subtype = select(7, GetItemInfo(itemLink))
						if (subtype == 'Mining Bag') or (subtype == 'Gem Bag') or (subtype == 'Engineering Bag') or (subtype == 'Enchanting Bag') or (subtype == 'Herb Bag') or (subtype == 'Inscription Bag') or (subtype == 'Leatherworking Bag') or (subtype == 'Fishing Bag')then
							isBag = false
						end
					end
				end
				if isBag then
					totalSlots = totalSlots + GetContainerNumSlots(i)
					freeSlots = freeSlots + GetContainerNumFreeSlots(i)
				end
				Text:SetText(hexa.."Bags: "..hexb.. freeSlots.. '/' ..totalSlots)
					if freeSlots < 6 then
						Text:SetTextColor(1,0,0)
					elseif freeSlots < 10 then
						Text:SetTextColor(1,0,0)
					elseif freeSlots > 10 then
						Text:SetTextColor(1,1,1)
					end
				self:SetAllPoints(Text)
				
			end
			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 Money
				Profit = Profit + Change
			end
			
			self:SetAllPoints(Text)

			local myPlayerName  = UnitName("player")
			local myPlayerFaction = UnitFactionGroup("player");
			if not BasicDB.Currency then BasicDB.Currency = {} end
			if not BasicDB.Currency[myPlayerRealm] then BasicDB.Currency[myPlayerRealm]={} end
			BasicDB.Currency[myPlayerRealm][myPlayerName] = GetMoney()	
				
			OldMoney = NewMoney	
				
		end

		bagsPlugin:RegisterEvent("PLAYER_MONEY")
		bagsPlugin:RegisterEvent("SEND_MAIL_MONEY_CHANGED")
		bagsPlugin:RegisterEvent("SEND_MAIL_COD_CHANGED")
		bagsPlugin:RegisterEvent("PLAYER_TRADE_MONEY")
		bagsPlugin:RegisterEvent("TRADE_MONEY_CHANGED")
		bagsPlugin:RegisterEvent("PLAYER_ENTERING_WORLD")
		bagsPlugin:RegisterEvent("BAG_UPDATE")
		
		bagsPlugin:SetScript('OnMouseDown', 
			function()
				if db.bag ~= true then
					ToggleAllBags()
				else
					ToggleBag(0)
				end
			end
		)
		bagsPlugin:SetScript('OnEvent', OnEvent)	
		bagsPlugin:SetScript("OnEnter", function(self)
			local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
			GameTooltip:SetOwner(panel, anchor, xoff, yoff)
			GameTooltip:ClearLines()
			GameTooltip:AddDoubleLine(hexa..PLAYER_NAME.."'s"..hexb.."|cffffd700 Gold|r", formatMoney(OldMoney), 1, 1, 1, 1, 1, 1)
			GameTooltip:AddLine' '			
			GameTooltip:AddLine("This 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:AddDoubleLine("Total:", formatMoney(OldMoney), 1, 1, 1, 1, 1, 1)
			GameTooltip:AddLine' '
			
			local totalGold = 0				
			GameTooltip:AddLine("Character's: ")
			local myPlayerFaction, _ = UnitFactionGroup("player");
			local thisRealmList = BasicDB.Currency[myPlayerRealm];
			for k,v in pairs(thisRealmList) do
				GameTooltip:AddDoubleLine(k, formatMoney(v), 1, 1, 1, 1, 1, 1)
				totalGold=totalGold+v;
			end

			GameTooltip:AddLine' '
			GameTooltip:AddLine("Server:")
			GameTooltip:AddDoubleLine("Total: ", formatMoney(totalGold), 1, 1, 1, 1, 1, 1)

			for i = 1, GetNumWatchedTokens() do
				local name, count, extraCurrencyType, icon, itemID = GetBackpackCurrencyInfo(i)
				if name and i == 1 then
					GameTooltip:AddLine(" ")
					GameTooltip:AddLine(CURRENCY..":")
				end
				local r, g, b = 1,1,1
				if itemID then r, g, b = GetItemQualityColor(select(3, GetItemInfo(itemID))) end
				if name and count then GameTooltip:AddDoubleLine(name, count, r, g, b, 1, 1, 1) end
			end
			GameTooltip:AddLine' '
			GameTooltip:AddLine("|cffeda55fClick|r to Open Bags")
			GameTooltip:AddLine("|cffeda55fType|r /resetcurrency to Reset Currency Totals")			
			GameTooltip:Show()
		end)
		
		bagsPlugin:SetScript("OnLeave", function() GameTooltip:Hide() end)			
		-- reset gold data
		local function RESETCURRENCY()
			local myPlayerRealm = GetRealmName();
			local myPlayerFaction = select(1, UnitFactionGroup("player"));
			local myPlayerName  = UnitName("player");
			
			BasicDB.Currency = {}
			BasicDB.Currency[myPlayerRealm]={}
			BasicDB.Currency[myPlayerRealm][myPlayerFaction][myPlayerName] = GetMoney();
		end
		SLASH_RESETCURRENCY1 = "/resetcurrency"
		SlashCmdList["RESETCURRENCY"] = RESETCURRENCY	

	end
Here is the SavedVariables it creates:
Code:
BasicDB = {
	["namespaces"] = {
		["Nameplate"] = {
		},
		["Misc"] = {
		},
		["Buff"] = {
		},
		["Powerbar"] = {
		},
		["Tooltip"] = {
		},
		["Chat"] = {
		},
		["Unitframe"] = {
		},
		["Actionbar"] = {
		},
		["Datapanel"] = {
			["profiles"] = {
				["Default"] = {
					["Currency"] = {
						["Fenris"] = {
							["Horde"] = {
								["Unknøwn"] = 17661878,
								["ßullwinkle"] = 95560850,
							},
							["Alliance"] = {
								["Silhøuette"] = 867196155,
								["Cokeman"] = 434537262,
							},
						},
					},
				},
			},
		},
	},
	["profileKeys"] = {
		["ßullwinkle - Fenris"] = "Default",
		["Silhøuette - Fenris"] = "Default",
		["Unknøwn - Fenris"] = "Default",
		["Cokeman - Fenris"] = "Default",
	},
	["profiles"] = {
		["Default"] = {
		},
	},
}
and yet nothings shows in the toolitp here is a screenshot:


As you can see nothing loads.

I think it might be useless to get this to do what i want.

Below is what im looking for in text format:

Code:
<Players Name>'s Currency          100g 00s 02c

This Session:
Earned:         100g0s0c
Spent:          20g0s0c

Character's:
Alliance:
<Players Name>          10,000g50s35c

Horde:
<Players Name>         1,000g0s0c

Nuetral:
<Players Name>          100g0s0c

Server:
Total         11,100g50s35c

Currency:
Nethershard         29

Click to Open Bags
If this is not possible please let me know so i can stop trying.

Thanks
Coke

Last edited by cokedrivers : 12-22-18 at 11:25 AM. Reason: Added First code
  Reply With Quote