Breaks API
Query and control the script break system. Breaks are scheduled by the user and can pause script execution for a configured duration.
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
trueto allow the break to start now - Return
falseto 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.
breaks.is_active() -> boolean
Check if currently on break.
breaks.time_remaining() -> number
Time left in current break (seconds). Returns -1 if not on break.
breaks.time_until_next() -> number
Time until next scheduled break (seconds). Returns -1 if no break scheduled.
breaks.should_break() -> boolean
Check if it's time for a break (based on schedule).
breaks.start() -> number
Manually start a break. Returns duration in seconds, or -1 if not started.
breaks.should_resume() -> boolean
Check if the current break should end (e.g. duration expired).
breaks.resume() -> ()
Manually end the current break.
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.
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
- Script Structure and Setup -
can_breakcallback and script lifecycle