01-10-11, 10:06 AM | #1 |
Fixing Net Worth Addon
Been trying to figure out how to get this to work since it got broken in Cataclysm.
Here's the addon you get when mousing over the Net Worth frame: Code:
Error occured in: Global Count: 1 Message: ..\AddOns\NetWorth\NetWorth.lua line 79: attempt to perform arithmetic on field 'TGG' (a nil value) Debug: [C]: ? NetWorth\NetWorth.lua:79: MoneyWorth_Info() [string "*:OnEnter"]:1: [string "*:OnEnter"]:1 Unfortunately, with my limited WoW addon coding knowlege, I haven't been able to figure out how this OnEvent call is supposed to be structured in Cataclysm. Here's the full LUA file for MoneyWorth (that's the addon's actual name even though it's titled Net Worth): Code:
NWOptions={ ["LSG"]=nil, ["CSG"]=nil, ["TGG"]=nil, ["TGS"]=nil, ["SGS"]=nil } SesTime=0 NetWorth={} Um=false Ut=0 tut=0 COPPER_PER_SILVER = 100; SILVER_PER_GOLD = 100; COPPER_PER_GOLD = COPPER_PER_SILVER * SILVER_PER_GOLD; LC=nil ACG=0 function MoneyWorth_OnDragStart() MoneyWorthFrame:StartMoving() end function MoneyWorth_OnDragStop() MoneyWorthFrame:StopMovingOrSizing() end function MoneyWorth_OnLoad() MoneyWorthFrame:RegisterForDrag("LeftButton"); MoneyWorthFrame:RegisterEvent("PLAYER_LOGOUT"); MoneyWorthFrame:RegisterEvent("VARIABLES_LOADED"); MoneyWorthFrame:RegisterEvent("PLAYER_MONEY"); MoneyWorthFrame:RegisterEvent("PLAYER_ENTERING_WORLD"); MoneyWorthFrame:RegisterEvent("PLAYER_LOGIN"); SlashCmdList["MoneyWorth"]=MoneyWorth; SLASH_MoneyWorth1="/MoneyWorth" end function NWCloseClick() DEFAULT_CHAT_FRAME:AddMessage( "Hiding window, Use /MoneyWorth to show window.", .5, 1.0, .3 ); MoneyWorthFrame:Hide() end function MoneyWorth_OnEvent() if (event == "VARIABLES_LOADED") then if NWOptions ==nil then NWOptions={["LSG"]=0,["CSG"]=0,["TGG"]=0,["TGS"]=0,["LSG"]=0,["SGS"]=0};end tt = GetAddOnMetadata("NetWorth", "Title") vt = GetAddOnMetadata("NetWorth", "Version") DEFAULT_CHAT_FRAME:AddMessage( tt.." "..vt.." loaded ", .3, .5, 1.0,.3 ); mCalc() end if (event == "PLAYER_LOGOUT") then NWOptions.LSG=NWOptions.CSG NWOptions.CSG=0 NWOptions.SGS=0 end if (event == "PLAYER_LOGIN") then SesTime=GetTime() end if (event == "PLAYER_MONEY") then mCalc() mCalc() end if (event == "PLAYER_ENTERING_WORLD") then LC=GetMoney() mCalc() end end function MoneyWorth_Info() GameTooltip:SetOwner(MoneyWorthFrame, "ANCHOR_BOTTOMRIGHT"); Ts="" if (NWOptions.TGG-NWOptions.TGS)<0 then Ts="-";end if (NWOptions.TGG-NWOptions.TGS)>0 then Ts="+";end GameTooltip:SetText("Net Worth on "..GetRealmName()..":") GameTooltip:AddDoubleLine("Total ",Fm(NW())) GameTooltip:AddLine(" ") GameTooltip:AddLine("Session Stats:") GameTooltip:AddDoubleLine("|CFF66FF00Gold gained this session: ","|CFF66FF00"..Fm(NWOptions.CSG)) GameTooltip:AddDoubleLine("|CFFFF0000Gold spent this session: ","|CFFFF0000"..Fm(NWOptions.SGS)) mph=0 mph=floor(((NWOptions.CSG / (GetTime()-SesTime))*60)*60) tl=40-strlen(Fm(mph)) if tl<1 then tl=1;end GameTooltip:AddDoubleLine("|CFF3399FFEstimated Gold per hour: ","|CFF3399FF"..Fm(mph)) GameTooltip:AddDoubleLine("|CFFFFFFFFGained last session: ","|CFFFFFFFF"..Fm(NWOptions.LSG)) GameTooltip:AddLine(" ") GameTooltip:AddDoubleLine("|CFFFFFF00Total Gold gained to date: ","|CFFFFFF00"..Ts..Fm(abs(NWOptions.TGG-NWOptions.TGS))) GameTooltip:Show(); end function MoneyWorth_OnUpdate() if GetTime() > tut + 5 then tut=GetTime() if (GameTooltip:IsVisible() and GameTooltip:IsOwned(MoneyWorthFrame)) then GameTooltip:ClearLines() MoneyWorth_Info() end -- mCalc() end end function Fm(m) if m==nil then m=0;end local gold = floor(m / (COPPER_PER_SILVER * SILVER_PER_GOLD)); local silver = floor((m - (gold * COPPER_PER_SILVER * SILVER_PER_GOLD)) / COPPER_PER_SILVER); local copper = mod(m, COPPER_PER_SILVER); local gtmp=gold.."g " local stmp=silver.."s " local ctmp=copper.."c" if (GameTooltip:IsVisible() and GameTooltip:IsOwned(MoneyWorthFrame)) then stmp=strrep(" ",5-strlen(stmp))..stmp ctmp=strrep(" ",4-strlen(ctmp))..ctmp end fms=gtmp..stmp..ctmp return fms end function MoneyWorth(msg) MoneyWorthFrame:Show() if strupper(msg)=="RESET" then NWOptions.LSG=0 NWOptions.CSG=0 NWOptions.TGG=0 NWOptions.TGS=0 NWOptions.SGS=0 mCalc() end end function CW(p) cg,sn = strsplit(",",NetWorth[p]) cg=tonumber(cg) if sn==GetRealmName() then if p==UnitName("PLAYER") then GameTooltip:AddDoubleLine("|CFFFFFFFF"..p,"|CFFFFFFFF"..Fm(cg)) else GameTooltip:AddDoubleLine("|cffbfbfbf"..p,"|cffbfbfbf"..Fm(cg)) end Acg=Acg+cg end end function NW() Acg=0 table.foreach(NetWorth,CW) return Acg end function mCalc() NetWorth[UnitName("PLAYER")]=GetMoney()..","..GetRealmName() if LC==nil then LC=GetMoney();end local CG=GetMoney() local CC=0 if NWOptions.TGG==nil then NWOptions.TGG=0;end if NWOptions.TGS==nil then NWOptions.TGS=0;end if NWOptions.SGS==nil then NWOptions.SGS=0;end if NWOptions.CSG==nil then NWOptions.CSG=0;end sv="" if (NWOptions.CSG-NWOptions.SGS)<0 then sv="-";end if (NWOptions.CSG-NWOptions.SGS)>0 then sv="+";end MoneyWorthText:SetText(sv..Fm(abs(NWOptions.CSG-NWOptions.SGS))) if CG~=LC then CC=CG-LC LC=CG if (CC>0) then NWOptions.CSG = NWOptions.CSG + CC; NWOptions.TGG = NWOptions.TGG + CC; end if (CC<0) then NWOptions.TGS = NWOptions.TGS + (CC*-1);NWOptions.SGS=NWOptions.SGS + (CC*-1); end end end |
|
01-10-11, 11:23 AM | #2 | |
I couldn't bear to read the code without proper indenting I find it strange that the author mentioned v2.0 was updated for Patch 4.0.1, but he only bumped the TOC instead .. Also removed the seemingly pointless ABF.ttf, coure.fon and Desktop.ini NetWorth.lua Lua Code:
XML Code:
Code:
## Interface: 40000 ## Version: 2.1 ## Release: 11 January 2011 ## Title: Net Worth ## Author: AFTiggerIntel ## Notes: Net Worth keeps track of your Gold earnings for both session, character, and totals for each character on the realm. Sorry it does not separate the Horde and Alliance toons. ## SavedVariables: NetWorth ## SavedVariablesPerCharacter: NWOptions NetWorth.xml Last edited by Ketho : 01-10-11 at 11:30 AM. |
||
01-10-11, 10:24 PM | #3 |
Sweet! Thanks so much!
|
|
WoWInterface » Developer Discussions » Lua/XML Help » Fixing Net Worth Addon |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|