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!

"Bug" with keys

Manu

Knight
"Bug" with keys

Keys can be used anywhere. Therefore it is possible to place a key in its matching container and use the key to lock the container. The player is now unable to open the container (lockpicking would be a way of getting it open again,though).

To prevent this I modified the key.cs so that keys can only be used while in your backpack. Simply find

Code:
		public override void OnDoubleClick( Mobile from )
		{
			Target t;
			int number;

			if ( m_KeyVal != 0 )
			{
				number = 501662; // What shall I use this key on?
				t = new UnlockTarget( this );
			}
			else
			{
				number = 501663; // This key is a key blank. Which key would you like to make a copy of?
				t = new CopyTarget( this );
			}

			from.SendLocalizedMessage( number );
			from.Target = t;
		}

and replace it with

Code:
		public override void OnDoubleClick( Mobile from )
		{
			if ( IsChildOf( from.Backpack ) )
			{

			Target t;
			int number;

			if ( m_KeyVal != 0 )
			{
				number = 501662; // What shall I use this key on?
				t = new UnlockTarget( this );
			}
			else
			{
				number = 501663; // This key is a key blank. Which key would you like to make a copy of?
				t = new CopyTarget( this );
			}

			from.SendLocalizedMessage( number );
			from.Target = t;

			}

			else
			{
			from.SendMessage( "That must be in your backpack to use it." );
			}
		}

or use the attached file.
 

Attachments

  • Key.cs
    7.5 KB · Views: 16

Phantom

Knight
This isn't exactly a bug :)

I think its possible to do this on the official servers, of course lockpicking is alot better, lets just say that skill has alot of work ahead of it.
 

Manu

Knight
Yeah, I know, thats why I used *"Bug"* as a title. I just thought it to be a stupid and not very realistic thing to happen :) So now folks know and anyone who agrees with me can change it.
 

DaZiL

Wanderer
*downloads attached file..

ignores useless information manu posted.

types the letters ' jk ' and places a '.' after it. *

jk.
 

Sathallrin

Sorceror
Manu, not that your solution is a bad one, but this also makes it so that it must be in your backpack to use... This way you can't use it from the ground, a secure container, your bank, or if the key is in any other bag in your pack.

A possible better solution would be simple to prevent the key from locking the container if it is inside of the container it is locking. Here is the change needed to prevent that.

Change this code:
Code:
else if ( targeted is ILockable )
{
	number = -1;

	ILockable o = (ILockable)targeted;

	if ( o.KeyValue == m_Key.KeyValue )
	{
		if ( o is BaseDoor && !((BaseDoor)o).UseLocks() )
		{
			number = 501668; // This key doesn't seem to unlock that.
		}

To this:
Code:
else if ( targeted is ILockable )
{
	number = -1;

	ILockable o = (ILockable)targeted;

	if ( m_Key.IsChildOf( o ) )
	{
		from.SendMessage( "You cannot lock this container with the key inside of it." );
	}
	else if ( o.KeyValue == m_Key.KeyValue )
	{
		if ( o is BaseDoor && !((BaseDoor)o).UseLocks() )
		{
			number = 501668; // This key doesn't seem to unlock that.
		}

This works if the key is inside the target, or any sub containers of the target lockable container.
 
Top