SRL Archive - OSR Intermediate Scripting Tutorials

Adding a Break Procedure


Inception

2012-02-13 15:57:12

Adding a Break Procedure
by Inception


Because very few people can do one task for six hours straight, a good break procedure is crucial to avoid detection. I have noticed that not a lot of people are using break procedures in their scripts, so I have decided to make a tutorial that will go over the very basics of breaking.

The breaking system that I use includes a few separate procedures, as well as a few modifications to existing procedures. I will discuss each procedure and modification in detail below. Keep in mind that this is a very basic template and additions/modifications should be made!

Global Variable

We will use this global variable as a timer. You should add this variable to the rest of your global variables.

var
BreakTime: Integer;

DeclarePlayers

This is the variation of DeclarePlayers I use. Feel free to use your own variation with the included values.

Notice the Boolean and Integer values that have been added.

{$i SRL\SRL.simba} 

procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

with Players[0] do
begin
Name := '';
Pass := '';
Pin := '';
Active := True;

Booleans[0] := True; // Take breaks

Integers[0] := 50; // Minimum time to play before breaking
Integers[1] := 120; // Maximum time to play before breaking
end;
end;
Booleans[0] - Gives the user the option to take breaks.
Integers[0..1] - We will use these numbers later to generate a timer.

ResetBreakTimer

This is a very basic procedure that you will need to add to your script. It simply sets the BreakTimer value by getting the system time and adding a random value (in our case, 50-120 minutes) to it.

Notice that we use the Integer values from DeclarePlayer here. The values are multiplied by 60000 to convert the Integers into minutes.

{*******************************************************************************
procedure ResetBreakTimer;
Description: Resets the timer.
*******************************************************************************}
procedure ResetBreakTimer;
begin
BreakTime := GetSystemTime + RandomRange(Players[CurrentPlayer].Integers[0] * 60000, Players[CurrentPlayer].Integers[1] * 60000);
end;

TakeBreak

This is another procedure that you will need to add to your script. We will be calling this procedure at the end of each script loop.

{**************************************************************************
procedure TakeBreak;
Description: Logs your character out for a random time.
**************************************************************************}
procedure TakeBreak;
var
H, M, S, T, BreakFor: Integer;
begin
if (GetSystemTime >= BreakTime) and Players[CurrentPlayer].Booleans[0] then
begin
Logout;
BreakFor := RandomRange(10 * 60000, 25 * 60000); // Between 10-25 minutes
ConvertTime(BreakFor, H, M, S);
Writeln('Break for: ' + IntToStr(M)+ 'm:' + IntToStr(S)+ 's');
MarkTime(T);
Repeat
Wait(1000);
until (BreakFor < TimeFromMark(T))
LogInPlayer;
ResetBreakTimer; // Important!!!
Wait(4000);
FindNormalRandoms;
end;
end;

This procedure tests whether the system time is greater than BreakTime. If it is and your Boolean value is set to True, your character is logged out for a random amount of time (10-25 minutes in our case - feel free to change these values as needed). The length of the break is written to the debug box in Simba. After the time from the start of the break is greater than the break length, your player is logged back in and ResetBreakTimer is called.

**It is very important to call ResetBreakTimer or you will take a break again when TakeBreak is called!!**

ScriptStart

This is a very generalized procedure that I use. This should be modified for your script!

{**************************************************************************
procedure ScriptStart;
Description: Actions to perform at the beginning of the script.
**************************************************************************}
procedure ScriptStart;
begin
ClearDebug;
Smart_Server := 22;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
SetupSRL;

DeclarePlayers;
LoginPlayer;
Wait(4000);
ResetBreakTimer; // Important!!!
end;

The main thing to take away from this example is to call ResetBreakTimer at the beginning of your script.

MainLoop

Again, this is a very generalized procedure that I use.

{**************************************************************************
procedure MainLoop;
Description: The main loop.
**************************************************************************}
procedure MainLoop;
begin
ScriptStart;
repeat
{....}

{Main loop}

{....}
TakeBreak; // Important!!
until not LoggedIn;
end;
This should be modified for your script!


I hope this tutorial helped you add break functions to your future and existing scripts! Feel free to post any comments or suggestions you have!
-Inception

Nemesis3X

2012-02-16 14:26:49

I tried It and it Works. Thanks you for the tutorial