One Time

One Time Beta v1.0.0.17

No permission to download
***** 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 5 timers (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.

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.

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
101
Views
1,858
First release
Last update
Rating
5.00 star(s) 3 ratings

More resources from GoldDraco13

Latest Updates

  1. Update

    *Reworked the System, Fixed some bugs and polished up the code! *Add support and feedback...
  2. Update

    *Updates system, now runs on all servers from RunUO 2.3 to Latest ServUO Repo
  3. Update

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

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

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