Go Back   RunUO - Ultima Online Emulation > RunUO > Server Support on Windows

Server Support on Windows Get (and give) support on general questions related to the RunUO server itself.

Reply
 
Thread Tools Display Modes
Old 08-06-2008, 10:44 PM   #1 (permalink)
Forum Expert
 
RoninGT's Avatar
 
Join Date: Oct 2002
Location: Evansville, IN
Age: 27
Posts: 943
Send a message via ICQ to RoninGT
Default Load Error, Again

Ok thought i had it fixed and i was wrong, Here is the error and script with lines of errors highlighted. Hope this helps.

Code:
Server Crash Report
===================

RunUO Version 2.0, Build 3022.28592
Operating System: Microsoft Windows NT 6.0.6000.0
.NET Framework: 2.0.50727.1433
Time: 8/6/2008 9:07:52 PM
Mobiles: 238
Items: 127239
Exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Item has already been added. Key in dictionary: '0x1 "Paige"'  Key being added: '0x1 "Paige"'
   at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
   at Server.FSCoreSystem.FSCore.Load() in e:\Extraz\Ultima Online\Server\Fallen Souls ML\Scripts\Custom\FS Customs\Systems\FSCore\Core\FSCoreSystem.cs:line 322
   at Server.FSCoreSystem.FSCore.Initialize() in e:\Extraz\Ultima Online\Server\Fallen Souls ML\Scripts\Custom\FS Customs\Systems\FSCore\Core\FSCoreSystem.cs:line 20
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Server.ScriptCompiler.Compile(Boolean debug, Boolean cache)
   at Server.Core.Main(String[] args)

Clients:
- Count: 0
Line 20 = Green
Line 322 = Red

Code:
using System;
using System.IO;
using Server.Gumps;
using Server.Items;
using Server.Guilds;
using Server.Network;
using Server.Mobiles;
using Server.Factions;
using Server.Targeting;
using Server.Accounting;
using System.Collections;

namespace Server.FSCoreSystem
{
	public class FSCore
	{
		public static void Initialize()
		{
			EventSink.WorldSave += new WorldSaveEventHandler( EventSink_WorldSave );
			Load();
		}

		private static void EventSink_WorldSave( WorldSaveEventArgs e )
		{
			Save();
		}

		private static Hashtable m_MobileTable;
		private static Hashtable MobileTable
		{
			get
			{
				if ( m_MobileTable == null )
					m_MobileTable = new Hashtable();

				return m_MobileTable;
			}
		}

		public class MobileCore
		{
			private Mobile m_Owner;
			private MobileRace m_Race;
			private MobileType m_Type;
			private PvpStatus m_PvpStatus;
			private int m_Level;
			private int m_GeneralEx;
			private int m_HitsBonus;
			private int m_StamBonus;
			private int m_ManaBonus;
	
			public Mobile Owner{ get{ return m_Owner; } }
			public MobileRace Race{ get{ return m_Race; } set{ m_Race = value; } }
			public MobileType Type{ get{ return m_Type; } set{ m_Type = value; } }
			public PvpStatus PvpStatus{ get{ return m_PvpStatus; } set{ m_PvpStatus = value; } }
			public int Level{ get{ return m_Level; } set{ m_Level = value; } }
			public int GeneralEx{ get{ return m_GeneralEx; } set{ m_GeneralEx = value; } }
			public int HitsBonus{ get{ return m_HitsBonus; } set{ m_HitsBonus = value; } }
			public int StamBonus{ get{ return m_StamBonus; } set{ m_StamBonus = value; } }
			public int ManaBonus{ get{ return m_ManaBonus; } set{ m_ManaBonus = value; } }

			public MobileCore()
			{
				m_Owner = null;
			}
			
			public MobileCore( Mobile Owner )
			{
				m_Owner = Owner;
				m_Level = 1;
			}

			public void Serialize( GenericWriter writer )
			{
				writer.Write( (int) 1 );

				// version 0
				writer.Write( (Mobile) m_Owner );

				// version 1
				writer.WriteEncodedInt( (int) m_Race );
				writer.WriteEncodedInt( (int) m_Type );
				writer.Write( (int) m_Level );
				writer.Write( (int) m_GeneralEx );
				writer.Write( (int) m_HitsBonus );
				writer.Write( (int) m_StamBonus );
				writer.Write( (int) m_ManaBonus );
			}

			public void Deserialize( GenericReader reader )
			{
				int version = reader.ReadInt();
				
				switch ( version )
				{
					case 1:
					{
						m_Race = (MobileRace)reader.ReadEncodedInt();
						m_Type = (MobileType)reader.ReadEncodedInt();
						m_Level = reader.ReadInt();
						m_GeneralEx = reader.ReadInt();
						m_HitsBonus = reader.ReadInt();
						m_StamBonus = reader.ReadInt();
						m_ManaBonus = reader.ReadInt();
						goto case 0;
					}
					case 0:
					{
						m_Owner = reader.ReadMobile();
						break;
					}
				}
			}

			public void CheckLevel( int exp )
			{
				if ( m_Owner != null )
				{
					int nextLevel = m_Level * 3000;

					if ( exp > nextLevel )
					{
						m_GeneralEx -= nextLevel;

						if ( m_Owner is PlayerMobile )
						{
							m_Owner.SendMessage( "You have gained in level." );
							m_Owner.SendMessage( "You are now level {0}.", m_Level );

							m_HitsBonus += 2;
							m_StamBonus += 1;
							m_ManaBonus += 1;
						}
						else if ( m_Owner is BaseCreature )
						{
							BaseCreature bc = (BaseCreature)m_Owner;

							bc.RawStr += 2;
							bc.RawDex += 1;
							bc.RawInt += 1;

							bc.HitsMaxSeed += bc.HitsMaxSeed / 4;
							bc.StamMaxSeed += Utility.RandomMinMax( 10, 30);
							bc.ManaMaxSeed += Utility.RandomMinMax( 10, 30);
						}
						else
						{
							// WTF is it doing leveling if its not a player or basecreature???
						}

						m_Owner.PlaySound( 503 );
						m_Owner.FixedParticles( 0x3709, 1, 30, 9904, 1108, 6, EffectLayer.RightFoot );
						m_Owner.FixedParticles( 0x373A, 10, 15, 5018, EffectLayer.Waist );

						m_Level += 1;

						if ( m_Level == 80 )
							m_GeneralEx = 0;

						if ( m_GeneralEx > nextLevel )
							CheckLevel( m_GeneralEx );
					}
				}
			}

			public void GiveExp( int exp )
			{
				if ( m_Owner != null && m_Level < 80 )
				{
					m_GeneralEx += exp;
					m_Owner.SendMessage( "You gained {0} exp.", exp );
					this.CheckLevel( m_GeneralEx );

					World.Broadcast( 0x35, true, "SYSTEM TEST: {0} has gained {1} exp.", m_Owner.Name, exp );
				}
			}

			public void SetLevel( int level )
			{
				if ( m_Owner != null )
				{
					if ( level > m_Level )
					{
						int newLevel = level - m_Level;

						if ( m_Owner is PlayerMobile )
						{
							m_Owner.SendMessage( "You have gained in level." );
							m_Owner.SendMessage( "You are now level {0}.", m_Level );

							int hits = 2 * level;
							int stam = 1 * level;
							int mana = 1 * level;

							m_HitsBonus = hits;
							m_StamBonus = stam;
							m_ManaBonus = mana;
						}
						else if ( m_Owner is BaseCreature )
						{
							BaseCreature bc = (BaseCreature)m_Owner;

							int newstr = 2 * newLevel;
							int newdex = 1 * newLevel;
							int newint = 1 * newLevel;

							bc.RawStr += newstr;
							bc.RawDex += newdex;
							bc.RawInt += newint;

							int hitsmax = bc.HitsMaxSeed / 4 * newLevel;
							int stammax = Utility.RandomMinMax( 10, 30) * newLevel;
							int manamax = Utility.RandomMinMax( 10, 30) * newLevel;

							bc.HitsMaxSeed += hitsmax;
							bc.StamMaxSeed += stammax;
							bc.ManaMaxSeed += manamax;
						}
						else
						{
							// WTF is it doing leveling if its not a player or basecreature???
						}
					}
					else
					{
						int newLevel = m_Level - level;

						if ( m_Owner is PlayerMobile )
						{
							m_Owner.SendMessage( "You have lost in level." );
							m_Owner.SendMessage( "You are now level {0}.", m_Level );

							int hits = 2 * newLevel;
							int stam = 1 * newLevel;
							int mana = 1 * newLevel;

							m_HitsBonus = hits;
							m_StamBonus = stam;
							m_ManaBonus = mana;
						}
						else if ( m_Owner is BaseCreature )
						{
							BaseCreature bc = (BaseCreature)m_Owner;

							int newstr = 2 * newLevel;
							int newdex = 1 * newLevel;
							int newint = 1 * newLevel;

							bc.RawStr -= newstr;
							bc.RawDex -= newdex;
							bc.RawInt -= newint;

							int hitsmax = bc.HitsMaxSeed / 4 * newLevel;
							int stammax = Utility.RandomMinMax( 10, 30) * newLevel;
							int manamax = Utility.RandomMinMax( 10, 30) * newLevel;

							bc.HitsMaxSeed -= hitsmax;
							bc.StamMaxSeed -= stammax;
							bc.ManaMaxSeed -= manamax;
						}
						else
						{
							// WTF is it doing leveling if its not a player or basecreature???
						}
					}

					m_Owner.PlaySound( 503 );
					m_Owner.FixedParticles( 0x3709, 1, 30, 9904, 1108, 6, EffectLayer.RightFoot );
					m_Owner.FixedParticles( 0x373A, 10, 15, 5018, EffectLayer.Waist );

					m_Level = level;
				}
			}

			public void Status( Mobile from )
			{
				if ( from != null )
					from.SendMessage( "Current Exp:{0}, Current Level:{1}.", m_GeneralEx, m_Level );
			}
		}

		public static void Load()
		{
			string idxPath = Path.Combine( "Saves/FS Systems/FSCoreSystem", "MobileTable.idx" );
			string binPath = Path.Combine( "Saves/FS Systems/FSCoreSystem", "MobileTable.bin" );

			if ( File.Exists( idxPath ) && File.Exists( binPath ) )
			{
				FileStream idx = new FileStream( idxPath, FileMode.Open, FileAccess.Read, FileShare.Read );
				FileStream bin = new FileStream( binPath, FileMode.Open, FileAccess.Read, FileShare.Read) ;
				BinaryReader idxReader = new BinaryReader( idx );
				BinaryFileReader binReader = new BinaryFileReader( new BinaryReader( bin ) );

				int orderCount = idxReader.ReadInt32();

				for ( int i = 0; i < orderCount; ++i )
				{
					MobileCore mc = new MobileCore();
					long startPos = idxReader.ReadInt64();
					int length = idxReader.ReadInt32();
					binReader.Seek( startPos, SeekOrigin.Begin );

					try
					{
						mc.Deserialize(binReader);

						if (binReader.Position != ( startPos + length ) )
							throw new Exception( String.Format( "***** Bad serialize on MobileCore[{0}] *****", i ) );
					}
					catch
					{
					}

					if ( mc != null && mc.Owner != null )
					{
							MobileTable.Add( mc.Owner, mc );
					}
				}
      
				idxReader.Close();
				binReader.Close();
			}

		}


		public static void Save()
		{
			if (!Directory.Exists( "Saves/FS Systems/FSCoreSystem" ) )
				Directory.CreateDirectory( "Saves/FS Systems/FSCoreSystem" );

			string idxPath = Path.Combine( "Saves/FS Systems/FSCoreSystem", "MobileTable.idx" );
			string binPath = Path.Combine( "Saves/FS Systems/FSCoreSystem", "MobileTable.bin" );
							

			GenericWriter idx = new BinaryFileWriter( idxPath, false );
			GenericWriter bin = new BinaryFileWriter( binPath, true );

			idx.Write( (int)MobileTable.Values.Count );
			foreach ( MobileCore mc in MobileTable.Values )
			{
				long startPos = bin.Position;
				mc.Serialize( bin );
				idx.Write( (long)startPos );
				idx.Write( (int)( bin.Position - startPos  ) );
			}

			idx.Close();
			bin.Close();
		}

		public static MobileCore GetMobileCore( Mobile m )
		{
			if ( m == null )
				return null;

			MobileCore mc = (MobileCore)MobileTable[m];
			if ( mc == null )
			{
				mc = new MobileCore( m );
				MobileTable.Add( m, mc );
			}

			return mc;
		}

		public static void GiveExp( Mobile from, int exp, int split )
		{
			if ( from != null )
			{
				int xp = exp / split;

				MobileCore mc = GetMobileCore( from );
				mc.GiveExp( xp );
			}
		}

		public static void SetLevel( Mobile from, int level )
		{
			if ( from != null )
			{
				MobileCore mc = GetMobileCore( from );
				mc.SetLevel( level );
			}
		}

		public static void GetStatus( Mobile target, Mobile sender )
		{
			if ( target != null && sender != null )
			{
				MobileCore mc = GetMobileCore( target );
				mc.Status( sender );
			}
		}
	}
}
Hope this helps not sure where its getting the issue. Been awhile since i scripted a bit rusty.

Ronin
__________________
Let me out i am stuck in your pocket!
RoninGT is offline   Reply With Quote
Old 08-07-2008, 05:02 AM   #2 (permalink)
Forum Expert
 
Join Date: Dec 2005
Posts: 537
Default

Code:
if ( mc != null && mc.Owner != null &&  !MobileTable.Contains(mc.Owner))
					{
							MobileTable.Add( mc.Owner, mc );
					}
b0b01 is offline   Reply With Quote
Old 08-07-2008, 10:27 AM   #3 (permalink)
Forum Expert
 
RoninGT's Avatar
 
Join Date: Oct 2002
Location: Evansville, IN
Age: 27
Posts: 943
Send a message via ICQ to RoninGT
Default

That was my oringinal fix, It does not crash on load but it also does not save anyones stats when the server reloads all values are set to 0 and null

Ronin
__________________
Let me out i am stuck in your pocket!
RoninGT is offline   Reply With Quote
Old 08-07-2008, 11:57 AM   #4 (permalink)
Forum Expert
 
Join Date: Dec 2005
Posts: 537
Default

I never worked with a hashtable so im not sure if this works but try it.

if ( mc != null && mc.Owner != null)
{
MobileTable[mc.Owner] =mc;
}



Btw why do you use a hastable instead of a dicitonary or something like that?
b0b01 is offline   Reply With Quote
Old 08-07-2008, 12:03 PM   #5 (permalink)
Forum Expert
 
RoninGT's Avatar
 
Join Date: Oct 2002
Location: Evansville, IN
Age: 27
Posts: 943
Send a message via ICQ to RoninGT
Default

Quote:
Originally Posted by b0b01 View Post
Btw why do you use a hastable instead of a dicitonary or something like that?
I am open for suggestions, Frankly this is old code i did 3 years ago, starting scripting again. If you know of a better way i am all ears always open to new ideas.

Ronin

P.S. Ill give it a shot and let you know if that worked thou

EDIT: I have another script that saves and loads the same way its a bounty hunter system however it has no problems with save and loading and the methods are the same. I get the problem with this code when i add the edits to the basecreature OnBeforeDeath() to have mobs and players gain exp
__________________
Let me out i am stuck in your pocket!

Last edited by RoninGT; 08-07-2008 at 12:05 PM.
RoninGT is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5