One Time

One Time 1.0.0.15

No permission to download
Requirements
Using [.Net 4.7.2] (Min Version Compatibility)
ServUO Pub 57 & Earlier : No Support for any pub after 57!
***** Rate this Resource if you find it useful *****

One Time replaces the need to use timers, it uses events & interfaces instead in creative ways!

Vorspire said:
The concept is neat and the example implementation looks great.
It's easy to use and implement for any dev, which means it's going to be a popular download.
OneTimeLO.jpg


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
OT1008_Test.png



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
Author
GoldDraco13
Downloads
52
Views
741
First release
Last update
Rating
5.00 star(s) 2 ratings

More resources from GoldDraco13

Latest updates

  1. Update

    *Cleaned up the code, removed the debug messages! *Added a Pause while Server Saving to avoid...
  2. Update

    *Fixed a potential issue with DateTime.Now
  3. Update

    *Fixed a issue with CPU Usage - Was coming from the Tick and Millisecond IOneTime methods...

Latest reviews

Just figured out how to use this system and i must say it makes timers MUCH easier and streamlined. no need to create timers in each scripts, all you need to do it hook a script up to onetime and your script is connected to a central timer. great idea, works well (we are running runuo).
GoldDraco13
GoldDraco13
Thanks for the awesome remarks, I am happy that it works well on RunUO! I look forward to seeing where this project goes overtime, I'm sure it'll get better each update it receives which is driven by feedback! Thanks again!
awesome idea, i hate writing timers :P
GoldDraco13
GoldDraco13
Thanks, I have been working on ways to limit the use of them, which has lead me to creating just one! Combined with Async Methods OnEventTick = Powerful!