Dracolique said:Quantos, I was getting a null reference exception server crash when using your modification of the PlayerGold script, so I changed the following parts( hope you dont mind ), and now it works flawlessly:
Code:public static float GoldOnPlayers( Mobile m ) { float GoP = 0; using ( StreamWriter css = GetWriter( "docs/", "Player Gold.txt" ) ) { foreach( Mobile MiW in World.Mobiles.Values ) { if( MiW != null && MiW is PlayerMobile ) { PlayerMobile pm = (PlayerMobile)MiW; if ( pm.BankBox != null && pm.Backpack != null ) { GoP += SearchForGold( pm.BankBox ); GoP += SearchForGold( pm.Backpack ); m.SendMessage( "Checking " + pm.Name + " ("+GoP+")"); css.WriteLine( pm.Name + " has "+GoP+" GP." ); } } } } return GoP; } public static float SearchForGold( Container c ) { float goldcount = 0; foreach( Item i in c.Items ) if( i!= null && i is Container ) goldcount += SearchForGold( (Container)i ); else if( i!= null && i is Gold ) goldcount += ((Gold)i).Amount; else if( i != null && i is BankCheck ) goldcount += ((BankCheck)i).Worth; return goldcount; }
public static float GoldOnPlayers( Mobile m )
{
float GoP = 0;
using ( StreamWriter css = GetWriter( "docs/", "Player Gold.txt" ) )
{
foreach( Mobile MiW in World.Mobiles.Values )
{
if( [B][U]MiW != null &&[/U] [/B] MiW is PlayerMobile )
{
PlayerMobile pm = (PlayerMobile)MiW;
[B][U]if ( pm.BankBox != null && pm.Backpack != null )
{[/U][/B] GoP += SearchForGold( pm.BankBox );
GoP += SearchForGold( pm.Backpack );
m.SendMessage( "Checking " + pm.Name + " ("+GoP+")");
css.WriteLine( pm.Name + " has "+GoP+" GP." );
[B][U]}[/U][/B]
}
}
}
return GoP;
}
public static float SearchForGold( Container c )
{
float goldcount = 0;
foreach( Item i in c.Items )
if([B][U] i!= null &&[/U] [/B] i is Container )
goldcount += SearchForGold( (Container)i );
else if( [B][U]i!= null && [/U] [/B] i is Gold )
goldcount += ((Gold)i).Amount;
else if( [B][U]i != null && [/U] [/B] i is BankCheck )
goldcount += ((BankCheck)i).Worth;
return goldcount;
}
so is this the fix to replace the other one i hadRevan said:ok ok, chill.
So I fixed it, ya happy now?
Won't count gold in houses, at least not yet.
Have fun
ahh ok will replace this one with the one i had thankyouQuantos said:It replaces the one that I released. For clarification see my post immediately prior to that one.
This line would have been the one:Dracolique said:I didnt test which one of those was giving the null reference exception crash, I just fixed everything in the script that it might possibly be.
panther said:This line would have been the one:
if ( pm.BankBox != null && pm.Backpack != null )
This would occur if a player has no backpack for some odd reason (not a normal occurance). The others couldn't possibly be null.