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!

Fix Scrambled Inventory on Resurrect

Shino90

Sorceror
Fix Scrambled Inventory on Resurrect

The following script edits will make sure items in your inventory stay in their place when you die/resurrect. The script edits affect Scripts/Mobiles/PlayerMobile.cs. It only saves item locations of blessed and newbied items for regular players, and all for GMs.


Find:
Code:
		private int m_GuildMessageHue, m_AllianceMessageHue;
Add below:
Code:
		private Dictionary<Item, Point2D> m_ItemLocations;



Find:
Code:
			base.Resurrect();
Add above:
Code:
			if( this.m_ItemLocations != null ) {
				foreach( Item item in this.m_ItemLocations.Keys ) {
					item.X = this.m_ItemLocations[item].X;
					item.Y = this.m_ItemLocations[item].Y;
				}
			}



Find:
Code:
			if ( m_SentHonorContext != null )
				m_SentHonorContext.OnSourceKilled();
Add below:
Code:
			List<Item> items = new List<Item>( this.Backpack.Items );
			
			m_ItemLocations = new Dictionary<Item, Point2D>();
			
			for( int i = 0; i < items.Count; i++ ) {
				if(items[i].LootType == LootType.Blessed || items[i].LootType == LootType.Newbied || AccessLevel > AccessLevel.Player) {
					m_ItemLocations[items[i]] = new Point2D( items[i].X, items[i].Y );
				}
			}



Find:
Code:
			switch ( version )
			{
Add below:
Code:
				case 26:
				{
					int itemLocationsCount = reader.ReadInt();

					if( itemLocationsCount > 0 )
					{
						m_ItemLocations = new Dictionary<Item, Point2D>();

						for( int i = 0; i < itemLocationsCount; i++ )
						{
							m_ItemLocations.Add( reader.ReadItem(), new Point2D( reader.ReadInt(), reader.ReadInt() ) );
						}
					}
					goto case 25;
				}



Find:
Code:
			writer.Write( (int) 25 ); // version
Replace by:
Code:
			writer.Write( (int) 26 ); // version
Add below:
Code:
			if( m_ItemLocations == null )
			{
				writer.Write( (int)0 );
			}
			else
			{
				writer.Write( m_ItemLocations.Count );

				foreach( KeyValuePair<Item, Point2D> kvp in m_ItemLocations )
				{
					writer.Write( kvp.Key );
					writer.Write( kvp.Value.X );
					writer.Write( kvp.Value.Y );
				}
			}
 
i know this is an old post but with newer SVN of RunUO we are having this problem again this helped the problem of blessed items but anything in blessed bags scatter everywhere into backpack out of their blessed bags any ideas?
 

Shino90

Sorceror
The issue of scrambled inventories is no longer present in RunUO 2.1, although, blessed items inside containers will be moved out to your main pack when you die. This is how OSI does it, to prevent blessed items from dropping to your corpse.

This bit of code in Scripts\Mobiles\PlayerMobile.cs's OnBeforeDeath() is responsible for it:
Code:
			if (Backpack != null && !Backpack.Deleted)
			{
				List<Item> ilist = Backpack.FindItemsByType<Item>(FindItems_Callback);

				for (int i = 0; i < ilist.Count; i++)
				{
					Backpack.AddItem(ilist[i]);
				}
			}

If you want, you can remove that code to have items stay in their containers (and thus drop when the container drops). I'd just disable it for staff characters though, because everything they have is blessed. To do that, make the following changes:

Find:
Code:
			if (Backpack != null && !Backpack.Deleted)

Replace by:
Code:
			if (Backpack != null && !Backpack.Deleted && !KeepsItemsOnDeath)

This doesn't cover non-staff players with blessed containers, but I assume you don't have those anyway.
 

UOExtreme

Sorceror
I tried using this script all looks good till you hit writer.Write( (int) 25 ); // version in Runuo 2.4 the only writer is writer.Write( (int) 28 ); // version and I figured that would be the old 25 well guess what live and learn the server booted right up and everything was working great but after restart I got this error Server.Mobiles.PlayerMobile, serial=0x00000001) so after clicking yes it deleted all accounts How do I fix this In the New Runuo 2.4?
 

tindo

Sorceror
This info is outdated. You should not do the above edits. If you are using RunUO 2.1 or higher, the inventories should not be scrambled. However, if you have set your expansion to pre-AOS, then your inventory will be scrambled (thats correct to the Era).

If you are pre-AOS and you don't want scrambled backpack, then do this override in your playermobile:

Code:
public override bool RetainPackLocsOnDeath { get { return true; } }
 

UOExtreme

Sorceror
This info is outdated. You should not do the above edits. If you are using RunUO 2.1 or higher, the inventories should not be scrambled. However, if you have set your expansion to pre-AOS, then your inventory will be scrambled (thats correct to the Era).

If you are pre-AOS and you don't want scrambled backpack, then do this override in your playermobile:

Code:
public override bool RetainPackLocsOnDeath { get { return true; } }

can you please tell me where to place that in Playermobile?
 

tindo

Sorceror
Pretty much anywhere in the class below the constructors. I place it right before the OnBeforeDeath Method in mine:

Code:
private bool FindItems_Callback(Item item)
        {
            if (!item.Deleted && (item.LootType == LootType.Blessed || item.Insured))
            {
                if (this.Backpack != item.ParentEntity)
                {
                    return true;
                }
            }
            return false;
        }
 
        public override bool RetainPackLocsOnDeath { get { return true; } }
       
        public override bool OnBeforeDeath()
        {
            NetState state = NetState;
 
            if ( state != null )
                state.CancelAllTrades();
 
            DropHolding();
 
            if (Core.AOS && Backpack != null && !Backpack.Deleted)
            {
                List<Item> ilist = Backpack.FindItemsByType<Item>(FindItems_Callback);
 
                for (int i = 0; i < ilist.Count; i++)
                {
                    Backpack.AddItem(ilist[i]);
                }
            }
 

UOExtreme

Sorceror
Pretty much anywhere in the class below the constructors. I place it right before the OnBeforeDeath Method in mine:

Code:
private bool FindItems_Callback(Item item)
        {
            if (!item.Deleted && (item.LootType == LootType.Blessed || item.Insured))
            {
                if (this.Backpack != item.ParentEntity)
                {
                    return true;
                }
            }
            return false;
        }
 
        public override bool RetainPackLocsOnDeath { get { return true; } }
     
        public override bool OnBeforeDeath()
        {
            NetState state = NetState;
 
            if ( state != null )
                state.CancelAllTrades();
 
            DropHolding();
 
            if (Core.AOS && Backpack != null && !Backpack.Deleted)
            {
                List<Item> ilist = Backpack.FindItemsByType<Item>(FindItems_Callback);
 
                for (int i = 0; i < ilist.Count; i++)
                {
                    Backpack.AddItem(ilist[i]);
                }
            }
I thank you so so much for this!!!!!! I have one more question to ask you do you know how to set server war timer?? so instead of it being everyday its only one time a week?? Thanks Again!!!
 

tindo

Sorceror
I'm not near my scripts right now, but I know its in the area that handles saves. If I remember correctly, there is a place where you can set the restarts. It will say something like Timespan.Hours to restart after so many hours, just change that to Timespan.Days and set it for 7 days. If you want a specific day, there is a way to set that as well, but I cant remember without looking.

The best solution would be a custom script that on the day you want, overrides the eventsink, turns off saves, then restarts the shard after so long.

Hmm, i might have to write that one, sounds fun, lol
 
Top