1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Lifespan timer

Discussion in 'ServUO Discussion' started by Redmoon, Feb 19, 2014.

  1. Redmoon
    Offline

    Redmoon Active Member

    Joined:
    Sep 16, 2013
    Messages:
    264
    Likes Received:
    39
    Is it possible to have a lifespan timer count down from days to seconds and display?
     
  2. Milva
    Offline

    Admin Moderator

    Joined:
    Mar 3, 2013
    Messages:
    3,637
    Likes Received:
    398
    I remember some of the SA items having the lifespan timer, but I don't think they were for days. I'm sure some one can help with this as I don't see why it couldn't be done :)
     
  3. Redmoon
    Offline

    Redmoon Active Member

    Joined:
    Sep 16, 2013
    Messages:
    264
    Likes Received:
    39
    I'm working on the exodus encounter quest. I have the items with the lifespan set for 168 hours (total is 7 days on each). I just think it'd be a grand idea to have it count down so players could actually see exactly how long they have til it *poofs*. :D
     
  4. Hank
    Offline

    Hank Active Member

    Joined:
    Nov 14, 2013
    Messages:
    972
    Likes Received:
    152
    I'm interested in this too, I found a picture of it once and now I can't find it to give the example. :|
     
  5. dmurphy
    Offline

    Admin ServUO Developer

    Joined:
    Feb 10, 2014
    Messages:
    1,009
    Likes Received:
    192
    If you post your code I could give it a whirl. It should be as easy as overriding GetProperties and adding text to show how long is left.
     
  6. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    I assume you mean when you hover over an item and see it's properties? If so then it's as simple as adding the time left to GetProperties of the item.

    Edit: Lol dmurphy just beat me to it :p.
     
  7. Redmoon
    Offline

    Redmoon Active Member

    Joined:
    Sep 16, 2013
    Messages:
    264
    Likes Received:
    39
    Code (C#):
    1. using System;
    2. using System.Collections.Generic;
    3. using Server;
    4. using Server.Mobiles;
    5. namespace Server.Items
    6. {
    7.     public class ExodusSacrificalDagger : Dagger
    8.     {
    9.            
    10.         private TimeSpan m_LifeSpan;
    11.  
    12.         [CommandProperty(AccessLevel.GameMaster)]
    13.         public TimeSpan LifeSpan
    14.         {
    15.             get { return m_LifeSpan; }
    16.             set { m_LifeSpan = value; }
    17.         }
    18.  
    19.         private DateTime m_CreationTime;
    20.  
    21.         [CommandProperty(AccessLevel.GameMaster)]
    22.         public DateTime CreationTime
    23.         {
    24.             get { return m_CreationTime; }
    25.             set { m_CreationTime = value; }
    26.         }
    27.  
    28.         private Timer m_Timer;
    29.  
    30.         public override bool Nontransferable { get { return true; } }
    31.  
    32.         public virtual void Expire(Mobile parent)
    33.         {
    34.             if (parent != null)
    35.                 parent.SendMessage(38, "Time's up! Your sacrifical dagger has disappeared.");
    36.             Effects.PlaySound(GetWorldLocation(), Map, 0x201);
    37.  
    38.             this.Delete();
    39.         }
    40.  
    41.         public virtual void SendTimeRemainingMessage(Mobile to)
    42.         {
    43.             to.SendLocalizedMessage(1072516, String.Format("{0}\t{1}", (this.Name == null ? String.Format("#{0}", LabelNumber) : this.Name), (int)m_LifeSpan.TotalHours)); // ~1_name~ will expire in ~2_val~ Hours!
    44.         }
    45.  
    46.         public override void OnDelete()
    47.         {
    48.             if (m_Timer != null)
    49.                 m_Timer.Stop();
    50.  
    51.             base.OnDelete();
    52.         }
    53.  
    54.         public virtual void CheckExpiry()
    55.         {
    56.             if ((m_CreationTime + m_LifeSpan) < DateTime.UtcNow)
    57.                 Expire(RootParent as Mobile);
    58.             else
    59.                 InvalidateProperties();
    60.         }
    61.  
    62.  
    63.         [Constructable]
    64.         public ExodusSacrificalDagger(int lifeSpan)
    65.             : this(TimeSpan.FromHours(lifeSpan))
    66.         {
    67.         }
    68.         [Constructable]
    69.         public ExodusSacrificalDagger(TimeSpan lifeSpan)
    70.            
    71.           {
    72.             Name = "Exodus Sacrifical Dagger";
    73.             ItemID = 0x2D2D;
    74.             Weight = 4.0;
    75.             m_CreationTime = DateTime.UtcNow;
    76.             m_LifeSpan = lifeSpan;
    77.  
    78.             m_Timer = Timer.DelayCall(TimeSpan.FromHours(5), TimeSpan.FromHours(5), new TimerCallback(CheckExpiry));
    79.         }
    80.  
    81.         public ExodusSacrificalDagger(Serial serial) : base(serial)
    82.         {
    83.         }
    84.  
    85.         public override void GetProperties(ObjectPropertyList list)
    86.         {
    87.             base.GetProperties(list);
    88.  
    89.             TimeSpan remaining = ((m_CreationTime + m_LifeSpan) - DateTime.UtcNow);
    90.             list.Add(1074049);
    91.             list.Add(1153090, ((int)remaining.TotalHours).ToString());
    92.         }
    93.  
    94.         public override void Serialize(GenericWriter writer)
    95.         {
    96.             base.Serialize(writer);
    97.             writer.Write((int)0);
    98.  
    99.             writer.Write(m_LifeSpan);
    100.             writer.Write(m_CreationTime);
    101.         }
    102.  
    103.         public override void Deserialize(GenericReader reader)
    104.         {
    105.             base.Deserialize(reader);
    106.             int version = reader.ReadInt();
    107.  
    108.             m_LifeSpan = reader.ReadTimeSpan();
    109.             m_CreationTime = reader.ReadDateTime();
    110.  
    111.             m_Timer = Timer.DelayCall(TimeSpan.FromHours(5), TimeSpan.FromHours(5), new TimerCallback(CheckExpiry));
    112.         }
    113.     }
    114. }
     
  8. Redmoon
    Offline

    Redmoon Active Member

    Joined:
    Sep 16, 2013
    Messages:
    264
    Likes Received:
    39

    Yup, that's exactly what I'm looking for! To show the timer maybe a 00:00:00 format.
     
  9. Kalamus
    Offline

    Kalamus Active Member

    Joined:
    Apr 24, 2013
    Messages:
    282
    Likes Received:
    32
    I have faith in dmurphy's ability to do this :).

    @dmurphy umm.. yeah.. sorry no pressure :p.
     
  10. Redmoon
    Offline

    Redmoon Active Member

    Joined:
    Sep 16, 2013
    Messages:
    264
    Likes Received:
    39
    @dmurphy no rush, it's not ~needed~, just would make players ~super~ happy. :)
     
  11. Hank
    Offline

    Hank Active Member

    Joined:
    Nov 14, 2013
    Messages:
    972
    Likes Received:
    152
  12. Redmoon
    Offline

    Redmoon Active Member

    Joined:
    Sep 16, 2013
    Messages:
    264
    Likes Received:
    39
  13. Hank
    Offline

    Hank Active Member

    Joined:
    Nov 14, 2013
    Messages:
    972
    Likes Received:
    152
    That is a shame because there is piles and piles and piles and piles and piles and piles and piles..... of code that you can learn from there.
    Type into google "site:runuo.com "Question"" (Without any "") 7/10 you'll find a thread with something to point you in a direction.
    For example: http://lmgtfy.com/?q=site:runuo.com item time limit
    not trying to be rude, just informative.
    Also it is our responsibility here as members of ServUO to make sure that this knowledge gets preserved here in the servuo community. So people can do that same searches on servuo with better results.
     
  14. Redmoon
    Offline

    Redmoon Active Member

    Joined:
    Sep 16, 2013
    Messages:
    264
    Likes Received:
    39
    Yeah, I know :oops:...I just...well...I just love ServUO so much I forget about RunUO. :p
     
    • Like Like x 1
  15. dmurphy
    Offline

    Admin ServUO Developer

    Joined:
    Feb 10, 2014
    Messages:
    1,009
    Likes Received:
    192
    Here you go. Replace your GetProperties override with this

    Code (C#):
    1.  
    2.  public override void GetProperties(ObjectPropertyList list)
    3.         {
    4.             TimeSpan remaining = ((m_CreationTime + m_LifeSpan) - DateTime.UtcNow);
    5.             base.GetProperties(list);
    6.             string timeLeft = null;
    7.             if (remaining.Minutes > 0)
    8.             {
    9.                 var min = remaining.Minutes;
    10.                 timeLeft = String.Format("Time Left: {0} minutes.", min);
    11.             }
    12.             else if (remaining.Seconds > 0)
    13.             {
    14.                 var sec = remaining.Seconds;
    15.                 timeLeft = String.Format("Time Left: {0} seconds.", sec);
    16.             }
    17.             list.Add((timeLeft));
    18.             list.Add(1074049);
    19.             list.Add(1153090, ((int)remaining.TotalHours).ToString());
    20.             Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), new TimerCallback( InvalidateProperties ) );
    21.  
    22.         }
    23.  
    I didn't remove your additions as I have no idea what they are as I do not have those clilocs. (Custom?)
     
    • Like Like x 1
  16. Redmoon
    Offline

    Redmoon Active Member

    Joined:
    Sep 16, 2013
    Messages:
    264
    Likes Received:
    39
    Yes, those are Cliloc #s, not custom. (client 7.0.34.6)
     
  17. dmurphy
    Offline

    Admin ServUO Developer

    Joined:
    Feb 10, 2014
    Messages:
    1,009
    Likes Received:
    192
    Ahh I have 7.0.15.1 Don't like the new despise :p
     
  18. Redmoon
    Offline

    Redmoon Active Member

    Joined:
    Sep 16, 2013
    Messages:
    264
    Likes Received:
    39
    Me either, I'm using old maps. ;)
     
Similar Threads: Lifespan timer
Forum Title Date
Archived Bug Reports Magic Drake Wing lifespan should be 90 seconds Feb 26, 2017
Script Support Gump + Timer refresh Oct 17, 2017
Archived Bug Reports Stat regen timers Aug 9, 2017
Archived Bug Reports Heat of Battle Mismatching Timers Aug 1, 2017
Script Support Fate Of Fortune Talisman -Timer issue- Jul 4, 2017
Script Support Need help with a timer Jun 30, 2017
Archived Bug Reports BOD timer Jun 7, 2017