***** Rate this Resource if you find it useful *****
One Time replaces the need to use timers, it uses events & interfaces instead in creative ways!
This System uses events and a interface to utilize 6 timers (tick, millisecond, second, minute, hour and day)
All you need to do is hook them up in your scripts, included are TimeTest.cs (event Item) and ITimeTest.cs (interface item) as examples of adding One Time to your scripts!
There is also a Sticky Grass project that will demonstrate different ways to use this system with a more complex method which includes Async.
I advise you read through the discussion, @Vorspire brought up some great points, some of which directly effected this project and the path forward, Thanks again @Vorspire
A few important notes when using events, they cost overhead when you remove them and can mess up the garbage collector if not disposed of when a object is deleted with a event registered in the array.
I have an example in TimeTest.cs of two ways to delete objects with the event registered,
One method is the delayed deletion tag, basically a bool that triggers when it first is targeted for deletion, what this does is shut down the listeners method and makes the object invisible, after next restart, you can then delete them without the overhead of removing events.
The other method is commented out, which is to remove the objects event handle in the OnAfterDelete(), this will cause overhead if there are a lot of objects being deleted at once!
With that said, I have also included NewStickyGrass.cs and Helper.cs which has a event trigger a world item look up and store, this is a great example of using a event outside the objects which allows the objects to be freely deleted without worry of events. Added Async Event example to Helper.cs as of 1.0.0.9!
Here is the Latest stress test on the sticky grass using async
Here is a video showcasing the New Sticky Grass, which stays hidden until the player is close!
One Time : Code Docs
Event
You can also use a Interface to setup One Time to a Item or Mobile : See ITimeTest.cs for example item
Interface
One Time replaces the need to use timers, it uses events & interfaces instead in creative ways!
Vorspire said:
This System uses events and a interface to utilize 6 timers (tick, millisecond, second, minute, hour and day)
All you need to do is hook them up in your scripts, included are TimeTest.cs (event Item) and ITimeTest.cs (interface item) as examples of adding One Time to your scripts!
There is also a Sticky Grass project that will demonstrate different ways to use this system with a more complex method which includes Async.
I advise you read through the discussion, @Vorspire brought up some great points, some of which directly effected this project and the path forward, Thanks again @Vorspire
A few important notes when using events, they cost overhead when you remove them and can mess up the garbage collector if not disposed of when a object is deleted with a event registered in the array.
I have an example in TimeTest.cs of two ways to delete objects with the event registered,
One method is the delayed deletion tag, basically a bool that triggers when it first is targeted for deletion, what this does is shut down the listeners method and makes the object invisible, after next restart, you can then delete them without the overhead of removing events.
The other method is commented out, which is to remove the objects event handle in the OnAfterDelete(), this will cause overhead if there are a lot of objects being deleted at once!
With that said, I have also included NewStickyGrass.cs and Helper.cs which has a event trigger a world item look up and store, this is a great example of using a event outside the objects which allows the objects to be freely deleted without worry of events. Added Async Event example to Helper.cs as of 1.0.0.9!
Here is the Latest stress test on the sticky grass using async
Here is a video showcasing the New Sticky Grass, which stays hidden until the player is close!
One Time : Code Docs
Event
Code:
using Server.OneTime.Events;
Code:
//Tick
OneTimeTickEvent.TickTimerTick += YourMethod();
//Millisecond
OneTimeMilliEvent.MilliTimerTick += YourMethod();
//Second
OneTimeSecEvent.SecTimerTick += YourMethod();
//Minute
OneTimeMinEvent.MinTimerTick += YourMethod();
//Hour
OneTimeHourEvent.HourTimerTick += YourMethod();
//Day
OneTimeDayEvent.DayTimerTick += YourMethod();
You can also use a Interface to setup One Time to a Item or Mobile : See ITimeTest.cs for example item
Interface
Code:
class YourClass : Item, IOneTime //Add interface to your item/mobile class
public interface IOneTime
{
int OneTimeType { get; set; } // 3 = second, 4 = minute, 5 = hour, 6 = day
void OneTimeTick();
}
Learn Concept of Events
Learn Basics of Interfaces
Learn Basics of Async
Learn Basics of Interfaces
Learn Basics of Async