Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- timers = {}
- timers.id = 0
- timers.list = {}
- timers.toremove = {}
- timers.new = function ( tic, loop, ... )
- timers.id = timers.id + 1
- local id = timers.id
- local time = 0
- local fct = {...}
- local timer = function()
- time = time + 1
- if time >= tic then
- for _,f in ipairs(fct) do
- f()
- end
- if loop then time = 0
- else table.insert(timers.toremove, id)
- end
- end
- end
- timers.list[id] = timer
- return id
- end
- timers.remove = function ()
- while(#timers.toremove~=0) do
- timers.list[timers.toremove[1]] = nil
- table.remove(timers.toremove, 1)
- end
- end
- timers.loop = function()
- for id, timer in pairs(timers.list) do
- timer()
- end
- timers.remove()
- end
- timers.delete = function (id)
- timers.list[id] = nil
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement