Skip to content

Instantly share code, notes, and snippets.

@Romain-P
Last active August 28, 2018 23:31
Show Gist options
  • Select an option

  • Save Romain-P/1818ae6dd6eec39dcdd69fe843a27d64 to your computer and use it in GitHub Desktop.

Select an option

Save Romain-P/1818ae6dd6eec39dcdd69fe843a27d64 to your computer and use it in GitHub Desktop.
Wow Timers | Lua
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