Go Back   RunUO - Ultima Online Emulation > RunUO > Script Support

Script Support Get support for modifying RunUO Scripts, or writing your own!

Reply
 
Thread Tools Display Modes
Old 03-16-2009, 12:40 PM   #1 (permalink)
Forum Novice
 
siran's Avatar
 
Join Date: Dec 2003
Location: Shreveport, Louisiana
Age: 51
Posts: 499
Send a message via Yahoo to siran
Default adding charges to dye tubs

I have added charges to dyes and dye tubs. However, because I am consuming a charge on the dyes in the double click method, it is consumed even if the dyeing attempt is unsucessful (i.e. you are too far away). When I try to move this into the targeting methods, I can't find a way to do it and compile. Any suggestions?

Code:
using System;
using Server.Targeting;
using Server.HuePickers;

namespace Server.Items
{
	public class Dyes : BaseItem // byron 3/13/09
	{
		// byron 3/13/09 - add dye charges***********************************************************
		private int charges;
		[CommandProperty (AccessLevel.GameMaster)]
		public int Charges
		{
			get {return charges;}
			set {charges = value;}
		}
		//*******************************************************************************************
		
		[Constructable]
		public Dyes() : base( 0xFA9 )
		{
			Weight = 3.0;
			Charges = 50; // byron 3/13/09 - add charges
		}

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

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
			writer.Write (charges); // byron 3/13/09 charges
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();
			int charges = reader.ReadInt (); // byron 3/13/09 charges
			if ( Weight == 0.0 )
				Weight = 3.0;
		}

		public override void OnDoubleClick( Mobile from )
		{
			from.SendLocalizedMessage( 500856 ); // Select the dye tub to use the dyes on.
			from.Target = new InternalTarget();
			// byron 3/13/09 - add charges ***************************************************************
				Charges -= 1;
				if (Charges < 1)
					this.Delete ();
			//********************************************************************************************
		}

		private class InternalTarget : Target
		{
			public InternalTarget() : base( 1, false, TargetFlags.None )
			{
			}

			private class InternalPicker : HuePicker
			{
				private DyeTub m_Tub;

				public InternalPicker( DyeTub tub ) : base( tub.ItemID )
				{
					m_Tub = tub;
				}

				public override void OnResponse( int hue )
				{
					m_Tub.DyedHue = hue;
					m_Tub.Charges = 20; // byron 3/13/09 add charges
				}
			}

			private static void SetTubHue( Mobile from, object state, int hue )
			{
				((DyeTub)state).DyedHue = hue;
			}

			protected override void OnTarget( Mobile from, object targeted )
			{
				if ( targeted is DyeTub )
				{
					DyeTub tub = (DyeTub) targeted;

					if ( tub.Redyable )
					{
						if ( tub.CustomHuePicker == null )
							from.SendHuePicker( new InternalPicker( tub ) );
						else
							from.SendGump( new CustomHuePickerGump( from, tub.CustomHuePicker, new CustomHuePickerCallback( SetTubHue ), tub ) );
					}
					else if ( tub is BlackDyeTub )
					{
						from.SendLocalizedMessage( 1010092 ); // You can not use this on a black dye tub.
					}
					else
					{
						from.SendMessage( "That dye tub may not be redyed." );
					}
				}
				else
				{
					from.SendLocalizedMessage( 500857 ); // Use this on a dye tub.
				}
			}
		}
	}
}
__________________
The valiant die but once.

I have died many times.
siran is offline   Reply With Quote
Old 03-16-2009, 02:00 PM   #2 (permalink)
Master of the Internet
 
Lord_Greywolf's Avatar
 
Join Date: Dec 2005
Posts: 12,206
Send a message via Yahoo to Lord_Greywolf
Default

i will get you started on it, you will have to finish off the targeting part (where your red line will go into in the right spot and using "thedyes" instead of "this".

change
from.Target = new InternalTarget();
to
from.Target = new InternalTarget(this);

then start of below:
Code:
		private class InternalTarget : Target
		{
			public InternalTarget() : base( 1, false, TargetFlags.None )
			{
			}
to this
Code:
		private class InternalTarget : Target
		{
			private Dyes thedyes;
			public InternalTarget(Dyes dummy) : base( 1, false, TargetFlags.None )
			{
				thedyes = dummy;
			}
now you have to figure the rest out
__________________
http://www.AoAUO.com

:) ..... Come for the Customs, Play for the Fun. Return to see your new Friends ..... :)
Lord_Greywolf is offline   Reply With Quote
Old 03-16-2009, 03:00 PM   #3 (permalink)
Forum Novice
 
siran's Avatar
 
Join Date: Dec 2003
Location: Shreveport, Louisiana
Age: 51
Posts: 499
Send a message via Yahoo to siran
Default

If I change

from.Target = new InternalTarget ();

to

from.Target = new InternalTarget (this);

I then get the error that there is no overload method for InternalTarget that will take 1 argument.

I am guessing I should modify the InternalTarget method to receive the variable?
__________________
The valiant die but once.

I have died many times.
siran is offline   Reply With Quote
Old 03-16-2009, 03:11 PM   #4 (permalink)
Forum Novice
 
siran's Avatar
 
Join Date: Dec 2003
Location: Shreveport, Louisiana
Age: 51
Posts: 499
Send a message via Yahoo to siran
Default

I got it working; thanks much Greywolf. Your posts are always helpful.

For those who may wonder, here is the working code:

Code:
using System;
using Server.Targeting;
using Server.HuePickers;

namespace Server.Items
{
	public class Dyes : BaseItem // byron 3/13/09
	{
		// byron 3/13/09 - add dye charges***********************************************************
		private int charges;
		[CommandProperty (AccessLevel.GameMaster)]
		public int Charges
		{
			get {return charges;}
			set {charges = value;}
		}
		//*******************************************************************************************
		
		[Constructable]
		public Dyes() : base( 0xFA9 )
		{
			Weight = 3.0;
			Charges = 50; // byron 3/13/09 - add charges
		}

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

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 0 ); // version
			writer.Write (charges); // byron 3/13/09 charges
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();
			int charges = reader.ReadInt (); // byron 3/13/09 charges
			if ( Weight == 0.0 )
				Weight = 3.0;
		}

		public override void OnDoubleClick( Mobile from )
		{
			from.SendLocalizedMessage( 500856 ); // Select the dye tub to use the dyes on.
			from.Target = new InternalTarget(this);
			}

		private class InternalTarget : Target
		{
			private Dyes dyes; // byron 3/16/09
			
			public InternalTarget(Dyes m_dyes) : base( 1, false, TargetFlags.None )
			{
				dyes = m_dyes; // byron 3/16/09
			}

			private class InternalPicker : HuePicker
			{
				private DyeTub m_Tub;
				
				public InternalPicker( DyeTub tub ) : base( tub.ItemID )
				{
					m_Tub = tub;
				}

				public override void OnResponse( int hue )
				{
					m_Tub.DyedHue = hue;
					m_Tub.Charges = 20; // byron 3/16/09
				}
			}

			private static void SetTubHue( Mobile from, object state, int hue )
			{
				((DyeTub)state).DyedHue = hue;
			}

			protected override void OnTarget( Mobile from, object targeted )
			{
				if ( targeted is DyeTub )
				{
					DyeTub tub = (DyeTub) targeted;

					if ( tub.Redyable )
					{
						if ( tub.CustomHuePicker == null )
							from.SendHuePicker( new InternalPicker( tub ) );
						else
							from.SendGump( new CustomHuePickerGump( from, tub.CustomHuePicker, new CustomHuePickerCallback( SetTubHue ), tub ) );
						// byron 3/16/09 add charges ***********************************************************
						dyes.Charges -= 1;
						if (dyes.Charges < 1)
						dyes.Delete ();
					//****************************************************************************
				
					}
					else if ( tub is BlackDyeTub )
					{
						from.SendLocalizedMessage( 1010092 ); // You can not use this on a black dye tub.
					}
					else
					{
						from.SendMessage( "That dye tub may not be redyed." );
					}
				}
				else
				{
					from.SendLocalizedMessage( 500857 ); // Use this on a dye tub.
				}
			}
		}
	}
}
__________________
The valiant die but once.

I have died many times.
siran is offline   Reply With Quote
Old 07-04-2009, 05:26 AM   #5 (permalink)
Forum Novice
 
Join Date: Jan 2006
Location: Russian Federation, Moscow
Posts: 163
Send a message via ICQ to Goury Send a message via Skype™ to Goury
Default

tried some
Code:
        public override void GetProperties( ObjectPropertyList list )
        {
            base.GetProperties( list );
            list.Add( 1060584, this.Charges.ToString() ); // uses remaining: ~1_val~
        }
but this.Charges.ToString() always returns zero
need help
Goury is offline   Reply With Quote
Old 07-04-2009, 06:18 AM   #6 (permalink)
Lurker
 
Join Date: Jun 2007
Posts: 13
Default

That's right. Because your deserialize method was wrong. You should also call InvalidateProperties() in property 'Charges'.

Valid code:

Code:
using System;
using Server.Targeting;
using Server.HuePickers;

namespace Server.Items
{
    public class Dyes : Item 
    {
        private int m_Charges;

        [CommandProperty( AccessLevel.GameMaster )]
        public int Charges
        {
            get { return m_Charges; }
            set { m_Charges = value; InvalidateProperties(); }
        }

        [Constructable]
        public Dyes() : base( 0xFA9 )
        {
            Weight = 3.0;
            Charges = 50; 
        }

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

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );

            writer.Write( ( int )1 ); // version
            writer.Write( m_Charges );//V1
        }

        public override void GetProperties( ObjectPropertyList list )
        {
            base.GetProperties( list );
            list.Add( 1060584, m_Charges.ToString() ); // uses remaining: ~1_val~
        }

        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );

            int version = reader.ReadInt();

            switch( version )
            {
                case 1:
                    {
                        m_Charges = reader.ReadInt();
                        goto case 0;
                    }
                case 0:
                    break;
            }

            if( version == 0 && m_Charges == 0 )
                m_Charges = 50;

            if( Weight == 0.0 )
                Weight = 3.0;
        }

        public override void OnDoubleClick( Mobile from )
        {
            from.SendLocalizedMessage( 500856 ); // Select the dye tub to use the dyes on.
            from.Target = new InternalTarget( this );
        }

        private class InternalTarget : Target
        {
            private Dyes m_Dyes;

            public InternalTarget( Dyes dyes ) : base( 1, false, TargetFlags.None )
            {
                m_Dyes = dyes;
            }

            private class InternalPicker : HuePicker
            {
                private DyeTub m_Tub;

                public InternalPicker( DyeTub tub ) : base( tub.ItemID )
                {
                    m_Tub = tub;
                }

                public override void OnResponse( int hue )
                {
                    m_Tub.DyedHue = hue;
                   // m_Tub.Charges = 20; // byron 3/16/09 //??????
                }
            }

            private static void SetTubHue( Mobile from, object state, int hue )
            {
                ( ( DyeTub )state ).DyedHue = hue;
            }

            protected override void OnTarget( Mobile from, object targeted )
            {
                if( targeted is DyeTub )
                {
                    DyeTub tub = ( DyeTub )targeted;

                    if( tub.Redyable )
                    {
                        if( tub.CustomHuePicker == null )
                            from.SendHuePicker( new InternalPicker( tub ) );
                        else
                            from.SendGump( new CustomHuePickerGump( from, tub.CustomHuePicker, new CustomHuePickerCallback( SetTubHue ), tub ) );

                        --m_Dyes.Charges;

                        if( m_Dyes.Charges < 1 )
                            m_Dyes.Delete();

                    }
                    else if( tub is BlackDyeTub )
                    {
                        from.SendLocalizedMessage( 1010092 ); // You can not use this on a black dye tub.
                    }
                    else
                    {
                        from.SendMessage( "That dye tub may not be redyed." );
                    }
                }
                else
                {
                    from.SendLocalizedMessage( 500857 ); // Use this on a dye tub.
                }
            }
        }
    }
}

Remember Goury: when You post a piece of code you should also post all connected scripts. We don't have a class named BaseItem.
Andreew is offline   Reply With Quote
Old 07-04-2009, 07:45 AM   #7 (permalink)
Forum Novice
 
Join Date: Jan 2006
Location: Russian Federation, Moscow
Posts: 163
Send a message via ICQ to Goury Send a message via Skype™ to Goury
Default

Andreew, my dyes script looks like one in siran's post
tnx u
Goury 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 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5