SHARE
TWEET

glua

usernamesad Dec 16th, 2018 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local timer = timer or {}
  2. local timers = {}
  3.  
  4. function timer.Create(name, delay, times, func)
  5.  
  6.     table.insert(timers, {["name"] = name, ["delay"] = delay, ["times"] = times, ["func"] = func, ["lastTime"] = globals.RealTime()})
  7.  
  8. end
  9.  
  10. function timer.Remove(name)
  11.  
  12.     for k,v in pairs(timers or {}) do
  13.    
  14.         if (name == v["name"]) then table.remove(timers, k) end
  15.    
  16.     end
  17.  
  18. end
  19.  
  20. function timer.Tick()
  21.  
  22.     for k,v in pairs(timers or {}) do
  23.    
  24.         if (v["times"] <= 0) then table.remove(timers, k) end
  25.        
  26.         if (v["lastTime"] + v["delay"] <= globals.RealTime()) then
  27.             timers[k]["lastTime"] = globals.RealTime()
  28.             timers[k]["times"] = timers[k]["times"] - 1
  29.             v["func"]()
  30.         end
  31.    
  32.     end
  33.  
  34. end
  35.  
  36. callbacks.Register( "Draw", "timerTick", timer.Tick);
  37.  
  38. timer.Create("test", 1, 2, function() print("hey") end)
  39. PM Find Rate Reply Quote Report
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top