add sborka
This commit is contained in:
51
garrysmod/addons/tacrp/lua/weapons/tacrp_base/sh_timers.lua
Normal file
51
garrysmod/addons/tacrp/lua/weapons/tacrp_base/sh_timers.lua
Normal file
@@ -0,0 +1,51 @@
|
||||
local tick = 0
|
||||
|
||||
function SWEP:InitTimers()
|
||||
self.ActiveTimers = {} -- { { time, id, func } }
|
||||
end
|
||||
|
||||
function SWEP:SetTimer(time, callback, id)
|
||||
if !IsFirstTimePredicted() then return end
|
||||
|
||||
table.insert(self.ActiveTimers, { time + CurTime(), id or "", callback })
|
||||
end
|
||||
|
||||
function SWEP:TimerExists(id)
|
||||
for _, v in pairs(self.ActiveTimers) do
|
||||
if v[2] == id then return true end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function SWEP:KillTimer(id)
|
||||
local keeptimers = {}
|
||||
|
||||
for _, v in pairs(self.ActiveTimers) do
|
||||
if v[2] != id then table.insert(keeptimers, v) end
|
||||
end
|
||||
|
||||
self.ActiveTimers = keeptimers
|
||||
end
|
||||
|
||||
function SWEP:KillTimers()
|
||||
self.ActiveTimers = {}
|
||||
end
|
||||
|
||||
function SWEP:ProcessTimers()
|
||||
local keeptimers, UCT = {}, CurTime()
|
||||
|
||||
if CLIENT and UCT == tick then return end
|
||||
|
||||
if !self.ActiveTimers then self:InitTimers() end
|
||||
|
||||
for _, v in pairs(self.ActiveTimers) do
|
||||
if v[1] <= UCT then v[3]() end
|
||||
end
|
||||
|
||||
for _, v in pairs(self.ActiveTimers) do
|
||||
if v[1] > UCT then table.insert(keeptimers, v) end
|
||||
end
|
||||
|
||||
self.ActiveTimers = keeptimers
|
||||
end
|
||||
Reference in New Issue
Block a user