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

function schedule(i, delay, reps, func, ...)
	Schedule[i] = {}
	Schedule[i].delay 	= delay
	Schedule[i].time 	= _CurTime()
	Schedule[i].func 	= func
	Schedule[i].arg 	= arg
	Schedule[i].reps 	= reps
	return i
end

function HaltSchedule(i)
	Schedule[i] = nil
end

AddThinkFunction(DoSchedules)
