12-15-18, 10:04 AM | #1 |
Sorting Tooltip for money by Faction
currently i have a mouseover tooltip in mt datatext that shows me my currents relms charators total gold.
Code:
local totalGold = 0 GameTooltip:AddLine("Character's: ") 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 I have both Horde and Alliance I would like to see how much gold i have on each faction beings you cannot send gold to other factions. Any help would be great. P.S. If you need more code my whole addon is on GitHub Here. And this is in the Datatext.lua file under bags. Thanks Coke |
|
12-21-18, 07:19 AM | #2 |
So noone knows anyway to get this info?
im trying to do it this way: Code:
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][myPlayerFaction][myPlayerName] = GetMoney() Code:
34x BasicUI\Modules\Datapanel.lua:558: attempt to index field '?' (a nil value) BasicUI\Modules\Datapanel.lua:558: in function <BasicUI\Modules\Datapanel.lua:510> Locals: self = <unnamed> { 0 = <userdata> } event = "PLAYER_ENTERING_WORLD" totalSlots = 120 freeSlots = 68 itemLink = "|cffffffff|Hitem:160452::::::::114:581::::::|h[]|h|r" subtype = nil isBag = true NewMoney = 122614145 Change = 0 myPlayerName = "Øsmosis" myPlayerFaction = "Alliance" (*temporary) = nil (*temporary) = 122614145 (*temporary) = 122614145 (*temporary) = "Alliance" (*temporary) = "Alliance" (*temporary) = <userdata> (*temporary) = "/" (*temporary) = "120" (*temporary) = "attempt to index field '?' (a nil value)" Text = <unnamed> { 0 = <userdata> } OldMoney = 122614145 Spent = 0 Profit = 0 myPlayerRealm = "Fenris" |
|
12-21-18, 08:22 AM | #3 |
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.
__________________
The cataclysm broke the world ... and the pandas could not fix it! |
|
12-22-18, 11:21 AM | #4 | |
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 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 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"] = { }, }, } 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 Thanks Coke Last edited by cokedrivers : 12-22-18 at 11:25 AM. Reason: Added First code |
||
12-22-18, 02:29 PM | #5 |
You have the data. So its totally possible to display it.
Lua Code:
In situations like this print out the variables so you can quickly see if the values are what you expect. Here it seems you mixed up the content and the meaning of the key. 'myPlayerFaction' represents the value you try to compare. db['Currency'][myPlayerRealm][myPlayerFaction] represents the list of your current faction. From your described result to list all factions this means you have (at least) two faults here. It should not be an if-elseif-clause if you want it all printed. Lua Code:
__________________
The cataclysm broke the world ... and the pandas could not fix it! |
|
12-24-18, 08:57 AM | #6 | |
Here is a screen shot of the new Tooltip: Again thank you for the help. Happy Gaming and Coding to All. Coke |
||
12-27-18, 08:39 AM | #7 |
So I've been playing around with the code and i think I finally have it where I like it here are some Screen Shots...
Alliance Only - Horde Only - Neutral Only - Alliance and Neutral - And Finally All 3 Factions - The spacing for missing factions sucks but i had to do a IF for nil so i used GameTooltip:AddDoubleLine(" ", " ") for nil then the tooltip for the Faction if its available. another reason for the bigs gaps are because of the space between factions if all 3 of them are shown. Well let me know if they look decent or if they are just to cluttered. Thanks Coke |
|
12-27-18, 11:32 AM | #8 |
Just curious, are you neutral characters Pandaren that have not picked a faction?
|
|
12-27-18, 11:45 AM | #9 |
12-28-18, 12:45 PM | #10 | |
|
||
12-29-18, 11:23 AM | #11 |
12-29-18, 11:31 AM | #12 |
so this is the code I use that hides or shows the Factions gold:
Code:
local totalGold = 0; local totalAlianceGold = 0; local totalHordeGold = 0; local totalNeutralGold = 0; if db['Gold'][myPlayerRealm]['Alliance'] == nil then GameTooltip:AddDoubleLine(" ", " ") else GameTooltip:AddLine("Alliance Character's:") for k,v in pairs(db['Gold'][myPlayerRealm]['Alliance']) do GameTooltip:AddDoubleLine(iconAlliance..k, formatMoney(v), 1, 1, 1, 1, 1, 1) totalAlianceGold = totalAlianceGold + v; end GameTooltip:AddDoubleLine("Total Alliance Gold", formatMoney(totalAlianceGold)) end GameTooltip:AddDoubleLine(" ", " ") if db['Gold'][myPlayerRealm]['Horde'] == nil then GameTooltip:AddDoubleLine(" ", " ") else GameTooltip:AddLine("Horde Character's:") for k,v in pairs(db['Gold'][myPlayerRealm]['Horde']) do GameTooltip:AddDoubleLine(iconHorde..k, formatMoney(v), 1, 1, 1, 1, 1, 1) totalHordeGold = totalHordeGold + v; end GameTooltip:AddDoubleLine("Total Horde Gold", formatMoney(totalHordeGold)) end GameTooltip:AddDoubleLine(" ", " ") if db['Gold'][myPlayerRealm]['Neutral'] == nil then GameTooltip:AddDoubleLine(" ", " ") else GameTooltip:AddLine("Neutral Character's:") for k,v in pairs(db['Gold'][myPlayerRealm]['Neutral']) do GameTooltip:AddDoubleLine(iconNuetral..k, formatMoney(v), 1, 1, 1, 1, 1, 1) totalNeutralGold = totalNeutralGold + v; end GameTooltip:AddDoubleLine("Total Neutral Gold", formatMoney(totalNeutralGold)) end local totalServerGold = totalAlianceGold + totalHordeGold + totalNeutralGold GameTooltip:AddLine" " GameTooltip:AddDoubleLine("Total Gold for "..myPlayerRealm, formatMoney(totalServerGold)) |
|
12-29-18, 02:51 PM | #13 |
Here is one way to shorten it. You're doing the same thing per faction, so you can create a loop that does the same thing. I've renamed some variables to make it more obvious what values they hold. I also think that by adding the blank line as a header for each faction's gold, it fixes the "extra" blank lines in your tooltip. Please note that I dry-coded this, so there may be typos and other errors.
Code:
local factions = { 'Alliance', 'Horde', 'Neutral' } local factionGold = { Alliance = 0, Horde = 0, Neutral = 0, } local factionIcon = { Alliance = iconAlliance, Horde = iconHorde, Neutral = iconNeutral, } local totalRealmGold = 0 local goldDB = (db and db.Gold) and db.Gold[myPlayerRealm] or nil if goldDB then for _, faction in pairs(factions) do if goldDB[faction] then GameTooltip:AddDoubleLine(" ", " ") GameTooltip:AddLine(faction .. " Characters:") for name, amount in pairs(goldDB[faction]) do GameTooltip:AddDoubleLine(factionIcon[faction] .. name, formatMoney(amount), 1, 1, 1, 1, 1, 1) factionGold[faction] = factionGold[faction] + amount end GameTooltip:AddDoubleLine("Total " .. faction .. " Gold", formatMoney(factionGold[faction])) totalRealmGold = totalRealmGold + factionGold[faction] end end GameTooltip:AddDoubleLine("Total Gold for " .. myPlayerRealm, formatMoney(totalRealmGold)) end |
|
12-29-18, 04:57 PM | #14 | |
Second, you're getting the gaps because you're adding the gaps. (Oh, and you also don't need to add a double-line to create a spacer, it can just be a regular line. This way you don't end up with more strings created in memory than necessary.) Lua Code:
For example, I've commented above how it is that you are getting 4 blank lines instead of one if you have only neutral characters on a server. If you follow the logic of what you are trying to do, you want an empty line (a spacer) after every faction's section. This is even true for the last displayed faction in the tooltip, since you want a spacer before the total gold on the realm. If a faction's info will not be present in the tooltip, then you don't need the spacer. If you wish to keep your code formatted as is (rather than jlam's condensed version), then do this instead. Lua Code:
|
||
12-30-18, 10:02 AM | #15 | |
to GameTooltip:AddLine(" ") because without the space the gap was not added. but thank you very much. Also thanks for the spell check Coke |
||
12-30-18, 12:46 PM | #16 |
I guess I forgot that it wouldn't work with an empty string.
|
|
WoWInterface » Developer Discussions » Lua/XML Help » Sorting Tooltip for money by Faction |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|