Timers4TFM

Timers4TFM

Timers4TFM

All Contributors GitHub file size in bytes GitHub Workflow Status CodeFactor Grade GitHub GitHub release (latest by date including pre-releases)

A library which provides easy and advanced timers for module developers

:warning: This library is still in beta phase. Use at your own risk! Contributions are always welcome

What is this?

A library which provides easy and advanced timers for module developers.

This project is inspired by mk’s timer library, make sure to support that project too :heart:

Background

As normal players - who aren’t in module team - aren’t allowed to use the Module API’s timers (system.newTimer and system.removeTimer), I decided to create a brand new, advanced timer system for the benefit of all!

There are many capabilities for these timers

How to use?

To use this library you need to insert this libraries code in top of your code.

Use the full code (Recommended for studying) | Use the minified version (Recommended for production use)


Examples

Creating new timer

--insert the library code here

local timer1 = Timer("timer1", function() end, 5000, false) -- Creating a very basic timer with a timeout value of 5000

function eventLoop()
  Timer.process() -- You need to call this method inside eventLoop to start and process timers
end


Documentation

Creating timers with callbacks


--a function to greet a user
function greet(name, nice)
    print("Hello" .. name .. "It seems you are " .. (nice and "nice" or "not nice"))
end

-- storing the timer in a variable is optional. Storing will be useful if you need to access information about the timer

Timer("callback", greet, 2000, false, "Seniru", true) --setting the callback to our greet function and pass "Seniru" and true as arguments

function eventLoop()
    Timer.process()
end

--Run this code to see the results!

Documentation

Looping timers


Timer("looping", function() print("prints") end, 3000, true)
-- This would print `prints` every 3 seconds. Note that you need to specify the time in milliseconds

Documentation

Contributing

Do you want to contribute this project? Great! There are many way that you can involve!

Creating issues You can create issues for,
Creating PRs You can submit a PR for,

Please, make sure that you have searched well before creating a new issue or a pull request. I’m actively responding to all kind of contributions :smile:

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Seniru Pasan Indira
Seniru Pasan Indira

💻
All Contributors
All Contributors

🚇
Lautenschlager
Lautenschlager

💻 🐛
Iván
Iván

🐛

This project follows the all-contributors specification. Contributions of any kind welcome!