-- Define the amount of time that needs to countdown.
local wait = {
    waitEvents = {}
}

-- Runs each tick.
function events.TICK()
    -- Subtract one from each event every tick.
    for id, values in pairs(wait.waitEvents) do
        -- When the event hits 0 or less run the function.
        if values[1] <= 0 then
            -- Run the function.
            values[2]()
            -- Remove the value from the table.
            wait.waitEvents[id] = nil
        end

        -- If the value still exists in the table then remove 1.
        if wait.waitEvents[id] ~= nil then
            wait.waitEvents[id][1] = values[1] - 1
        end
    end
end

function wait.schedule(ticks, execute)
    -- Add the amount of ticks to the wait.waitEvents variable.
    table.insert(wait.waitEvents, { ticks, execute })
    -- Return the value of the schedule in the table.
    return #wait.waitEvents
end

function wait.cancel(event_id)
    -- Cancel the event by removing it from the table.
    wait.waitEvents[event_id] = nil
end

return wait
