Hi guys i try to do special pigment for Spellbooks,NecromancerSpellbook,BookOfChivalry but something is wrong with my script. I all the time hear "You cannot dye that"somebody see my mistake ?

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

namespace Server.Items
{
	public class SpellbookPigment : Item, IUsesRemaining
	{
		public override int LabelNumber { get { return 1070933; } } // Pigments of Tokuno

        private PigmentType m_Type;

		private int m_UsesRemaining;

		[CommandProperty( AccessLevel.GameMaster )]
        public PigmentType Type { get { return m_Type; } set { m_Type = value; } }

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

		public bool ShowUsesRemaining
		{
			get { return true; }
			set
			{
			}
		}

        public int GetHue(PigmentType type)
		{
			int hue = 0;

			switch ( type )
			{
                case PigmentType.ParagonGold:
					hue = 0x501;
					break;
                case PigmentType.VioletCouragePurple:
					hue = 0x486;
					break;
                case PigmentType.InvulnerabilityBlue:
					hue = 0x4F2;
					break;
                case PigmentType.LunaWhite:
					hue = 0x47E;
					break;
                case PigmentType.DryadGreen:
					hue = 0x48F;
					break;
                case PigmentType.ShadowDancerBlack:
					hue = 0x455;
					break;
                case PigmentType.BerserkerRed:
					hue = 0x21;
					break;
                case PigmentType.NoxGreen:
					hue = 0x58C;
					break;
                case PigmentType.RumRed:
					hue = 0x66C;
					break;
                case PigmentType.FireOrange:
					hue = 0x54F;
					break;
			}

			return hue;
		}

		[Constructable]
        public SpellbookPigment(PigmentType type)
            : base(0xEFF)
		{
			m_Type = type;

            Name = "Spellbook";

			Hue = GetHue( type );

			m_UsesRemaining = 1;
		}

		public override void OnDoubleClick( Mobile from )
		{
            if (IsChildOf(from.Backpack))
            {
                from.SendMessage("Select item to dye");
                from.Target = new DyeTarget(this);
            }
            else
            {
                from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
            }			
		}

		public override void GetProperties( ObjectPropertyList list )
		{
			base.GetProperties( list );

			list.Add( 1070987 + (int) m_Type );

			list.Add( 1060584, m_UsesRemaining.ToString() ); // uses remaining: ~1_val~
		}

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

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

			writer.Write( (int) 0 );

			writer.Write( (int) m_Type );

			writer.Write( (int) m_UsesRemaining );
		}

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

			int version = reader.ReadInt();

            m_Type = (PigmentType)reader.ReadInt();

			m_UsesRemaining = reader.ReadInt();
		}

		private class DyeTarget : Target
		{
            private SpellbookPigment dye;

            public DyeTarget(SpellbookPigment m_dye)
                : base(8, false, TargetFlags.None)
			{
				dye = m_dye;
			}			

			public bool CanHue( Item item )
			{
				if (item is Spellbook || item is NecromancerSpellbook || item is BookOfChivalry)
				{
					return true;
				}
				return false;
			}

			protected override void OnTarget( Mobile from, object targeted )
			{
				Item item = targeted as Item;

				if ( item == null )
				{
					return;
				}

				if ( !item.IsChildOf( from.Backpack ) )
				{
					from.SendLocalizedMessage( 1062334 ); // This item must be in your backpack to be used.
				}
                else if (!(item is Spellbook) || !(item is NecromancerSpellbook) || !(item is BookOfChivalry))
				{
					from.SendLocalizedMessage( 1042083 ); // You cannot dye that.
				}				
				else if ( CanHue( item ) )
				{
					item.Hue = dye.GetHue( dye.Type );

					dye.UsesRemaining--;

					if ( dye.UsesRemaining <= 0 )
					{
						dye.Delete();
					}
				}
				else
				{
                    from.SendLocalizedMessage(1042083); // You cannot dye that.
				}
			}
		}
	}
}
 
Maybe in the spellbooks you would need to add IDyable
Just a guess :)
public class NecromancerSpellbook : Spellbook, IDyable
 
else if (!(item is Spellbook) || !(item is NecromancerSpellbook) || !(item is BookOfChivalry))

to

else if (!(item is Spellbook) && !(item is NecromancerSpellbook) && !(item is BookOfChivalry))

Answer:
not a spellbook, not a necrobook, is a chivalry book.
true || true || false.
will pick true, as || means "or" as long as there's one true it will pass thru.

if it's not a book, it will do:
true && true && true
which means it will pass and send an error,
if it's true && true && false, it will not pass thru, as one of those is not at true.
 
Last edited:
Back