RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Half Life Bow ( Self Delete Timer + Timer In Attributes List )

fwiffo

Sorceror
Here it is....almost a complete rewrite, I hope that I haven't used any c#4.0 reference or sintax, but anyway tell me if it doesn't compile, switching to .net4 without using the internals in .net4 format is really easy...

Code:
using System;
using Server;
 
namespace Server.Items
{
    public class HalfLifeBow : CompositeBow
    {
        public override int InitMinHits{ get{ return 255; } }
        public override int InitMaxHits{ get{ return 255; } }
        private static readonly TimeSpan m_Delay = TimeSpan.FromMinutes( 30 );
        private InternalTimer m_Halflifetimer;
 
        // starting the item itself
        [Constructable]
        public HalfLifeBow() : base()
        {
            Name = "Half Life Bow";
            Hue = 2711;
            Attributes.WeaponDamage = 40;
            Attributes.WeaponSpeed = 20;
            WeaponAttributes.HitLeechHits = 25;
            WeaponAttributes.HitLeechMana = 40;
            WeaponAttributes.HitFireball = 35;
            WeaponAttributes.SelfRepair = 5;
            Attributes.SpellChanneling = 1;
            Attributes.CastSpeed = 1;
            Attributes.Luck = 20;
            Attributes.RegenMana = 5;
            Attributes.SpellDamage = 15;
        }
 
        // this controls the list you see when you mouse-over the item
        public override void AddNameProperty( ObjectPropertyList list )
        {
            // make sure the normal mouse-over props show up
            base.AddNameProperty( list );
 
            // determine the info the timer display shows
            if(m_Halflifetimer!=null)
            {
                string lisths;
                TimeSpan timetouse = m_Halflifetimer.GetDelay().Subtract(DateTime.Now);
                if ( timetouse.Minutes > 0 )
                {
                    int min = timetouse.Minutes;
                    lisths = String.Format( "{0} minutes.", min.ToString() );
                }
                else if ( timetouse.Seconds > 0 )
                {
                    int sec = timetouse.Seconds;
                    lisths = String.Format( "{0} seconds.", sec.ToString() );
                }
                else
                {
                    lisths = ( "<BASEFONT COLOR=#00FF00>Dormant<BASEFONT COLOR=#FFFFFF>" ); //FFFFFF
                }
                // adding the timer to the property list
                list.Add( "<BASEFONT COLOR=#00FF00>Half Life Remaining: {0}<BASEFONT COLOR=#FFFFFF>", lisths ); //FFFFFF
                [FONT=Consolas]Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), new TimerCallback( InvalidateProperties ) );[/FONT]
            }
        }
 
        public override bool OnEquip( Mobile from )
        {
            if(base.OnEquip(from))
            {
                if(m_Halflifetimer==null)
                {
                    m_Halflifetimer=new HalfLifeBow.InternalTimer(this, DateTime.Now+m_Delay);
                    m_Halflifetimer.Start();
                    Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), new TimerCallback( InvalidateProperties ) );
                }
            }
            return true;
        }
 
        public HalfLifeBow( Serial serial ) : base( serial )
        {
        }
 
        public override void Serialize( GenericWriter writer ) // generic info to write and save
        {
            base.Serialize( writer );
            writer.Write( (int) 1 );
            //version 1
            writer.Write( (bool)(m_Halflifetimer!=null));
            if(m_Halflifetimer!=null)
            {
                writer.WriteDeltaTime( m_Halflifetimer.GetDelay() );
            }
        }
 
        public override void Deserialize(GenericReader reader) // make sure proper variables are read
        {
            base.Deserialize( reader );
            int version = reader.ReadInt();
            switch(version)
            {
                case 0:
                    {
                        reader.ReadDateTime();
                        break;
                    }
                case 1:
                    {
                        if(reader.ReadBool())
                        {
                            DateTime end = reader.ReadDeltaTime();
                            m_Halflifetimer = new HalfLifeBow.InternalTimer(this, end);
                            m_Halflifetimer.Start();
                        }
                        break;
                    }
            }
     
        }
 
        [CommandProperty(AccessLevel.GameMaster, true)]
        public TimeSpan Remaining
        {
            get{if(m_Halflifetimer!=null) return m_Halflifetimer.GetDelay().Subtract(DateTime.Now); else return TimeSpan.Zero;}
        }
 
        protected class InternalTimer : Timer
        {
            private Item m_Item;
            public InternalTimer(Item item, DateTime end) : base(end.Subtract(DateTime.Now))
            {
                m_Item=item;
                Priority = TimerPriority.FiveSeconds;
            }
 
            public DateTime GetDelay()
            {
                return this.Next;
            }
 
            protected override void OnTick()
            {
                if(m_Item!=null && !m_Item.Deleted)
                {
                    if(m_Item.Parent is Mobile)
                        ((Mobile)m_Item.Parent).SendMessage("The bow turns to dust");
                    m_Item.Delete();
                   
                }
                Stop();
            }
        }
    }
}
 

virus512

Sorceror
thank you its work good I tested it on 1 min timer:

Create HalfLifeBow test when Bow was equip I was online timer run out and no crash.
Create HalfLifeBow test when Bow was equip I was log out and wait until timer run out and no crash.
Create HalfLifeBow test when Bow was equip and unequip it and put into backpack I was online timer run out and no crash.
Create HalfLifeBow test when Bow was equip and unequip it and put into backpack I was log out and wait until timer run out and no crash.
Create HalfLifeBow test when Bow was equip and unequip it and put on the ground/floor I was online timer run out and no crash.
Create HalfLifeBow test when Bow was equip and unequip it and put on the ground/floor I was log out and wait until timer run out and no crash.
Create HalfLifeBow test when Bow was equip I was log out and log in and wait until timer run out and no crash.
Create HalfLifeBow test when Bow was equip and unequip it and put into backpack I was log out and log in and wait until timer run out and no crash.
Create HalfLifeBow test when Bow was equip and unequip it and put on the ground/floor I was log out and log in and wait until timer run out and no crash.

Create HalfLifeBow test when Bow was equip and unequip it and put on the ground/floor I was save world, log out and turn off the server then wait 2 minutes turn on server and log in (timer stoped when server was turn off and starts when server was turn on) and wait until timer run out and bow disapear and no crash.
Create HalfLifeBow test when Bow was equip I was save world, log out and turn off the server then wait 2 minutes turn on server and log in (timer stoped when server was turn off and starts when server was turn on) and wait until timer run out and bow disapear and no crash.
Create HalfLifeBow test when Bow was equip and unequip it and put into backpack I was save world, log out and turn off the server then wait 2 minutes turn on server and log in (timer stoped when server was turn off and starts when server was turn on) and wait until timer run out and bow disapear and no crash.


The script works good and thank you for it ;)

I have two things in old script I wanted to stay:

-first in old script after create bow by [add or take it from killed mob I had "half life ramaining : dormant" under the item name --- now in new script I dont have it on bow who wasnt used and it apear when bow was equip

-second in old script when bow was equip the timer starts and when my mouse was on the bow the timer count down and I saw 40..39..38..37.....4...3..2..1 and bow disapear (was delete) --- now in new script when bow was equip the timer starts and when my mouse was on the bow timer count down but I didnt see it I saw only 58 seconds and on bow timer freeze and after the 1 min remain the bow disapear (was delete) but I didnt see the count on my eyes like 58..57..56..55. The seconds on the bow was change only when after equip the bow I saw 58 seconds and freeze then I was unequip the bow to my backpack or on the ground/floor the timer was change and I saw 45 seconds and freeze

I know that timer count good but I think the players wanted to see count down timer on his eyes ;)

I hope you understand me one more time ;D I know its not easy to work with me ;)
 

zerodowned

Sorceror
-first in old script after create bow by [add or take it from killed mob I had "half life ramaining : dormant" under the item name --- now in new script I dont have it on bow who wasnt used and it apear when bow was equip

So you're saying that the bow says Dormant even after it's equipped?

-second in old script when bow was equip the timer starts and when my mouse was on the bow the timer count down and I saw 40..39..38..37.....4...3..2..1 and bow disapear (was delete) --- now in new script when bow was equip the timer starts and when my mouse was on the bow timer count down but I didnt see it I saw only 58 seconds and on bow timer freeze and after the 1 min remain the bow disapear (was delete) but I didnt see the count on my eyes like 58..57..56..55. The seconds on the bow was change only when after equip the bow I saw 58 seconds and freeze then I was unequip the bow to my backpack or on the ground/floor the timer was change and I saw 45 seconds and freeze

This is a problem with the Timer Update. I don't know if this is a problem with .net4.0 as Avachei mentioned.
 

virus512

Sorceror
So you're saying that the bow says Dormant even after it's equipped?




This is a problem with the Timer Update. I don't know if this is a problem with .net4.0 as Avachei mentioned.

No. In your script bow say Dormant before equip but after take it from monster corps and put it in backpack or somewhere else. Its good that before equip we saw Time Remaining: Dormant or sth because player know that weapon will be for limited time. After equip your weapon lose Dormant and start count down. In wiffo script before equip we didnt know that weapon will be with limited time because its look like normal weapon.. only after equip we saw Time remaining but not one by one like old script 59..58..57..56..55 but when you put mouse on bow we saw 58 or any other seconds and freeze but timer work good but like in the system not on screen.
 

fwiffo

Sorceror
Unless I'm reading this backwards, are you saying this script isn't compatible with .net 4.0 based servers?
just try it, then you can comment, .net4 has nothing to do with compatibility, but only in changes of certain sintax, but as I can see there is no problem if it does compile and run (you'll get an error at compile time otherwise).

Anyway, I'll give it a look, but my time is short and I have really no time, since I must do things on my shard.
The script is there, it's not an hard to do mod, but it requires always time...

For the crashes in the old script, it's easy, who made it didn't consider the fact that the private variable "Mobile" could be null, and when the timer run out, the call of that mobile to send a message without a check would throw an unreferenced exeption (you can't call a generic type method if the object is null!).

When I'll get some time I'll give another look there, but don't hold your breath
 

virus512

Sorceror
just try it, then you can comment, .net4 has nothing to do with compatibility, but only in changes of certain sintax, but as I can see there is no problem if it does compile and run (you'll get an error at compile time otherwise).

Anyway, I'll give it a look, but my time is short and I have really no time, since I must do things on my shard.
The script is there, it's not an hard to do mod, but it requires always time...

For the crashes in the old script, it's easy, who made it didn't consider the fact that the private variable "Mobile" could be null, and when the timer run out, the call of that mobile to send a message without a check would throw an unreferenced exeption (you can't call a generic type method if the object is null!).

When I'll get some time I'll give another look there, but don't hold your breath

ok ;D I will try to do something by myself ;D I will try to copy and paste some part of script from old script to your new script because I want this script in game to look like old with count down timer like 59..58..57 but with your new full working script ;) I will wait for your new version try to learn something ;)
 

zerodowned

Sorceror
virus512 - i've been wanting to take a look at this script again and might have time to do so over the weekend.
as a workaround thought you can just comment out the message sent when the item deletes itself. there may be more than one line you have to do this to, i can't remember. but it removes the mobile null error that fwiffo mentioned.

if you need help, post the script in code brackets on here, since i'm at work, and i should be able to tell you what lines to comment out.
 

Bittiez

Sorceror
Well, I attempted to make this bow only count down while it is equiped, but I can't seem to get it to work and frankly it's pissing me off, not sure whats wrong with it so if anyone wants to give it a go, here you go:

Code:
/*
    script by zerodowned
    credits to: Murzin's Hearthstone script, Peoharen's SelfDeletingItem script (part of the Mobile Abilities Package), and Soteric for help on Script Support boards - pointed out that I forgot to use ": base()" in the Constructable.
 
    Edited by Bittiez
*/
 
using System;
using Server;
using Server.Mobiles;
using Server.Items;
using Server.Regions;
using Server.Network;
 
namespace Server.Items
{
    public class HalfLifeBow : CompositeBow
    {
    public override int InitMinHits{ get{ return 255; } }
    public override int InitMaxHits{ get{ return 255; } }
       
 
        // Initiate the starting variables to be used
        public int time_left;
        public int start = 30; //Minutes for delay
        public Timer halflifetimer;
        public Mobile m;
 
 
        // Setup the GM access/viewable variables for the item
        [CommandProperty( AccessLevel.GameMaster )]
        public int TimeLeft
        {
            get { return time_left; }
            set { time_left = value; }
        }
 
       
        // starting the item itself
        [Constructable]
        public HalfLifeBow() : base()
        {
            time_left = start;
            Name = "Half Life Bow";
            Hue = 2988;
            Attributes.WeaponDamage = 40;
            Attributes.WeaponSpeed = 20;
            WeaponAttributes.HitLeechHits = 25;
            WeaponAttributes.HitLeechMana = 40;
            WeaponAttributes.HitFireball = 35;
            WeaponAttributes.SelfRepair = 5;
            Attributes.SpellChanneling = 1;
            Attributes.CastSpeed = 1;
            Attributes.Luck = 20;
            Attributes.RegenMana = 5;
            Attributes.SpellDamage = 15;
        }
       
        public HalfLifeBow( Serial serial ) : base( serial )
        {
        }
 
        private void Expire()
        {
            if ( Deleted )
                return;
 
            Delete();
            if(m is Mobile)m.SendMessage( "The bow turns to dust." );
        }
 
        // this controls the list you see when you mouse-over the item
        public override void AddNameProperty( ObjectPropertyList list )
        {
            base.AddNameProperty( list );
            string lisths;
            lisths = String.Format( "{0} minutes.", time_left );
            list.Add( "<BASEFONT COLOR=#00FF00>Half Life Remaining: {0}<BASEFONT COLOR=#FFFFFF>", lisths ); //FFFFFF
        }
 
        public override bool OnEquip( Mobile from )
        {
            base.OnEquip(from);
            m = from;
            from.SendMessage("You feel your " + this.Name + " start to decay.");
            Timer.DelayCall(TimeSpan.FromSeconds(5.0), new TimerCallback(decaying));
            return true;
        }
 
        private void decaying()
        {
            Mobile from = m;
            halflifetimer = Timer.DelayCall(TimeSpan.FromMinutes(1.0), new TimerCallback(minusone));
 
            while (from.FindItemOnLayer(this.Layer) == this)
            {
                Timer.DelayCall(TimeSpan.FromMinutes(1.0), new TimerCallback(InvalidateProperties));
                if (!halflifetimer.Running) halflifetimer = Timer.DelayCall(TimeSpan.FromMinutes(1.0), new TimerCallback(minusone));
               
            }
            if (halflifetimer is Timer) if (halflifetimer.Running) halflifetimer.Stop();
        }
 
 
        private void minusone()
        {
            time_left = time_left - 1;
            if (time_left < 1)
            {
                Expire();
            }
            InvalidateProperties();
        }
 
        public override void Serialize( GenericWriter writer ) // generic info to write and save
        {
            base.Serialize( writer );
            writer.Write( (int) 0 );
            writer.Write((int) time_left);
            //writer.Write( (DateTime)i_halflife );
        }
     
        public override void Deserialize(GenericReader reader) // make sure proper variables are read
        {
            base.Deserialize( reader );
            int version = reader.ReadInt();
            time_left = reader.ReadInt();
            //i_halflife = reader.ReadDateTime();
        }
   
    }
}
 

virus512

Sorceror
virus512 - i've been wanting to take a look at this script again and might have time to do so over the weekend.
as a workaround thought you can just comment out the message sent when the item deletes itself. there may be more than one line you have to do this to, i can't remember. but it removes the mobile null error that fwiffo mentioned.

if you need help, post the script in code brackets on here, since i'm at work, and i should be able to tell you what lines to comment out.

Code:
using System;
using Server;
 
namespace Server.Items
{
    public class HalfLifeBow : CompositeBow
    {
        public override int InitMinHits{ get{ return 255; } }
        public override int InitMaxHits{ get{ return 255; } }
        private static readonly TimeSpan m_Delay = TimeSpan.FromMinutes( 1 );
        private InternalTimer m_Halflifetimer;
 
        // starting the item itself
        [Constructable]
        public HalfLifeBow() : base()
        {
            Name = "Half Life Bow";
            Hue = 2711;
            Attributes.WeaponDamage = 40;
            Attributes.WeaponSpeed = 20;
            WeaponAttributes.HitLeechHits = 25;
            WeaponAttributes.HitLeechMana = 40;
            WeaponAttributes.HitFireball = 35;
            WeaponAttributes.SelfRepair = 5;
            Attributes.SpellChanneling = 1;
            Attributes.CastSpeed = 1;
            Attributes.Luck = 20;
            Attributes.RegenMana = 5;
            Attributes.SpellDamage = 15;
        }
 
        public override void OnSingleClick(Mobile from)
        {
            InvalidateProperties();
            base.OnSingleClick(from);
        }
 
        // this controls the list you see when you mouse-over the item
        public override void AddNameProperty( ObjectPropertyList list )
        {
            // make sure the normal mouse-over props show up
            base.AddNameProperty( list );
 
            // determine the info the timer display shows
            if(m_Halflifetimer!=null)
            {
                string lisths;
                TimeSpan timetouse = m_Halflifetimer.GetDelay().Subtract(DateTime.Now);
                if ( timetouse.Days > 0 )
                {
                    int min = timetouse.Days;
                    lisths = String.Format( "{0} days.", min.ToString() );
                }
        else  if ( timetouse.Hours > 0 )
                {
                    int min = timetouse.Hours;
                    lisths = String.Format( "{0} hours.", min.ToString() );
                }
        else if ( timetouse.Minutes > 0 )
                {
                    int min = timetouse.Minutes;
                    lisths = String.Format( "{0} minutes.", min.ToString() );
                }
                else if ( timetouse.Seconds > 0 )
                {
                    int sec = timetouse.Seconds;
                    lisths = String.Format( "{0} seconds.", sec.ToString() );
                }
                else
                {
                    lisths = ( "<BASEFONT COLOR=#00FF00>Dormant<BASEFONT COLOR=#FFFFFF>" ); //FFFFFF
                }
                // adding the timer to the property list
                list.Add( "<BASEFONT COLOR=#00FF00>Half Life Remaining: {0}<BASEFONT COLOR=#FFFFFF>", lisths ); //FFFFFF
            }
        }
 
        public override bool OnEquip( Mobile from )
        {
            if(base.OnEquip(from))
            {
                if(m_Halflifetimer==null)
                {
                    m_Halflifetimer=new HalfLifeBow.InternalTimer(this, DateTime.Now+m_Delay);
                    m_Halflifetimer.Start();
                    Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), new TimerCallback( InvalidateProperties ) );
                }
            }
            return true;
        }
 
        public HalfLifeBow( Serial serial ) : base( serial )
        {
        }
 
        public override void Serialize( GenericWriter writer ) // generic info to write and save
        {
            base.Serialize( writer );
            writer.Write( (int) 1 );
            //version 1
            writer.Write( (bool)(m_Halflifetimer!=null));
            if(m_Halflifetimer!=null)
            {
                writer.WriteDeltaTime( m_Halflifetimer.GetDelay() );
            }
        }
 
        public override void Deserialize(GenericReader reader) // make sure proper variables are read
        {
            base.Deserialize( reader );
            int version = reader.ReadInt();
            switch(version)
            {
                case 0:
                    {
                        reader.ReadDateTime();
                        break;
                    }
                case 1:
                    {
                        if(reader.ReadBool())
                        {
                            DateTime end = reader.ReadDeltaTime();
                            m_Halflifetimer = new HalfLifeBow.InternalTimer(this, end);
                            m_Halflifetimer.Start();
                        }
                        break;
                    }
            }
     
        }
 
        [CommandProperty(AccessLevel.GameMaster, true)]
        public TimeSpan Remaining
        {
            get{if(m_Halflifetimer!=null) return m_Halflifetimer.GetDelay().Subtract(DateTime.Now); else return TimeSpan.Zero;}
        }
 
        protected class InternalTimer : Timer
        {
            private Item m_Item;
            public InternalTimer(Item item, DateTime end) : base(end.Subtract(DateTime.Now))
            {
                m_Item=item;
                Priority = TimerPriority.FiveSeconds;
            }
 
            public DateTime GetDelay()
            {
                return this.Next;
            }
 
            protected override void OnTick()
            {
                if(m_Item!=null && !m_Item.Deleted)
                {
                    if(m_Item.Parent is Mobile)
                        ((Mobile)m_Item.Parent).SendMessage("The bow turns to dust");
                    m_Item.Delete();
                   
                }
                Stop();
            }
        }
    }
}


this is the script ;) thank you for try ;)
 

zerodowned

Sorceror
Bittiez - after reading this: http://www.runuo.com/community/threads/timer-stop.102659/ I don't think stopping the timer would be a good thing to do. If I understand Murzin correctly, it could Null the timer making the item so it never self-deletes, or just eventually delete the item altogether. Would that cause a bigger issue with the server/save files/etc? I don't know.
Still, I tried a few ways to make it work. I think what you want to use is the OnRemove method:

Code:
public override void OnRemoved( object parent )

Virus512 - seems like you just reposted fwiffo's altered script. if the countdown timer still isn't working for you on that, here's an altered option for my original script that still has the countdown timer. instead of deleting the item, the properties change and the name changes to "Depleted Bow".

Code:
/*
    script by zerodowned
    credits to: Murzin's Hearthstone script, Peoharen's SelfDeletingItem script (part of the Mobile Abilities Package), and Soteric for help on Script Support boards - pointed out that I forgot to use ": base()" in the Constructable.
 
    Info: If you change the timer on this make sure that the timer on Line 24, and 112, and 123 match.
*/
 
using System;
using Server;
using Server.Mobiles;
using Server.Items;
using Server.Regions;
 
namespace Server.Items
{
    public class HalfLifeBow : CompositeBow
    {
    public override int InitMinHits{ get{ return 255; } }
    public override int InitMaxHits{ get{ return 255; } }
       
 
        // Initiate the starting variables to be used
        private DateTime i_halflife;
        private static readonly TimeSpan delay = TimeSpan.FromMinutes( 1 );
        private Timer halflifetimer;
        private Mobile m;
        private Item i;
 
        // Setup the GM access/viewable variables for the item
        [CommandProperty( AccessLevel.GameMaster )]
        public DateTime lastused
        {
            get{ return i_halflife; }
            set{ i_halflife = value; }
        }
 
       
        // starting the item itself
        [Constructable]
        public HalfLifeBow() : base()
        {
            Name = "Half Life Bow";
            Hue = 2711;
            Attributes.WeaponDamage = 40;
            Attributes.WeaponSpeed = 20;
            WeaponAttributes.HitLeechHits = 25;
            WeaponAttributes.HitLeechMana = 40;
            WeaponAttributes.HitFireball = 35;
            WeaponAttributes.SelfRepair = 5;
            Attributes.SpellChanneling = 1;
            Attributes.CastSpeed = 1;
            Attributes.Luck = 20;
            Attributes.RegenMana = 5;
            Attributes.SpellDamage = 15;
        }
       
       
        private void Expire()
        {
            //if ( Deleted )
            //    return;
 
            //Delete();
           
            Name = "Depleted Bow";
            Hue = 0;
            Attributes.WeaponDamage = 0;
            Attributes.WeaponSpeed = 0;
            WeaponAttributes.HitLeechHits = 0;
            WeaponAttributes.HitLeechMana = 0;
            WeaponAttributes.HitFireball = 0;
            WeaponAttributes.SelfRepair = 0;
            Attributes.SpellChanneling = 0;
            Attributes.CastSpeed = 0;
            Attributes.Luck = 0;
            Attributes.RegenMana = 0;
            Attributes.SpellDamage = 0;
        }
       
       
        /*
        private void Expire( Item item )
        {
            if ( item == null || item.Deleted )
              {
                    if(m_Item.Parent is Mobile) && ((Mobile)parent).Alive)
                        ((Mobile)m_Item.Parent).SendMessage("The bow turns to dust");
             
                }
                return;
            Item.Delete();
        }
        */
 
        // this controls the list you see when you mouse-over the item
        public override void AddNameProperty( ObjectPropertyList list )
        {
            // make sure the normal mouse-over props show up
            base.AddNameProperty( list );
 
            // initial variables for use only inside the property list
            TimeSpan timetouse = ( ( this.lastused + Server.Items.HalfLifeBow.delay) - DateTime.Now );
            string lisths;
 
            // determine the info the timer display shows
            if ( timetouse.Minutes > 0 )
            {
                int min = timetouse.Minutes;
                lisths = String.Format( "{0} minutes.", min.ToString() );
            }
            else if ( timetouse.Seconds > 0 )
            {
                int sec = timetouse.Seconds;
                lisths = String.Format( "{0} seconds.", sec.ToString() );
            }
            else
            {
                lisths = ( "<BASEFONT COLOR=#00FF00>Dormant<BASEFONT COLOR=#FFFFFF>" ); //FFFFFF
            }
 
            // adding the timer to the property list
            list.Add( "<BASEFONT COLOR=#00FF00>Half Life Remaining: {0}<BASEFONT COLOR=#FFFFFF>", lisths ); //FFFFFF
 
            // because we do not want the server spamming updates, slow down how fast the mouse-over info refreshes
            Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), new TimerCallback( InvalidateProperties ) );
        }
 
        public override bool OnEquip( Mobile from )
        {
            i = this;
            m = from;
           
            if ( ( this.lastused + Server.Items.HalfLifeBow.delay ) > DateTime.Now ) //check if timer is already started
                {
                    return true;
                }
        /*       
            if ( Item.Name = "Depleted Bow" )
                {
                    return true;
                }
        */   
            else //start timer
            {
                this.lastused = DateTime.Now;
                halflifetimer = Timer.DelayCall( TimeSpan.FromMinutes( 1 ), new TimerCallback( Expire ) );
                return true;
               
            }
        }
 
        /*
        public override void OnRemoved( object parent )
        {
            Mobile m = (Mobile)parent;
            halflifetimer = Timer.Stop ();
            return true;
        }
        */
       
       
 
        public HalfLifeBow( Serial serial ) : base( serial )
        {
            Timer.DelayCall( TimeSpan.FromMinutes( 1 ), new TimerCallback( Expire ) );
        }
 
        public override void Serialize( GenericWriter writer ) // generic info to write and save
        {
            base.Serialize( writer );
            writer.Write( (int) 0 );
            writer.Write( (DateTime)i_halflife );
        }
     
        public override void Deserialize(GenericReader reader) // make sure proper variables are read
        {
            base.Deserialize( reader );
            int version = reader.ReadInt();
            i_halflife = reader.ReadDateTime();
        }
   
    }
}
 

Bittiez

Sorceror
Bittiez - after reading this: http://www.runuo.com/community/threads/timer-stop.102659/ I don't think stopping the timer would be a good thing to do. If I understand Murzin correctly, it could Null the timer making the item so it never self-deletes, or just eventually delete the item altogether. Would that cause a bigger issue with the server/save files/etc? I don't know.



My method did not involve any timer, on creation the bow was set with 30 "minutes", then every minute WHILE equipped would - 1 from that 30, at 0 it would self destruct.
 
Top