Last active
August 28, 2018 23:31
-
-
Save Romain-P/1818ae6dd6eec39dcdd69fe843a27d64 to your computer and use it in GitHub Desktop.
Wow Timers | Lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if not timers then | |
| timers = true | |
| callback_timers = {} | |
| function TableSize(table) | |
| local count = 0 | |
| for _,_ in pairs(table) do | |
| count = count + 1 | |
| end | |
| return count | |
| end | |
| function NewTimer(millis, func) | |
| local instance = "timer" .. TableSize(callback_timers) | |
| callback_timers[instance] = { | |
| frame = CreateFrame("Frame", nil, UIParent), | |
| callback = func, | |
| rate = millis / 1000, | |
| rate_counter = 0 | |
| } | |
| callback_timers[instance].frame:SetScript("OnUpdate", | |
| function(self, elapsed) | |
| callback_timers[instance].rate_counter = callback_timers[instance].rate_counter + elapsed | |
| if callback_timers[instance].rate_counter > callback_timers[instance].rate then | |
| callback_timers[instance].callback() | |
| callback_timers[instance].rate_counter = 0 | |
| end | |
| end | |
| ) | |
| callback_timers[instance].frame:Show() | |
| return instance | |
| end | |
| function DeleteTimer(timer) | |
| callback_timers[timer].frame:Hide() | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment