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!

Bank Box Max Items

have to ad it in the player creation so set its max items

then i have also found out for some reason they like to go back to normal

so i have also put in a line in 1 of the scripts that auto run each time they log in to reset it to the number also

like the motd or simular script
 

Joeku

Lord
"Server\Items\Containers.cs" (RunUO 2.0 SVN Core):
Code:
using System;
using Server.Network;

namespace Server.Items
{
	public class BankBox : Container
	{
[COLOR="Red"]		public override int DefaultMaxItems
		{
			get
			{
				// return base.DefaultMaxItems;
				return 200;
			}
		}[/COLOR]

		private Mobile m_Owner;
		private bool m_Open;
Add the code in red. You can set the "200" to whatever you want.

Make sure to recompile the core to see the changes take effect.
 
Hey thanks for your help : ) I decided on modifying the core, just because I wanted to test my skills, and it seemed like the thing to do.
 

davidovo

Page
Hey I wish to know what do you modify in core wich files wich sentences cause you seems to found the solution for your problem but you dont even show it so everyone who got the same cannot succesfully fix it too, Thanks
 

Vorspire

Knight
This is the minimal amount of code needed to do what you want to do. This code is not safe (for the sake of simplicity in this example), you'd have to add in your own checks for null references.
Rich (BB code):
using System;

using Server;
using Server.Mobiles;

public sealed class Update
{
      public static void Initialize()
      {
              EventSink.Login += delegate( LoginEventArgs e )
              {
                    ((PlayerMobile)e.Mobile).BankBox.MaxItems = 1234;
              };
      }
}
The code above is an entire, single CS file.
 

davidovo

Page
Im maybe noob but what null reference means?? and in wich .cs files I put this script? I know how to add them but in which files in charactercreation.cs ??

Modern was talking bout cores Wo do I had this script in core files?? and if yes wich one .

Theese are the information I wanna know not just the script.

thanks for quick answer
 

Peoharen

Sorceror
I'm bored (waiting on money in Assassin's Creed again).

Null references mean what it sounds like. Null means nothing, it's a reference to nothing.

For instance.
Mobile m = YOU; // Really any mobile.
m.Backpack.Delete(); // If they DON'T have a backpack, calling delete on it IS a null reference, if they do (and they probably do) this deletes it.
m.Backpack.DropItem( new Gold() ); // Invoke their backpack's DropItem, since they don't have a backpack an exception is throw, aka it crashes.

Vorspire's code snippet assumes the mobile is a PlayerMobile (should be) and assumes they have a Bankbox (again should have). In some regards you shouldn't have to check null and in doing so like this is a waste of time. But then again RunUO's community isn't exactly adhering to any real code quality so it's not a bad idea to go ahead and check.

If you really want to get fancy, this is what I coded a while back after seeing someone's idea of a deed to increase bank slots. Only theirs required edits to PlayerMobile and LoginStats when you didn't need to do that at all. I threw in a lot of comments just for you.
Code:
// Created by Peoharen
using System;
using Server;
using Server.Accounting;
using Server.Mobiles;

namespace Server.Items
{
	public class BankStorageIncreaseDeed : Item
	{
		// Maximum bonus these deeds can give is...
		public const int BonusCap = 25;

		// Standard private member with public access a GM can manipulate.
		private int m_BonusSlots;

		[CommandProperty( AccessLevel.GameMaster )]
		public int BonusSlots
		{
			get { return m_BonusSlots; }
			set { m_BonusSlots = value; }
		}

		[Constructable]
		public BankStorageIncreaseDeed( int bonusslots ) : base( 0x14F0 )
		{
			Name = "Bank Storage Increase Deed";
			m_BonusSlots = bonusslots;
		}

		// Adds a special messages at the bottom of the mouse over properties.
		public override void GetProperties( ObjectPropertyList list )
		{
			base.GetProperties( list );
			list.Add( 1114057, ((m_BonusSlots).ToString() + " Bonus Bank Slots") ); // ~1_VAL~
		}

		// This is how the tag is encoded into the account.
		// It uses the mobile's serial, thus only the mobile that uses this can gain the benefit fo it.
		public static string GetTag( Mobile m )
		{
			if ( m == null )
				return String.Empty; // String.Empty is a faster way of checking for ""
			else
				return "Bonus Bank Slots[" + m.Serial.ToString() + "]";
		}

		// OVerride DoubleClick
		public override void OnDoubleClick( Mobile from )
		{
			// Sanity, check for nulls
			if ( from.Backpack == null || Parent != from.Backpack )
				from.SendLocalizedMessage( 1080058 ); // This must be in your backpack to use it.
			else if ( from.Account != null )
			{
				// Convert IAccount to Account
				Account acc = (Account)from.Account;

				// Get the tag and set up for reading the value.
				string tag = GetTag( from );
				int currentbonus = 0;

				// Convert can create an exception if the value cannot be converted to an integer.
				// so we throw it into Try/Catch to prevent the crash.
				try { currentbonus = Convert.ToInt32( acc.GetTag( tag ) ); }
				catch {}

				// Check bonus slots vs cap.
				if ( currentbonus + m_BonusSlots > BonusCap )
					from.SendMessage( "You cannot use another one of these." );
				else
				{
					from.SendMessage( "You increase your maximum item limit for your bank." );
					currentbonus += m_BonusSlots;

					// More sanity, then set max items to default (125) + bonus.
					if ( from.BankBox != null )
						from.BankBox.MaxItems = from.BankBox.DefaultMaxItems + currentbonus;

					// Remove the tag and readd it with the new value.
					acc.RemoveTag( tag );
					acc.AddTag( tag, currentbonus.ToString() );
				}
			}
		}

		// Initialize is call on class creation, IE a way to set up stuff.
		public static void Initialize()
		{
			// This is an event handler, the Login event is triggers when ever someone logs in.
			// By using Events/Delegates we can tap into them from any script without edits to the base script.
			EventSink.Login += delegate( LoginEventArgs e )
			{
				// Sanity
				if ( e.Mobile.Account != null )
				{
					// Same as before really.
					Account acc = (Account)e.Mobile.Account;
					int currentbonus = 0;

					try { currentbonus = Convert.ToInt32( acc.GetTag( GetTag( e.Mobile ) ) ); }
					catch {}

					if ( e.Mobile.BankBox != null && currentbonus > 0 )
						e.Mobile.BankBox.MaxItems = e.Mobile.BankBox.DefaultMaxItems + currentbonus;
				}
			};
		}

		public BankStorageIncreaseDeed( Serial serial ) : base( serial )
		{
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );
			writer.Write( (int) 0 ); // version

			// Save the bunus slots if the deed isn't used and instead traded or sold.
			writer.Write( (int) m_BonusSlots );
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );
			int version = reader.ReadInt();

			// Load the bonus slots.
			m_BonusSlots = reader.ReadInt();
		}
	}
}
Script compiles, never used it though. I'm probably the laziest guy you could know about that kind of thing.
 

Pyro-Tech

Knight
I was looking for a way to do this without the edits described in Hank the Drunk's post....I have a question....

Couldn't you do this by accessing the "equipped" bank box of the playermobile? Therefore making this per character instead of per account.

If so, how would you change the code that Peoharen gave?

EDIT: FYI for the OP, the code Peoharen gave doesn't delete the Deed when used.
 

jargo2000

Sorceror
I was looking for a way to do this without the edits described in Hank the Drunk's post....I have a question....

Couldn't you do this by accessing the "equipped" bank box of the playermobile? Therefore making this per character instead of per account.

If so, how would you change the code that Peoharen gave?

EDIT: FYI for the OP, the code Peoharen gave doesn't delete the Deed when used.

I have that script compiled in my server but I am unsure on how to use it in game(what command)
I searched for a Deed by that name but found none.
 

Pyro-Tech

Knight
you can't add just the deed as it wants a value associated with it....

Use the command [BankStorageIncreaseDeed 50 for example to give a deed that adds 50

Or alternativly, you can add the following ribht above the [constructable] method that's in there;

Code:
        [Constructable]
        public BankStorageIncreaseDeed() : this( 25 )
        {
        }

and it will let you add the item without needing to provide an argument. change the 25 to whatever you want the default to be.

If you want it to update the properties when you change the value of the number of slots added, you will need to change the command a bit to as follows (change in red);

Code:
        [CommandProperty( AccessLevel.GameMaster )]
        public int BonusSlots
        {
            get { return m_BonusSlots; }
            set { m_BonusSlots = value; InvalidateProperties(); }
        }

EDIT: Removed the color tag as it seems like the forums don't like color :L
 
Top