So I'm not going to claim to be an expert scripter at all. In fact total newb.

I found this script and have been playing with it in my quest to learn C# and the ServUO world. I can get it to work however for some reason the shield always has double the luck of any of the other three items.

Makes no sense to me. Hoping someone can help.

Or explain what/why it is acting the way that it is.

Thanks in advance!

Current script:

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

namespace Server.Items
{
public class LuckTarget : Target
{
private LuckDeed m_Deed;

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

protected override void OnTarget( Mobile from, object target )
{
if ( target is BaseWeapon || target is BaseShield || target is BaseArmor ) //*| target is BaseJewel |//*
//Note: weapon, basearmor, basejewel get 50 luck, shield is getting 100.
{

int augment = + 50;
int augmentper = + 50;

Item item = (Item)target;
if (item is BaseWeapon)
{
if ( ((BaseWeapon)item).Attributes.Luck >= 200 ) from.SendMessage( "That already has luck!");
else
{
if( item.RootParent != from ) from.SendMessage( "You can not put luck on that there!" );
else
{
((BaseWeapon)item).Attributes.Luck += augmentper;
from.SendMessage( "You magically add luck to your item...." );
m_Deed.Delete();
}
}
}
if (item is BaseShield)//gets 100 luck
{
if ( ((BaseShield)item).Attributes.Luck >= 200 ) from.SendMessage( "That already has luck!");
else
{
if( item.RootParent != from ) from.SendMessage( "You cannot put luck on that there!" );
else
{
((BaseShield)item).Attributes.Luck += augmentper;
from.SendMessage( "You magically add luck to your item...." );
m_Deed.Delete();
}
}
}
if (item is BaseArmor) //gets 50 luck
{
if ( ((BaseArmor)item).Attributes.Luck >= 200 ) from.SendMessage( "That already has luck!");
else
{
if( item.RootParent != from ) from.SendMessage( "You cannot put luck on that there!" );
else
{
((BaseArmor)item).Attributes.Luck += augmentper;
from.SendMessage( "You magically add luck to your item...." );
m_Deed.Delete();
}
}
}
//if (item is BaseJewel) //Gets 50 luck
//{
// if ( ((BaseJewel)item).Attributes.Luck >= 200 ) from.SendMessage( "That already has luck!");
// else
// {
// if( item.RootParent != from ) from.SendMessage( "You cannot put luck on that there!" );
// else
// {
// ((BaseJewel)item).Attributes.Luck += augmentper;
// from.SendMessage( "You magically add luck to your item...." );
// m_Deed.Delete();
// }
// }
//}
}
else from.SendMessage( "You can not put luck on that" );
}
}

public class LuckDeed : Item
{
[Constructable]
public LuckDeed() : base( 0x14F0 )
{
Name = "+100 Luck Increase deed";
Hue = 1260; //100 luck deed use 1260, for 300+ use 1259
Weight = 1.0;
}
public override void GetProperties( ObjectPropertyList list )
{
base.GetProperties( list );

list.Add( "<BASEFONT COLOR=#FFC300>\u0022Armor, Weapon and Shields\u0022<BASEFONT COLOR=#FFC300>" );
}
public LuckDeed(Serial serial) : base(serial){}
public override void Serialize( GenericWriter writer ) {base.Serialize( writer ); writer.Write( (int) 0 );}
public override void Deserialize( GenericReader reader ) { base.Deserialize( reader ); int version = 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 luck to?" );
from.Target = new LuckTarget( this );
}
}
}
}
 
thats because baseshield is also basearmor, and therefor it goes into both if conditions and gets you twice the bonus
 
Well I made it a bit more customizeable, also a little over the top for a luckdeed but why not! :)

To answer your question look at line 189 to 195

C#:
using Server.Targeting;
using System;
using System.Text;

namespace Server.Items
{
    public class LuckDeed : Item
    {
        public static readonly int Luckbonus = 50;
        public static readonly int MaxLuck = 200;
        public override string DefaultName { get { return "+" + Luckbonus + " Luck Increase deed"; } }
        public override double DefaultWeight { get { return 1; } }
        public override bool DisplayLootType { get { return false; } }

        private bool allowWeapon = true;
        private bool allowArmor = true;
        private bool allowShield = true;
        private bool allowJewelry = false;

        [CommandProperty(AccessLevel.GameMaster)]
        public bool AllowWeapon
        {
            get { return allowWeapon; }
            set { allowWeapon = value; InvalidateProperties(); }
        }

        [CommandProperty(AccessLevel.GameMaster)]
        public bool AllowArmor
        {
            get { return allowArmor; }
            set { allowArmor = value; InvalidateProperties(); }
        }

        [CommandProperty(AccessLevel.GameMaster)]
        public bool AllowShield
        {
            get { return allowShield; }
            set { allowShield = value; InvalidateProperties(); }
        }

        [CommandProperty(AccessLevel.GameMaster)]
        public bool AllowJewelry
        {
            get { return allowJewelry; }
            set { allowJewelry = value; InvalidateProperties(); }
        }

        [Constructable]
        public LuckDeed() : base(0x14F0)
        {
            Hue = 1260; //100 luck deed use 1260, for 300+ use 1259
        }

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

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

            list.Add("<BASEFONT COLOR=#FFC300>\u0022" + GetAllowedTypeString() + "\u0022<BASEFONT COLOR=#FFC300>");
        }

        private string GetAllowedTypeString()
        {
            StringBuilder temp = new StringBuilder();

            if (AllowArmor)
                temp.Append("Armor");
            if (AllowJewelry)
            {
                if (temp.Length > 0) temp.Append(", ");
                temp.Append("Jewelry");
            }
            if (AllowShield)
            {
                if (temp.Length > 0) temp.Append(", ");
                temp.Append("Shields");
            }
            if (AllowWeapon)
            {
                if (temp.Length > 0) temp.Append(", ");
                temp.Append("Weapons");
            }

            if (temp.Length > 0)
            {
                int i;
                for (i = temp.Length - 1; i > 0; i--)
                {
                    if (temp[i] == ',')
                        break;
                }
                temp.Replace(",", " and", i, 1);
            }
            else
            {
                temp.Append("No Items allowed! (Disabled)");
            }

            return temp.ToString();
        }

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

            writer.Write(allowArmor);
            writer.Write(allowJewelry);
            writer.Write(allowShield);
            writer.Write(allowWeapon);
        }

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

            if (version >= 1)
            {
                allowArmor = reader.ReadBool();
                allowJewelry = reader.ReadBool();
                allowShield = reader.ReadBool();
                allowWeapon = reader.ReadBool();
            }
        }

        public override void OnDoubleClick(Mobile from)
        {
            if (!IsChildOf(from.Backpack))
                from.SendLocalizedMessage(1042001);
            else
            {
                from.SendMessage("What item would you like to add luck to?");
                from.Target = new LuckTarget(this);
            }
        }
    }

    public class LuckTarget : Target
    {
        private readonly LuckDeed m_Deed;

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

        protected override void OnTarget(Mobile from, object target)
        {
            if (!(target is Item))
            {
                from.SendMessage("You can not put luck on that!");
                return;
            }
            if (((Item)target).RootParent != from)
            {
                from.SendMessage("You can not put luck on that there!");
                return;
            }

            AosAttributes attr = null;

            if (m_Deed.AllowWeapon && target is BaseWeapon)
            {
                attr = ((BaseWeapon)target).Attributes;
            }
            else if (target is BaseShield)
            {
                if (m_Deed.AllowShield)
                    attr = ((BaseShield)target).Attributes;
            }
            else if (m_Deed.AllowArmor && target is BaseArmor)
            {
                attr = ((BaseArmor)target).Attributes;
            }
            else if (m_Deed.AllowJewelry && target is BaseJewel)
            {
                attr = ((BaseJewel)target).Attributes;
            }

            if (attr == null)
            {
                from.SendMessage("You can not put luck on that item!");
                return;
            }

            if (attr.Luck >= LuckDeed.MaxLuck)
            {
                from.SendMessage("That already has enough luck!");
                return;
            }

            attr.Luck = Math.Min(LuckDeed.MaxLuck, attr.Luck + LuckDeed.Luckbonus);
            from.SendMessage("You magically add luck to your item....");
            m_Deed.Delete();
        }
    }
}
 
If you keep at it and look for ways to implement things yourself you will get there, and way further than me :D
 
Back