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!

OnTick

ThatDudeJBob

Sorceror
How can i call on an item in 'OnTick'

Here is the Basics of the timer i am using.
C#:
        private class SomeTimer : Timer
        {
            private readonly Mobile m_From;
            private readonly int m_SoundID;
            private int m_Count;
 
            public SomeTimer(Mobile from, int soundID) : base(TimeSpan.Zero, TimeSpan.FromSeconds(1.0))
            {
                m_From = from;
                m_SoundID = soundID;
 
                Priority = TimerPriority.TenMS;
            }
            protected override void OnTick()
            {
                m_Count++;
                if (this is FirstItem)
                {
                }
               
                else if (this is SecondItem)
                {
                }
               
                else if (this is ThirdItem)
                {
                }
            }
        }

When i do 'if (this is FirstItem)', 'this' is refering to SomeTimer and not the item.
and if i try this(below)
C#:
        private class SomeTimer : Timer
        {
            private readonly Mobile m_From;
            private readonly Item m_Item;
            private readonly int m_SoundID;
            private int m_Count;
 
            public SomeTimer(Mobile from, Item item, int soundID) : base(TimeSpan.Zero, TimeSpan.FromSeconds(1.0))
            {
                m_From = from;
                m_Item = item;
                m_SoundID = soundID;
 
                Priority = TimerPriority.TenMS;
            }
            protected override void OnTick()
            {
                m_Count++;
                if (m_Item is FirstItem)
                {
                }
               
                else if (m_item is SecondItem)
                {
                }
               
                else if (m_Item is ThirdItem)
                {
                }
            }
        }

I get this Error...

Code:
CS1729: Line 136: 'Server.Items.BaseSomthing.SomeTimer' does not contain a constructor that takes 2 arguments

Line 136:
C#:
public SomeTimer(Mobile from, Item item, int soundID) : base(TimeSpan.Zero, TimeSpan.FromSeconds(1.0))

I'm at a loss at what to try now.
Any suggestions?
 

zerodowned

Sorceror
I think you're looking for this

public Timer( TimeSpan delay, TimeSpan interval ) : this( delay, interval, 0 )
{
}

well that's the format anyway.
i'm sure I can find a script to ref. but give me a little while
 

zerodowned

Sorceror
best basic version of a timer i could find that seems to fit what you need
from Blood script

C#:
private class InternalTimer : Timer
{
private Item m_Blood;
public InternalTimer( Item blood ) : base( TimeSpan.FromSeconds( 5.0 ) )
{
Priority = TimerPriority.OneSecond;
m_Blood = blood;
}
protected override void OnTick()
{
m_Blood.Delete();
}
}
 

zerodowned

Sorceror
might be wrong, but have you tried changing the

base(TimeSpan.Zero, TimeSpan.FromSeconds(1.0))
to
base( TimeSpan.FromSeconds(1.0))
 

Soteric

Knight
You had
Code:
public SomeTimer(Mobile from, int soundID)
and somewhere in code you did something like this
Code:
SomeTimer someTimer = new SomeTimer(mobile, 0x4F);
Now you added 'item' argument into constructor
Code:
public SomeTimer(Mobile from, Item item, int soundID)
and should update 'new SomeTimer(...)' code to pass the item to constructor.
 
Top