Skip to content

Conversation

@BaldPRs
Copy link
Contributor

@BaldPRs BaldPRs commented Jan 3, 2026

Problem:

TimeUntilBreak is awkward for programmatic use. It returns a formatted string, which is useful for logging but requires parsing to use in logic. To retrieve the MS until an antiban sleep or break you have to use something similar to the example code which is difficult to read, and mentioned nowhere in the docs.

Suggestion:

Add two helper functions that return the raw milliseconds until the next scheduled break/sleep (if one exists):
MsUntilBreak(): Double
MsUntilSleep(): Double

Example Before:

{$I WaspLib/osrs.simba}

begin
  if ((Length(Antiban.Breaks) > 0) and (Antiban.Breaks[0].Next - GetTimeRunning() < Random(140, 240) * ONE_SECOND)) or
     ((Length(Antiban.Sleeps) > 0) and (Antiban.Sleeps[0].Next - GetTimeRunning() < Random(140, 240) * ONE_SECOND)) then
    WriteLn('Break coming soon!');
end;

Example After:

{$I WaspLib/osrs.simba}

begin
  if (Antiban.MsUntilBreak() < Random(140, 240) * ONE_SECOND) or
     (Antiban.MsUntilSleep() < Random(140, 240) * ONE_SECOND) then
    WriteLn('Break coming soon!');
end;

Use Case

A Scripter wants to clean up or perform specific actions before a break interrupts execution. This helper now allows the scripter to perform a simple MS comparison against the upcoming break/sleep.

@BaldPRs BaldPRs changed the title Add MsUntilBreak, and MsUntilSleep AntiBan helpers feat: Add MsUntilBreak, and MsUntilSleep AntiBan helpers Jan 3, 2026
@BaldPRs BaldPRs changed the title feat: Add MsUntilBreak, and MsUntilSleep AntiBan helpers feat(Antiban): Add MsUntilBreak, and MsUntilSleep AntiBan helpers Jan 3, 2026
@Torwent
Copy link
Collaborator

Torwent commented Jan 7, 2026

If you give me a good use case I'll merge it 😉

The use case you gave is not a good one! It already has a solution:

TAntiban = record  
  //...
  //...
  OnStartTask,  OnFinishTask:  procedure(task: PAntibanTask) of object;
  OnStartBreak, OnFinishBreak: procedure(task: PBreakTask)   of object;
  OnStartSleep, OnFinishSleep: procedure(task: PSleepTask)   of object;
  //...
  //...
end;

And this solution is better because what you are suggesting for the scripter to know there's a break coming is misleading.
A break can be due but it will never happen unless the scripter calls Antiban.DoAntiban().

The built-in approach however runs every time at the start of the task, break or sleep when you are actually going to do it for sure and as a bonus you also have OnFinish callbacks to restore your script properly if you need.

TimeUntilBreak and TimeUntilSleep is awkward to use programatically because they are not meant to be used programatically. They are meant to show a string to users. What you want is the OnStart callbacks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants