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!

[RunUO 1.0 Final] Gold per account

Gold per account

Compatibility: RunUO 2.0 RC1 donno, the forum is buggy, even if I accidently picked that...

Description:
[CountGoldPerAccount
by Admin or higher will create a text file, which contains some info on global amount of gold and a list of accounts telling how much each one of them owns.
All those with exact 1k are most likely inactive accounts, but you better check before removing them. :p
If you want to post any modifications just go ahead. :)

GoldByAccount.txt said:
Gold counted on 02.08.2006 16:02:53
Gold on NPCs: 634141
Gold on playervendors: 213555
Gold in containers: 81892
Gold on the floor: 285
Total gold: 929873
Gold on Accounts by name:
acc1 : 110000
12bla : 90000
acct : 10555
somerand : 1500
somfrand : 1500

Installation:
Right-Click, save as and so on...
Drop the file in your desired custom script directory
 

Attachments

  • CountGoldPerAccount.cs
    5 KB · Views: 318

Joeku

Lord
Neat.

Suggestion: modify it so that you can specify a Type to count, within the command parameters.

Example: [CountTypePerAccount Gold
 

Pyro-Tech

Knight
Joeku said:
Neat.

Suggestion: modify it so that you can specify a Type to count, within the command parameters.

Example: [CountTypePerAccount Gold

yeah....doing that would expand this to count anything in theory
 
I was thinking about a script to count the vet rewards belonging to each account... gues some ppl will be interested in token... hmmm... It's a good idea, I'll try to steal the code from the RunUO basecommand. :p
 
Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Server.Accounting;
using Server.Items;
using Server.Mobiles;
using Server.Multis;

namespace Server.Commands
{
	public class CountGoldPerAccount
	{
		public static void Initialize()
		{
			CommandSystem.Register( "CountGoldPerAccount", AccessLevel.Administrator, new CommandEventHandler( CountGoldPerAccount_OnCommand ) );
		}

		[Usage( "UnusedAccountRemove [<name> <propertyName>]" )]
		[Description( "Counts the gold owned by an account and writes to file or counts a property of a certain item." )]
		public static void CountGoldPerAccount_OnCommand( CommandEventArgs arg )
		{
			if ( arg.Length == 0 )
				CountGold( arg.Mobile );
			else if ( arg.Length > 1 )
			{
				Type t = ScriptCompiler.FindTypeByName( arg.GetString( 0 ) );

				if ( t == null )
				{
					arg.Mobile.SendMessage( "No type with such a name was found." );
					return;
				}

				PropertyInfo[] allProps = t.GetProperties( BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public );

				PropertyInfo thisProp = null;
				string propName = arg.GetString( 1 );

				for ( int j = 0; thisProp == null && j < allProps.Length; ++j )
				{
					if ( Insensitive.Equals( propName, allProps[j].Name ) )
						thisProp = allProps[j];
				}

				if ( thisProp == null )
				{
					arg.Mobile.SendMessage( "Property not found: {0}", propName );
					return;
				}
				else
				{
					CountInstances( arg.Mobile, t, thisProp );
				}

			}
			else
				arg.Mobile.SendMessage( "You need to supply a type and a property." );
		}

		public static void CountInstances( Mobile from, Type t, PropertyInfo prop )
		{
			if ( DoesInherit( t, typeof( Item ) ) )
			{
				CountItemInstances( from, t, prop );
			}
			/*else if ( DoesInherit( t, typeof( Mobile ) ) )
			{
				from.SendMessage( "That type is not supported yet." ); //Don't really see any use for that
			}*/
			else
				from.SendMessage( "That type is not supported!" );
		}

		public static void CountItemInstances( Mobile from, Type t, PropertyInfo prop )
		{
			from.SendMessage( "Counting. Drink tea and wait..." );

			List<Item> itemList = new List<Item>( World.Items.Values );
			object parent;
			PlayerMobile master = null;
			BaseHouse house = null;
			IAccount account;
			Hashtable goldOnAccountTable = new Hashtable();
			uint value = 0;
			uint totalValue = 0;
			foreach ( Item item in itemList )
			{
				if ( item.GetType().IsAssignableFrom( t ) )
				{
					if ( item.Deleted )
						continue;

					try{value = System.Convert.ToUInt32( prop.GetValue( item, null ) );}
					catch(Exception e){from.SendMessage( "You just crashed the shard my friend. Maybe not... Try harder!" ); Console.WriteLine( e ); continue;}

					if ( value == 0 )
						continue;
					else
						totalValue += value;

					parent = item.RootParent;
					if ( parent is Mobile )
					{
						if ( parent is PlayerVendor )
							master = ((PlayerVendor)parent).Owner as PlayerMobile;
						else if ( parent is BaseCreature )
							master = ((BaseCreature)parent).ControlMaster as PlayerMobile;
						else
							master = parent as PlayerMobile;
					}
					else if ( parent != null ) // Containers
					{
						if ( ((Item)parent).IsSecure || ((Item)parent).IsLockedDown )
							house = BaseHouse.FindHouseAt( parent as Item );
				
						if ( house != null )
							master = house.Owner as PlayerMobile;
					}
					else
					{
						if ( item.IsSecure || item.IsLockedDown )
							house = BaseHouse.FindHouseAt( item );

						if ( house != null )
							master = house.Owner as PlayerMobile;
						if ( master == null && item is IMount )
							master = ((IMount)item).Rider;
					}

					if ( master != null )
					{
						account = master.Account;
						if (  account != null )
						{
							if ( goldOnAccountTable.Contains( account ) )
								goldOnAccountTable[account] = (uint)goldOnAccountTable[account] + (uint)value;
							else
								goldOnAccountTable[account] = (uint)value;
						}
						else
							from.SendMessage( master.ToString() + " has no account!" );
					}
					master = null;
					house = null;
				}
			}

			System.IO.StreamWriter tw = new System.IO.StreamWriter( t.Name + prop.Name + ".txt", true );

			tw.WriteLine( t.Name + "s' " + prop.Name + " counted on " + DateTime.Now.ToString() );

			IDictionaryEnumerator en = goldOnAccountTable.GetEnumerator();
			List<GoldAccountEntry> gaList = new List<GoldAccountEntry>();
			GoldAccountEntry gae;
			while (en.MoveNext())
			{
				gae = new GoldAccountEntry();
				gae.Account = (IAccount)(en.Key);
				gae.Value = (uint)(en.Value);
				gaList.Add( gae );
			}

			tw.WriteLine( "Total " + t.Name + " : " + totalValue.ToString() );
			tw.WriteLine( t.Name + " on accounts by name:" );

			gaList.Sort();
			for ( int i = 0; i < gaList.Count; ++i )
				tw.WriteLine( gaList[i].Account.ToString() + " : " + gaList[i].Value.ToString() );

			tw.Close();

			from.SendMessage( "Saved log to " + t.Name + prop.Name + ".txt..." );
		}

		public static bool DoesInherit( Type type, Type child ) //DoesInherit here returns true if equal too
		{
			while( type != null )
			{
				if ( type == child )
					return true;
				else
					type = type.BaseType;
			}
			return false;
		}

		public static void CountGold( Mobile from )
		{
			from.SendMessage( "Counting gold. Drink tea and wait..." );

			object parent;
			PlayerMobile master = null;
			BaseHouse house = null;
			PlayerVendor vendor;
			int value = 0;
			IAccount account;
			uint goldHeldByNPCs = 0;
			uint goldOnFloor = 0;
			uint goldInContainers = 0;
			Hashtable goldOnAccountTable = new Hashtable();
			List<Item> itemList = new List<Item>( World.Items.Values );
			List<Mobile> mobileList = new List<Mobile>( World.Mobiles.Values );

			foreach ( Item item in itemList )
			{
				if ( item.Deleted )
					continue;

				if ( item is Gold )
					value = item.Amount;
				else if ( item is BankCheck)
					value = ((BankCheck)item).Worth;
				else
					continue;

				if ( value == 0 )
					continue;

				parent = item.RootParent;
				if ( parent is Mobile )
				{
					if ( parent is PlayerVendor )
						master = ((PlayerVendor)parent).Owner as PlayerMobile;
					else if ( parent is BaseCreature )
						master = ((BaseCreature)parent).ControlMaster as PlayerMobile;
					else
						master = parent as PlayerMobile;

					if ( master == null )
						goldHeldByNPCs += (uint)value;
				}
				else if ( parent != null ) // Containers
				{
					if ( ((Item)parent).IsSecure || ((Item)parent).IsLockedDown )
						house = BaseHouse.FindHouseAt( parent as Item );
					
					if ( house != null )
						master = house.Owner as PlayerMobile;

					if ( master == null )
						goldInContainers += (uint)value;	
				}
				else
				{
					if ( item.IsSecure || item.IsLockedDown )
						house = BaseHouse.FindHouseAt( item );

					if ( house != null )
						master = house.Owner as PlayerMobile;

					if ( master == null )
						goldOnFloor += (uint)value;
				}

				if ( master != null )
				{
					account = master.Account;
					if (  account != null )
					{
						if ( goldOnAccountTable.Contains( account ) )
							goldOnAccountTable[account] = (uint)goldOnAccountTable[account] + (uint)value;
						else
							goldOnAccountTable[account] = (uint)value;
					}
					else
						from.SendMessage( master.ToString() + " has no account!" );
				}
				parent = null;
				master = null;
				house = null;
			}

			uint goldOnPlayervendors = 0;
			foreach ( Mobile m in mobileList )
			{
				if ( !(m is PlayerVendor) )
					continue;

				vendor = (PlayerVendor)m;
				master = vendor.Owner as PlayerMobile;
				if ( master != null )
				{
					account = master.Account;
					if (  account != null )
					{
						goldOnPlayervendors += (uint)(vendor.BankAccount + vendor.HoldGold);
						if ( goldOnAccountTable.Contains( account ) )
							goldOnAccountTable[account] = (uint)goldOnAccountTable[account] + (uint)(vendor.BankAccount + vendor.HoldGold);
						else
							goldOnAccountTable[account] = (uint)value;
					}
					else
						from.SendMessage( master.ToString() + " has no account!" );
				}
			}

			uint totalGold = goldHeldByNPCs + goldOnFloor + goldInContainers;

			System.IO.StreamWriter tw = new System.IO.StreamWriter( "GoldByAccount.txt", true );

			tw.WriteLine( "Gold counted on " + DateTime.Now.ToString() );
			tw.WriteLine( "Gold on NPCs: " + goldHeldByNPCs.ToString() );
			tw.WriteLine( "Gold on playervendors: " + goldOnPlayervendors.ToString() );
			tw.WriteLine( "Gold in containers: " + goldInContainers.ToString() );
			tw.WriteLine( "Gold on the floor: " + goldOnFloor.ToString() );

			IDictionaryEnumerator en = goldOnAccountTable.GetEnumerator();
			List<GoldAccountEntry> gaList = new List<GoldAccountEntry>();
			GoldAccountEntry gae;
			while (en.MoveNext())
			{
				gae = new GoldAccountEntry();
				gae.Account = (IAccount)(en.Key);
				gae.Value = (uint)(en.Value);
				gaList.Add( gae );
				totalGold += gae.Value;
			}

			tw.WriteLine( "Total gold: " + totalGold.ToString() );
			tw.WriteLine( "Gold on accounts by name:" );

			gaList.Sort();
			for ( int i = 0; i < gaList.Count; ++i )
				tw.WriteLine( gaList[i].Account.ToString() + " : " + gaList[i].Value.ToString() );

			tw.Close();

			from.SendMessage( "Saved log to GoldByAccount.txt..." );
		}

		private class GoldAccountEntry : IComparable
		{
			public IAccount Account;
			public uint Value;

			public int CompareTo(object o)
			{
				GoldAccountEntry g = (GoldAccountEntry)o;

				int i = Value.CompareTo( g.Value );

				if ( i != 0 )
					return -i;

				return Account.Username.CompareTo( g.Account.Username );
			}
		}
	}
}

[CountGoldPerAccount EtherealMount IsRewardItem
gives:
System.Reflection.TargetException: Das Objekt stimmt mit dem Zieltyp nicht übere
in.
bei System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
bei System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invok
eAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisi
bilityChecks)
bei System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invok
eAttr, Binder binder, Object[] parameters, CultureInfo culture)
bei System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags i
nvokeAttr, Binder binder, Object[] index, CultureInfo culture)
bei System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index
)
bei Server.Commands.CountGoldPerAccount.CountItemInstances(Mobile from, Type
t, PropertyInfo prop) in c:\Dokumente und Einstellungen\Alexander Göbel\Eigene D
ateien\My Downloads\Conversion\Convert\E2 2.0\Scripts\Custom\CountGoldPerAccount
.cs:Zeile 94.
System.Reflection.TargetException: The object does not match the target type, or a property is an instance property but obj is null.
I'm a bit puzzled on that one. Didn't google yet, will later.
 
Top