Breaks API

Breaks API

Query and control the script break system. Breaks are scheduled by the user and can pause script execution for a configured duration.

Break Control Callback: can_break

Scripts can optionally define a can_break function on their script table to control when scheduled breaks occur. This is a script lifecycle callback, not a function on the breaks module.

When the break system wants to start a break, it calls your script's can_break function:

  • Return true to allow the break to start now
  • Return false to defer the break until a better time

If can_break is not defined, breaks are always allowed when scheduled. The system will re-check until it returns true or the schedule changes.

Example:

local script = {
    name = "MyScript",
    version = "1.0.0"
}

function script:can_break()
    -- Don't break during combat
    local player = players:local_player()
    if player and player:in_combat() then
        return false
    end

    -- Don't break while banking
    if bank.is_open() then
        return false
    end

    return true  -- Safe to take a break
end

function script:on_start()
    return true
end

function script:poll()
    -- Script logic with breaks.handle() integration
    if breaks.handle() then
        sleep(1000)  -- On break
        return
    end
    -- Do work...
    sleep(50)
end

return script

See Script Structure and Setup - Break Control Callback for full documentation.


Functions

is_active

breaks.is_active() -> boolean

Check if currently on break.


time_remaining

breaks.time_remaining() -> number

Time left in current break (seconds). Returns -1 if not on break.


time_until_next

breaks.time_until_next() -> number

Time until next scheduled break (seconds). Returns -1 if no break scheduled.


should_break

breaks.should_break() -> boolean

Check if it's time for a break (based on schedule).


start

breaks.start() -> number

Manually start a break. Returns duration in seconds, or -1 if not started.


should_resume

breaks.should_resume() -> boolean

Check if the current break should end (e.g. duration expired).


resume

breaks.resume() -> ()

Manually end the current break.


status

breaks.status() -> table

Get full break status table with keys: active, total_breaks, total_minutes, session_minutes, next_break_seconds, next_break_minutes, remaining_seconds, remaining_minutes.


handle

breaks.handle() -> boolean

One-function break handler for scripts. Starts breaks when scheduled, ends them when done. Returns true if on break (caller should sleep/return), false otherwise.

Example usage in poll:

function script:poll()
    if breaks.handle() then
        logger:info("On break...")
        sleep(1000)
        return
    end

    -- Do script work
    perform_action()
    sleep(50)
end