Timer = {}

function DoTimers()
	for key in Timer do
		if Timer[key].time + Timer[key].delay < _CurTime() then
			if Timer[key].reps > 1 then
				Timer[key].reps = Timer[key].reps - 1
				Timer[key].func(unpack(Timer[key].arg))
			elseif Timer[key].reps == 1 then
				Timer[key].func(unpack(Timer[key].arg))
				Timer[key] = nil
			else
				Timer[key].func(unpack(Timer[key].arg))
			end
			if Timer[key] then Timer[key].time = _CurTime() end
		end
	end
end

function AddTimer(delay, reps, func, ...)
	local i = 1
	while Timer[i] do
		i = i + 1
	end
	Timer[i] = {}
	Timer[i].delay 	= delay
	Timer[i].time 	= _CurTime()
	Timer[i].func 	= func
	Timer[i].arg 	= arg
	Timer[i].reps 	= reps
	return i
end

function HaltTimer(timer)
	if Timer[timer] then Timer[timer] = nil end
end

AddThinkFunction(DoTimers)
