RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Gold commands

Revan

Sorceror
ok ok, chill.
So I fixed it, ya happy now? :p
Won't count gold in houses, at least not yet.
Have fun :)
 

Attachments

  • PlayerGold.cs
    2.3 KB · Views: 27

Dracolique

Sorceror
Im proud of the community. You all pulled together to make and improve something useful. Now if only we could do it for my old "I have a dream" post. :)

But I think that project would take more than a day.
 

Quantos

Lord
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;
		}


Please point out what in here was changed.
 

Dracolique

Sorceror
No problem

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( [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;
		}
 

Dracolique

Sorceror
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.
 

Quantos

Lord
It may have been a conflict with another script you are running then. I've seen no problems on our shard with it.

I will keep my eyes open for it though.
 

Erica

Knight
Quantos said:
It replaces the one that I released. For clarification see my post immediately prior to that one.
ahh ok will replace this one with the one i had thankyou
 

panther

Sorceror
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.
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.
 

Quantos

Lord
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.

Ah, okay, that makes sense to me too. Thanks for the heads up on that.
 
Top