Advertisement
KananGamer

[TFM-LUA] sleep()

Oct 24th, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | None | 0 0
  1. --[[
  2.     Author(s): Nettoork#0000
  3. ]]--
  4.  
  5. do
  6.     local coroutines = {}
  7.     avl = function()
  8.         local toRemove = {}
  9.         for i, v in next, coroutines do
  10.             if not v[2] or v[2] < os.time() then
  11.                 if (coroutine.status(v[1]) == 'dead') then
  12.                     toRemove[#toRemove+1] = i
  13.                 else
  14.                     local s, timerV = coroutine.resume(v[1])
  15.                     v[2] = timerV
  16.                 end
  17.             end
  18.         end
  19.         if (toRemove[1]) then
  20.             for i, v in next, toRemove do
  21.                 coroutines[v] = nil
  22.             end
  23.         end
  24.     end
  25.     timer = function(f)
  26.         local pauseList = nil
  27.         coroutines[#coroutines + 1] = {coroutine.create(function()
  28.             local pause = function(n)
  29.                 coroutine.yield(os.time() + math.floor(n/500)*500)
  30.             end
  31.             f(pause)
  32.         end), timeValue = nil}
  33.     end
  34. end
  35.  
  36. eventLoop = avl
  37.  
  38. --[[ Example
  39.  
  40. timer(function(sleep)
  41.     for i = 1, 10 do
  42.         print(i)
  43.         sleep(1000)
  44.     end
  45. end)
  46.  
  47. timer(function(sleep)
  48.     for i = 1, 20 do
  49.         print('Hello World!')
  50.         sleep(500)
  51.     end
  52. end)
  53.  
  54. ]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement