Redsnow

Member
Having a problem a with 2 lines below:

Code:
Errors:
+ Customs/2-15-14/UseBest SkillDeed.cs:
  CS0103: Line 28: The name 'Attributes' does not exist in the current context
  CS0103: Line 36: The name 'Attributes' does not exist in the current context


Code:
using System;
using Server.Network;
using Server.Prompts;
using Server.Items;
using Server.Targeting;

namespace Server.Items
{
    public class UseBestSkillTarget : Target // Create our targeting class (which we derive from the base target class)
    {
        private UseBestSkillDeed m_Deed;

        public UseBestSkillTarget(UseBestSkillDeed deed)
            : base(1, false, TargetFlags.None)
        {
            m_Deed = deed;
        }

        protected override void OnTarget(Mobile from, object target) // Override the protected OnTarget() for our feature
        {
            if (m_Deed.Deleted || m_Deed.RootParent != from)
                return;

            if (target is Item)
            {
                Item item = (Item)target;

                if ((BaseWeapon)target == WeaponAttributes.UseBestSkill += 1)////PROBLEM
                {
                    from.SendMessage("Use Best Weapon can not be added to that Item");
                }

            }
            else if (target is BaseWeapon)
            {
                target == WeaponAttributes.UseBestSkill = 1; //////PROBLEM

                from.SendMessage("you use the deed on that weapon");

                m_Deed.Delete(); // Delete the deed
            }
            else
                from.SendMessage("Use Best Weapon can not be added to that Item");
        }
    }

    public class UseBestSkillDeed : Item
    {
        public override string DefaultName
        {
            get { return "an use best skill deed"; }
        }

        [Constructable]
        public UseBestSkillDeed()
            : base(0x14F0)
        {
            Weight = 1.0;
            LootType = LootType.Blessed;
        }

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

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

            writer.Write((int)0); // version
        }

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

            int version = reader.ReadInt();
        }

        public override bool DisplayLootType { get { return false; } }

        public override void OnDoubleClick(Mobile from) // Override double click of the deed to call our target
        {
            if (!IsChildOf(from.Backpack)) // Make sure its in their pack
            {
                from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
            }
            else
            {
                from.SendMessage("Which item do you wish to put Best Skill on?");

                from.Target = new UseBestSkillTarget(this); // Call our target
            }
        }
    }
}



Any Suggestions on how I can fix this? or write it better?
 
You have a few problems in that script.

Check out this one I just made and compare it with yours.

I f you're not using vitanexcore then remove .WrapUOHtmlColor(Color.SkyBlue) at line 68

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

namespace Server.Items
{
    public class UseBestSkillTarget : Target
    {
        private readonly UseBestSkillDeed _mDeed;

        public UseBestSkillTarget(UseBestSkillDeed deed)
            : base(1, false, TargetFlags.None)
        {
            _mDeed = deed;
        }

        protected override void OnTarget(Mobile from, object target)
        {
            var weapon = target as BaseWeapon;
            if (weapon == null)
            {
                @from.SendMessage("You cannot put Use Best Skill on that");
            }
            else
            {
                var item = (Item)target;

                if (((BaseWeapon)item).WeaponAttributes.UseBestSkill == 1)
                {
                    @from.SendMessage("That already has Use Best Skill!");
                }
                else
                {
                    if (item.RootParent != @from)
                    {
                        @from.SendMessage("You cannot put Use Best Skill on that there!");
                    }
                    else
                    {
                        ((BaseWeapon)item).WeaponAttributes.UseBestSkill = 1;
                        @from.SendMessage("You magically add Use Best Skill to your weapon....");

                        _mDeed.Delete();
                    }
                }
            }
        }
    }

    public sealed class UseBestSkillDeed : Item
    {
        [Constructable]
        public UseBestSkillDeed()
            : base(0x14F0)
        {
            Weight = 1.0;
            Name = "a Use Best Skill deed";
            LootType = LootType.Blessed;
            Hue = 0x492;
        }

        public UseBestSkillDeed(Serial serial)
            : base(serial)
        {
        }
        public override void GetProperties(ObjectPropertyList list)
        {
            var add = String.Format("Makes your weapon use your best combat skill".WrapUOHtmlColor(Color.SkyBlue));

            base.GetProperties(list);
            list.Add(add);
        }

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

            writer.Write(0); // version
        }

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

            reader.ReadInt();
        }

        public override bool DisplayLootType { get { return false; } }

        public override void OnDoubleClick(Mobile from)
        {
            if (!IsChildOf(from.Backpack))
            {
                from.SendLocalizedMessage(1042001);
            }
            else
            {
                from.SendMessage("What item would you like to add Use Best Skill to?");
                from.Target = new UseBestSkillTarget(this);
            }
        }
    }
}
 
Last edited:
Code:
if ((BaseWeapon)target == WeaponAttributes.UseBestSkill += 1)////PROBLEM
Couple things wrong with this statement. First it's trying to say 'If BaseWeapon equals WeaponAttributes.UseBestSkill' which aren't two comparable types. Second problem is the += 1 assignment at the end. That's going to keep adding 1 to it everytime it checks instead of checking if it is 1. dmurphys code above has the correct answer for you which should be.
Code:
if (((BaseWeapon)target).WeaponAttributes.UseBestSkill == 1)
One other thing you are missing is first checking the item is a BaseWeapon first because if you use that code on say Armor the server will crash when it tries to do the BaseWeapon cast. You can use something simple like this or dmurphy code has a check as well that will work.
Code:
if (target is BaseWeapon)


You should be able to fix the second problem you have the same way.
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back