heres one that i used a while back. playRange is just what the user enters, for example between 200 and 300 minutes … same with breakRange, eg 10 to 15 minutes.
this bit goes in my main bit, inside the repeat loop …
nextBreak := GetTimeRunning + RandomRange(playRange[0], playRange[1]);
breakLength := RandomRange(breakRange[0], breakRange[1]);
repeat
if (nextbreak < GetTimeRunning) and (playRange[1] > 0) then // playerRange[1] >0 is just to check it has a value
begin
MyDebug('starting to break');
breakLoop(breakLength);
nextBreak := GetTimeRunning + RandomRange(playRange[0], playRange[1]); // get a new time for nextBreak and breakLength
breakLength := RandomRange(breakRange[0], breakRange[1]); // so it changes every break.
end;
if not LoggedIn then
begin
if attempts >3 then
begin
terminatescript;
end;
LogInPlayer;
inc(attempts);
end;
attempts := 0;
MainLoop;
until(false)
and then the actual breakLoop procedure:
procedure breakLoop(length: Integer);
var
timeLeft: integer;
begin
timeLeft := length;
MyDebug('starting break for: ' + inttostr(timeLeft));
while(Incombat) do // made for a combat script so what this does is ensure that it is able to logout before trying
begin // to log out, there are other ways that you could do this,
while(Incombat) do // but for some reason i chose this way :)
begin
eat;
ProduceProgressReport;
wait(500);
end;
wait(13000);
end;
Logout;
SMART_DrawTextEx(false, 50, 50, 'UpChars07', 'Breaking For:', 62207); // when logged out i had a little countdown
SMART_DrawTextEx(false, 50, 75, 'UpChars07', MyGetTimeRunning(timeLeft), 62207); // timer thing on the go so if you user looks
SMART_DrawTextEx(false, 50, 125, 'UpChars07', 'Break Time Left:', 62207); // they can see how long is left
while (timeLeft > 0) do
begin
SMART_ClearCanvasArea(IntToBox(45,145,250,175));
SMART_DrawTextEx(false, 50, 150, 'UpChars07', MyGetTimeRunning(timeLeft) , 62207);
timeLeft := timeLeft - 1000;
wait(1000);
end;
end;
well thats how i implemented a break function into a script of mine before, if i came at it again i might go a slightly different way, but this still works pretty well :D