I have worked on this script now for over three days. Yes I know . . silly fellow.

I have been trying to make a quest reward 'Shroud' with the following features:
1) it turns the wearer Invisible
2) it increases the the wearer's Hiding and Stealth skill while worn
3) it gets removed after a short period of time (I used 10 seconds for testing) so they cannot just walk around with it on all the time
4) it resets their Hiding and Stealth skill when it gets removed
5) it has a limited number of uses (10)
6) it drops into their backpack when it gets removed and shows the reduced number of uses

The script I made compiles and everything seems to work 'Except' the new Shroud that gets dropped into their backpack does not show the correct reduced number of uses. Actually the new Shroud shows zero uses.

I am not able to carry the value of UsesRemaining from the Shroud into the Shroud's Timer . . . just too much above my scripting grade.

My last attempt to get this working gives me an Error.

Here is the error:
Code:
Errors:
+ Customs/Quest Invisibility/Items/InvisibilityShroud.cs:
    CS0038: Line 209: Cannot access a non-static member of outer type 'Server.Items.InvisibilityShroud' via nested type 'Server.Items.InvisibilityShroud.ShowTimer'

and . . here is my script as it currently stands:
Code:
using System;
using Server;
using Server.Misc;
using Server.Items;
using Server.Network;
using Server.Mobiles;
using Server.Targeting;
using Server.Accounting;
using System.Collections;
using Server.ContextMenus;
using System.Globalization;
using System.Collections.Generic;

namespace Server.Items
{
    [Flipable( 0x2684, 0x2683 )]
    public class InvisibilityShroud : BaseOuterTorso, IUsesRemaining
    {
            private Timer st;

        private SkillMod m_SkillMod0;
        private SkillMod m_SkillMod1;

        private int m_UsesRemaining;
        private bool m_ShowUsesRemaining;

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

        [CommandProperty(AccessLevel.GameMaster)]
        public virtual bool ShowUsesRemaining
        {
            get { return m_ShowUsesRemaining; }
            set
            {
                m_ShowUsesRemaining = value;
                InvalidateProperties();
            }
        }

        [Constructable]
        public InvisibilityShroud() : this( 10 )
        {
        }

        [Constructable]
        public InvisibilityShroud( int uses ) : base(0x2684)
        {
            Weight = 0.0;
            Hue = 2955;
            Name = "Elven Cloak of Invisibility";

            Identified = true;

            LootType = LootType.Blessed;
            Attributes.NightSight = 1;
            Attributes.ReflectPhysical = 10;
            Attributes.BonusHits = 5;
            Attributes.BonusMana = 5;
            Attributes.LowerRegCost = 5;
            Attributes.LowerManaCost = 5;

            DefineMods();

            m_UsesRemaining = uses;
            m_ShowUsesRemaining = true;
        }

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

            if ( m_UsesRemaining >= 0 && m_ShowUsesRemaining)
            {
                    list.Add(1060584, m_UsesRemaining.ToString(CultureInfo.InvariantCulture)); // uses remaining: ~1_val~
            }
        }

        private void DefineMods()
        {
            m_SkillMod0 = new DefaultSkillMod( SkillName.Hiding, true, 120 );
            m_SkillMod1 = new DefaultSkillMod( SkillName.Stealth, true, 120 );
        }

        private void SetMods( Mobile wearer )
        {          
            wearer.AddSkillMod( m_SkillMod0 );
            wearer.AddSkillMod( m_SkillMod1 );
        }

        public override bool OnEquip( Mobile from )
        {
            SetMods( from );

            if (from.Hidden == false)
            {
                from.Hidden = true;
            }

            st = new ShowTimer(from);
            st.Start();

            if ( m_UsesRemaining > 0 )
            {
                m_UsesRemaining -= 1;
                InvalidateProperties();
                from.SendMessage( "a veil falls over you" );
            }
            return true;
        }

        public override void OnRemoved( object parent )
        {
            if ( parent is Mobile )
            {
                Mobile m = (Mobile)parent;

                if (m.Hidden == true)
                {
                    m.Hidden = false;
                }

                m.SendMessage( "the veil is lifted" );

                if ( m.Hits > m.HitsMax )
                    m.Hits = m.HitsMax;

                if ( m_SkillMod0 != null )
                    m_SkillMod0.Remove();

                if ( m_SkillMod1 != null )
                    m_SkillMod1.Remove();

                if ( m_UsesRemaining < 1 )
                {
                    this.Delete();
                    return;
                }
            }
        }

        public InvisibilityShroud( Serial serial ) : base( serial )
        {
            DefineMods();

            if ( Parent != null && this.Parent is Mobile )
                SetMods( (Mobile)Parent );
        }

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
            writer.Write(2); // version

            writer.Write(m_UsesRemaining);
            writer.Write(m_ShowUsesRemaining);
        }

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

            switch (version)
            {
                case 2:
                {
                    m_UsesRemaining = reader.ReadInt();
                    m_ShowUsesRemaining = reader.ReadBool();
                }
                goto case 1;
                case 1:
                case 0:
                break;
            }
        }

        public override void GetProperties( ObjectPropertyList list )
         {
             base.GetProperties( list );
            list.Add( "<BASEFONT COLOR=#75FBEB>Crafted by Corellon Larethian" );
         }

        private class ShowTimer : Timer
        {
            private Mobile m_Mobile;
            private Item outertorso;
            private InvisibilityShroud _Shroud;
            //private int m_UsesRemaining;
            private int lefttogo;

            public ShowTimer( Mobile drunk ) : base( TimeSpan.FromSeconds( 5.0 ), TimeSpan.FromSeconds( 5.0 ) )
            {
                m_Mobile = drunk;

                Priority = TimerPriority.OneSecond;
            }

            protected override void OnTick()
            {
                lefttogo = m_UsesRemaining;

                if ( m_Mobile.Deleted || m_Mobile.Map == Map.Internal )
                {
                    if (m_Mobile.Hidden == true)
                    {
                        Item outertorso = m_Mobile.FindItemOnLayer(Layer.OuterTorso);
                        if (outertorso != null && outertorso is InvisibilityShroud)
                        {
                            outertorso.Delete();

                            _Shroud = (new InvisibilityShroud());
                            _Shroud.m_UsesRemaining = lefttogo;

                            m_Mobile.AddToBackpack(_Shroud);

                            m_Mobile.Hidden = false;
                        }
                    }
                    Stop();
                }

                else if ( m_Mobile.Alive )
                {
                    if (m_Mobile.Hidden == true)
                    {
                        Item outertorso = m_Mobile.FindItemOnLayer(Layer.OuterTorso);

                        if (outertorso != null && outertorso is InvisibilityShroud)
                        {
                            outertorso.Delete();

                            _Shroud = (new InvisibilityShroud());
                            _Shroud.m_UsesRemaining = lefttogo;

                            m_Mobile.AddToBackpack(_Shroud);

                            m_Mobile.Hidden = false;
                            m_Mobile.SendMessage( "the veil is lifted" );
                        }
                    }

                    Stop();
                }
            }
        }
    }
}

If anyone knows how to solve this it would be appreciated.

Many Thanks
 
Hey,

the reason you're getting that error is because you are trying to access the variable in the shroud, you need to store the shroud somewhere and then access it from that variable. (See this link: Compiler Error CS0038)

I modified your code, you pretty much overcomplicated the timer, it is much simpler and you also don't need to create the shroud new each time :)

haven't tested it but i think this should work:

C#:
using System;
using Server;
using Server.Misc;
using Server.Items;
using Server.Network;
using Server.Mobiles;
using Server.Targeting;
using Server.Accounting;
using System.Collections;
using Server.ContextMenus;
using System.Globalization;
using System.Collections.Generic;

namespace Server.Items
{
    [Flipable( 0x2684, 0x2683 )]
    public class InvisibilityShroud : BaseOuterTorso, IUsesRemaining
    {
        private Timer st;

        private SkillMod m_SkillMod0;
        private SkillMod m_SkillMod1;

        private int m_UsesRemaining;
        private bool m_ShowUsesRemaining;

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

        [CommandProperty(AccessLevel.GameMaster)]
        public virtual bool ShowUsesRemaining
        {
            get { return m_ShowUsesRemaining; }
            set
            {
                m_ShowUsesRemaining = value;
                InvalidateProperties();
            }
        }

        [Constructable]
        public InvisibilityShroud() : this( 10 )
        {
        }

        [Constructable]
        public InvisibilityShroud( int uses ) : base(0x2684)
        {
            Weight = 0.0;
            Hue = 2955;
            Name = "Elven Cloak of Invisibility";

            Identified = true;

            LootType = LootType.Blessed;
            Attributes.NightSight = 1;
            Attributes.ReflectPhysical = 10;
            Attributes.BonusHits = 5;
            Attributes.BonusMana = 5;
            Attributes.LowerRegCost = 5;
            Attributes.LowerManaCost = 5;

            DefineMods();

            m_UsesRemaining = uses;
            m_ShowUsesRemaining = true;
        }

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

            if ( m_UsesRemaining >= 0 && m_ShowUsesRemaining)
            {
                    list.Add(1060584, m_UsesRemaining.ToString(CultureInfo.InvariantCulture)); // uses remaining: ~1_val~
            }
        }

        private void DefineMods()
        {
            m_SkillMod0 = new DefaultSkillMod( SkillName.Hiding, true, 120 );
            m_SkillMod1 = new DefaultSkillMod( SkillName.Stealth, true, 120 );
        }

        private void SetMods( Mobile wearer )
        {         
            wearer.AddSkillMod( m_SkillMod0 );
            wearer.AddSkillMod( m_SkillMod1 );
        }

        public override bool OnEquip( Mobile from )
        {
            SetMods( from );

            if (from.Hidden == false)
            {
                from.Hidden = true;
            }

            st = new ShowTimer(from, this);
            st.Start();

            if ( m_UsesRemaining > 0 )
            {
                m_UsesRemaining -= 1;
                InvalidateProperties();
                from.SendMessage( "a veil falls over you" );
            }
            return true;
        }

        public override void OnRemoved( object parent )
        {
            if (st != null)
                st.Stop();

            if ( parent is Mobile )
            {
                Mobile m = (Mobile)parent;

                if (m.Hidden == true)
                {
                    m.Hidden = false;
                }

                m.SendMessage( "the veil is lifted" );

                if ( m.Hits > m.HitsMax )
                    m.Hits = m.HitsMax;

                if ( m_SkillMod0 != null )
                    m_SkillMod0.Remove();

                if ( m_SkillMod1 != null )
                    m_SkillMod1.Remove();

                if ( m_UsesRemaining < 1 )
                {
                    this.Delete();
                    return;
                }
            }
        }

        public InvisibilityShroud( Serial serial ) : base( serial )
        {
            DefineMods();

            if ( Parent != null && this.Parent is Mobile )
                SetMods( (Mobile)Parent );
        }

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
            writer.Write(2); // version

            writer.Write(m_UsesRemaining);
            writer.Write(m_ShowUsesRemaining);
        }

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

            switch (version)
            {
                case 2:
                {
                    m_UsesRemaining = reader.ReadInt();
                    m_ShowUsesRemaining = reader.ReadBool();
                }
                goto case 1;
                case 1:
                case 0:
                break;
            }
        }

        public override void GetProperties( ObjectPropertyList list )
         {
             base.GetProperties( list );
            list.Add( "<BASEFONT COLOR=#75FBEB>Crafted by Corellon Larethian" );
         }

        private class ShowTimer : Timer
        {
            Mobile _drunk;
            InvisibilityShroud _shroud;

            public ShowTimer(Mobile drunk, InvisibilityShroud shroud) : base(TimeSpan.FromSeconds(5))
            {
                Priority = TimerPriority.OneSecond;

                _drunk = drunk;
                _shroud = shroud;
            }

            protected override void OnTick()
            {
                if (!_drunk.Deleted && _drunk.Map != Map.Internal && _drunk.Alive && _drunk.Hidden)
                {
                    _shroud.m_UsesRemaining--;
                    _drunk.Hidden = false;
                    _drunk.AddToBackpack(_shroud);
                    _drunk.SendMessage("The veil is lifted");
                }
            }
        }
    }
}
 
Last edited:
Well I can think of two words . . . Wow and WOW.

I appreciate this a lot both for speed and for success. You not only helped me solve a problem, you also taught me something that I hope will avoid a similar one later.

While I'm not great at 'speaking C# I do know enough of it to appreciate when I see it 'spoken' so eloquently as is is from you.

Many thanks.

*bows*
 
Back