Thread Tools Display Modes
01-10-11, 10:06 AM   #1
lyps
A Defias Bandit
Join Date: Jan 2011
Posts: 2
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
As far as I can tell from my testing, the MoneyWorth_OnEvent() function isn't ever getting fired, so the NWOptions hash is never getting setup.

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
I'm guessing this is just a simple matter of fixing the OnEvent setup. Does anybody know how to do this from a quick glance at the code?
  Reply With Quote
01-10-11, 11:23 AM   #2
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Originally Posted by lyps View Post
Been trying to figure out how to get this to work since it got broken in Cataclysm.
I'm guessing this is just a simple matter of fixing the OnEvent setup. Does anybody know how to do this from a quick glance at the code?
Yes, only the OnEvent had to be fixed

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:
  1. NWOptions={
  2.     ["LSG"]=nil,
  3.     ["CSG"]=nil,
  4.     ["TGG"]=nil,
  5.     ["TGS"]=nil,
  6.     ["SGS"]=nil
  7. }
  8. SesTime=0
  9. NetWorth={}
  10. Um=false
  11. Ut=0
  12. tut=0
  13.  
  14. COPPER_PER_SILVER = 100;
  15. SILVER_PER_GOLD = 100;
  16. COPPER_PER_GOLD = COPPER_PER_SILVER * SILVER_PER_GOLD;
  17. LC=nil
  18. ACG=0
  19.  
  20. function MoneyWorth_OnDragStart()
  21.     MoneyWorthFrame:StartMoving()
  22. end
  23.  
  24. function MoneyWorth_OnDragStop()
  25.     MoneyWorthFrame:StopMovingOrSizing()   
  26. end
  27.  
  28.  
  29. function MoneyWorth_OnLoad(self)
  30.     self:RegisterForDrag("LeftButton");
  31.     self:RegisterEvent("PLAYER_LOGOUT");
  32.     self:RegisterEvent("VARIABLES_LOADED");
  33.     self:RegisterEvent("PLAYER_MONEY");
  34.     self:RegisterEvent("PLAYER_ENTERING_WORLD");
  35.     self:RegisterEvent("PLAYER_LOGIN");
  36.     SlashCmdList["MoneyWorth"]=MoneyWorth;
  37.     SLASH_MoneyWorth1="/MoneyWorth"
  38. end
  39.  
  40. function NWCloseClick()
  41.     DEFAULT_CHAT_FRAME:AddMessage( "Hiding window, Use /MoneyWorth to show window.", .5, 1.0, .3 );
  42.     MoneyWorthFrame:Hide()
  43. end
  44.  
  45. function MoneyWorth_OnEvent(self, event)
  46.     if (event == "VARIABLES_LOADED") then
  47.         if NWOptions ==nil then
  48.             NWOptions={["LSG"]=0,["CSG"]=0,["TGG"]=0,["TGS"]=0,["LSG"]=0,["SGS"]=0};
  49.         end
  50.         tt = GetAddOnMetadata("NetWorth", "Title")
  51.         vt = GetAddOnMetadata("NetWorth", "Version")
  52.         DEFAULT_CHAT_FRAME:AddMessage( tt.." "..vt.." loaded ", .3, .5, 1.0,.3 );
  53.         mCalc()
  54.     end
  55.  
  56.     if (event == "PLAYER_LOGOUT") then
  57.         NWOptions.LSG=NWOptions.CSG
  58.         NWOptions.CSG=0
  59.         NWOptions.SGS=0
  60.     end
  61.  
  62.     if (event == "PLAYER_LOGIN") then
  63.         SesTime=GetTime()
  64.     end
  65.  
  66.     if (event == "PLAYER_MONEY") then
  67.         mCalc()
  68.         mCalc()
  69.     end
  70.  
  71.     if (event == "PLAYER_ENTERING_WORLD") then
  72.         LC=GetMoney()
  73.         mCalc()
  74.     end
  75. end
  76.  
  77. function MoneyWorth_Info()
  78.     GameTooltip:SetOwner(MoneyWorthFrame, "ANCHOR_BOTTOMRIGHT");
  79.     Ts=""
  80.     if (NWOptions.TGG-NWOptions.TGS)<0 then Ts="-";end
  81.     if (NWOptions.TGG-NWOptions.TGS)>0 then Ts="+";end
  82.     GameTooltip:SetText("Net Worth on "..GetRealmName()..":")
  83.     GameTooltip:AddDoubleLine("Total ",Fm(NW()))
  84.     GameTooltip:AddLine(" ")
  85.  
  86.     GameTooltip:AddLine("Session Stats:")
  87.     GameTooltip:AddDoubleLine("|CFF66FF00Gold gained this session: ","|CFF66FF00"..Fm(NWOptions.CSG))
  88.     GameTooltip:AddDoubleLine("|CFFFF0000Gold spent this session: ","|CFFFF0000"..Fm(NWOptions.SGS))
  89.     mph=0
  90.     mph=floor(((NWOptions.CSG / (GetTime()-SesTime))*60)*60)
  91.     tl=40-strlen(Fm(mph))
  92.     if tl<1 then tl=1;end
  93.  
  94.     GameTooltip:AddDoubleLine("|CFF3399FFEstimated Gold per hour: ","|CFF3399FF"..Fm(mph))
  95.  
  96.     GameTooltip:AddDoubleLine("|CFFFFFFFFGained last session: ","|CFFFFFFFF"..Fm(NWOptions.LSG))
  97.     GameTooltip:AddLine(" ")
  98.     GameTooltip:AddDoubleLine("|CFFFFFF00Total Gold gained to date: ","|CFFFFFF00"..Ts..Fm(abs(NWOptions.TGG-NWOptions.TGS)))
  99.     GameTooltip:Show();
  100. end
  101.  
  102. function MoneyWorth_OnUpdate()
  103.     if GetTime() > tut + 5 then
  104.         tut=GetTime()
  105.         if (GameTooltip:IsVisible() and GameTooltip:IsOwned(MoneyWorthFrame)) then
  106.             GameTooltip:ClearLines()
  107.             MoneyWorth_Info()
  108.         end
  109.         -- mCalc()
  110.     end
  111. end
  112.  
  113. function Fm(m)
  114.     if m==nil then m=0 end
  115.     local gold = floor(m / (COPPER_PER_SILVER * SILVER_PER_GOLD));
  116.     local silver = floor((m - (gold * COPPER_PER_SILVER * SILVER_PER_GOLD)) / COPPER_PER_SILVER);
  117.     local copper = mod(m, COPPER_PER_SILVER);
  118.  
  119.     local gtmp=gold.."g  "
  120.     local stmp=silver.."s  "
  121.     local ctmp=copper.."c"
  122.     if (GameTooltip:IsVisible() and GameTooltip:IsOwned(MoneyWorthFrame)) then
  123.         stmp=strrep("  ",5-strlen(stmp))..stmp
  124.         ctmp=strrep("  ",4-strlen(ctmp))..ctmp
  125.     end
  126.     fms=gtmp..stmp..ctmp
  127.  
  128.     return fms
  129. end
  130.  
  131.  
  132. function MoneyWorth(msg)
  133.     MoneyWorthFrame:Show()
  134.     if strupper(msg)=="RESET" then
  135.         NWOptions.LSG=0
  136.         NWOptions.CSG=0
  137.         NWOptions.TGG=0
  138.         NWOptions.TGS=0
  139.         NWOptions.SGS=0
  140.         mCalc()
  141.     end
  142. end
  143.  
  144. function CW(p)
  145.     cg,sn = strsplit(",",NetWorth[p])
  146.     cg=tonumber(cg)
  147.     if sn==GetRealmName() then
  148.         if p==UnitName("PLAYER") then
  149.             GameTooltip:AddDoubleLine("|CFFFFFFFF"..p,"|CFFFFFFFF"..Fm(cg))
  150.         else
  151.             GameTooltip:AddDoubleLine("|cffbfbfbf"..p,"|cffbfbfbf"..Fm(cg))
  152.         end
  153.     Acg=Acg+cg
  154.     end
  155. end
  156.  
  157. function NW()
  158.     Acg=0
  159.     table.foreach(NetWorth,CW)
  160.     return Acg
  161. end
  162.  
  163. function mCalc()
  164.     NetWorth[UnitName("PLAYER")]=GetMoney()..","..GetRealmName()
  165.     if LC==nil then LC=GetMoney();end
  166.         local CG=GetMoney()
  167.         local CC=0
  168.         if NWOptions.TGG==nil then NWOptions.TGG=0;end
  169.         if NWOptions.TGS==nil then NWOptions.TGS=0;end
  170.         if NWOptions.SGS==nil then NWOptions.SGS=0;end
  171.         if NWOptions.CSG==nil then NWOptions.CSG=0;end
  172.         sv=""
  173.         if (NWOptions.CSG-NWOptions.SGS)<0 then sv="-";end
  174.         if (NWOptions.CSG-NWOptions.SGS)>0 then sv="+";end
  175.         MoneyWorthText:SetText(sv..Fm(abs(NWOptions.CSG-NWOptions.SGS)))
  176.  
  177.     if CG~=LC then
  178.         CC=CG-LC
  179.         LC=CG
  180.         if (CC>0) then NWOptions.CSG = NWOptions.CSG + CC; NWOptions.TGG = NWOptions.TGG + CC; end
  181.         if (CC<0) then NWOptions.TGS = NWOptions.TGS + (CC*-1);NWOptions.SGS=NWOptions.SGS + (CC*-1); end
  182.     end
  183. end
NetWorth.xml
XML Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  2. ..\FrameXML\UI.xsd">
  3. <Script file="NetWorth.lua" />
  4.     <Frame name="MoneyWorthFrame" toplevel="true" enableMouse="true" movable="true" parent="UIParent">
  5.         <Size>
  6.             <AbsDimension x="128" y="22"/>
  7.         </Size>
  8.         <Anchors>
  9.             <Anchor point="CENTER"/>
  10.         </Anchors>
  11.         <Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="false">
  12.             <BackgroundInsets>
  13.                 <AbsInset left="5" right="5" top="5" bottom="5"/>
  14.             </BackgroundInsets>
  15.             <TileSize>
  16.                 <AbsValue val="16"/>
  17.             </TileSize>
  18.             <EdgeSize>
  19.                 <AbsValue val="16"/>
  20.             </EdgeSize>
  21.         </Backdrop>
  22.         <Layers>
  23.         <Layer level="ARTWORK">
  24.                 <FontString name="MoneyWorthText" inherits="GameFontNormal" >
  25.                     <Size>
  26.                         <AbsDimension x="128" y="18"/>                  </Size>
  27.                     <Anchors>
  28.                     <Anchor point="TOPLEFT"/>
  29.                     </Anchors>
  30.                 </FontString>
  31.             </Layer>
  32.         </Layers>
  33.         <Frames>
  34.             <Button name="MoneyWorthClose">
  35.                 <Size>
  36.                     <AbsDimension x="22" y="22"/>
  37.                 </Size>
  38.                 <Anchors>
  39.                     <Anchor point="RIGHT">
  40.                         <Offset>
  41.                             <AbsDimension x="19" y="0"/>
  42.                         </Offset>
  43.                     </Anchor>
  44.                 </Anchors>
  45.                 <Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="false">
  46.                     <BackgroundInsets>
  47.                         <AbsInset left="5" right="5" top="5" bottom="5"/>
  48.                     </BackgroundInsets>
  49.                     <TileSize>
  50.                         <AbsValue val="16"/>
  51.                     </TileSize>
  52.                     <EdgeSize>
  53.                         <AbsValue val="16"/>
  54.                     </EdgeSize>
  55.                 </Backdrop>
  56.                 <Scripts>
  57.                 <OnClick>
  58.                     NWCloseClick();
  59.                 </OnClick>
  60.                 <OnLoad>
  61.                 self:SetClampedToScreen(true)
  62.                 </OnLoad>              
  63.                 </Scripts>
  64.                 <NormalTexture file="Interface\Buttons\UI-Panel-MinimizeButton-Up"/>
  65.                 <PushedTexture file="Interface\Buttons\UI-Panel-MinimizeButton-Down"/>
  66.                 <HighlightTexture alphaMode="ADD" file="Interface\Buttons\UI-Panel-MinimizeButton-Highlight"/>
  67.             </Button>
  68.         </Frames>
  69.         <Scripts>
  70.             <OnLoad>self:SetClampedToScreen(true); MoneyWorth_OnLoad(self)</OnLoad>
  71.             <OnEvent>MoneyWorth_OnEvent(self, event)</OnEvent>
  72.             <OnDragStart>
  73.                 MoneyWorth_OnDragStart();
  74.             </OnDragStart>
  75.             <OnDragStop>
  76.                 MoneyWorth_OnDragStop();
  77.             </OnDragStop>
  78.             <OnEnter>
  79.                 MoneyWorth_Info();             
  80.             </OnEnter>
  81.             <OnLeave>
  82.                 GameTooltip:Hide()
  83.             </OnLeave>
  84.             <OnMouseUp>
  85.                
  86.             </OnMouseUp>
  87.            
  88.             <OnUpdate>
  89.                 MoneyWorth_OnUpdate();
  90.             </OnUpdate>
  91.  
  92.         </Scripts>
  93.     </Frame>
  94.        
  95. </Ui>
NetWorth.toc
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
Attached Files
File Type: zip NetWorth 2.1.zip (3.1 KB, 645 views)

Last edited by Ketho : 01-10-11 at 11:30 AM.
  Reply With Quote
01-10-11, 10:24 PM   #3
lyps
A Defias Bandit
Join Date: Jan 2011
Posts: 2
Sweet! Thanks so much!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Fixing Net Worth Addon


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