TomTuff
12-27-2010, 11:49 PM
There are many functions available in the SRL include that can makes script more effective in many ways. They allow the avoidance of static waits (i.e. Wait(Amount + Random(Int)); ). They allow the script to continue on as soon as possible. They also allow the script to be able to handle lag better.
Let's take an example of clicking a tree. Once you mouse to the tree, you would naturally check for the uptext next, right? Most people would do something like Wait(800 + Random(80)); after they have MMouse'd. However, in cases of lag and slow computers, the uptext might not show up in this time. On faster computers, the uptext might have come up in about 100 ms. You could instead use WaitUptext('illow', 1200);. Let's compare how this would work to how a human plays: A human KNOWs it's going to have its mouse pointer on that tree. They wouldn't look at the uptext. The only reason our scripts do is to make sure we did things right. So, using WaitOption, we continue on as soon as we can, thus seeming more human like.
Here are some of the best functions in timing.scar:
{************************************************* ******************************
function WaitOption(S: String; Time: Integer): Boolean;
By: N1ke!
Description: Waits for an Option and selects it
************************************************** *****************************}
{************************************************* ******************************
function WaitOptionMulti(S: TStringArray; Time: Integer): Boolean;
By: Marpis, N1ke! & Rasta Magician
Description: Waits for a TStringArray of options and selects one of them
************************************************** *****************************}
{************************************************* ******************************
function WaitUptext(S: String; Time: Integer): Boolean;
By: Marpis edited by N1ke!
Description: Waits for an UpText, returns true if found
************************************************** *****************************}
{************************************************* ******************************
function WaitUpTextMulti(S: TStringArray; Time: integer): Boolean;
By: Marpis & N1ke!
Description: Waits for a TStringArray of UpText, returns true if found
************************************************** *****************************}
{************************************************* ******************************
function WaitFunc(Func: Function: Boolean; WaitPerLoop, MaxTime: Integer): Boolean;
By: Rasta Magician, small edit by EvilChicken!
Description: Waits for function Func to be true. WaitPerLoop is how often you
want to call "Func" function.
Example: "WaitFunc(@BankScreen, 10 + Random(15), 750);" will check if BankScreen
is open every 10-25th millisecond, for a maximum of 750 milliseconds.
Notice the '@'.
************************************************** *****************************}
//^Personal favorite
{************************************************* ******************************
function WaitFindColors(var x, y: integer; Color, Tol, x1, y1, x2, y2, MaxTime: integer): Boolean;
By: IceFire908 based completely off WaitFindColor
Description: Waits for a color at (x, y) with tolerance Tol, returns true if found
************************************************** *****************************}
{************************************************* ******************************
function WaitInvCount(Count, MaxTime: Integer; CountType: (MaxCT, MinCT, ExactCT)): boolean;
By: Rasta Magician
Description: Waits for a maximum inv count. Returns true if InvCount <= Count
************************************************** *****************************}
//all found in timing.scar of SRL
It's small, but it can make a huge difference in the human-likeness and efficiency of your scripts.
Here are some examples of when using these functions could be used.
Ex 1: Result.
Using some of these functions could be used to return a boolean in a function.
function OpenTheBank: Boolean;
begin
//banking stuff
Result := WaitFunc(@BankScreen, 10 + Random(5), 4000);
end;
you could also use WaitInvCount.
function WithdrawSomeItem: Boolean;
begin
//stuff here
Result := WaitInvCount(1, 4000, MinCT);
end;
Ex 2: Uptext, Options
you could replace this
function ClickRock: Boolean;
var
Rock: TPoint;
begin
Rock := FindRock;
MMouse(Rock.X, Rock.Y, 4, 4);
Wait(200 + Random(20));
if IsUptext('oal') then
begin
ClickMouse2(False);
Result := ChooseOption('ine');
end;
end;
with
function ClickRock: Boolean;
var
Rock: TPoint;
begin
Rock := FindRock;
MMouse(Rock.X, Rock.Y, 4, 4);
if WaitUptext('oal', 1200) then //see here
begin
ClickMouse2(False);
Result := WaitOption('ine', 1200); //and here
end;
end;
Protip: When searching for options or uptext, i generally make the max time be 400 * number of chars you're searching for.
Let's take an example of clicking a tree. Once you mouse to the tree, you would naturally check for the uptext next, right? Most people would do something like Wait(800 + Random(80)); after they have MMouse'd. However, in cases of lag and slow computers, the uptext might not show up in this time. On faster computers, the uptext might have come up in about 100 ms. You could instead use WaitUptext('illow', 1200);. Let's compare how this would work to how a human plays: A human KNOWs it's going to have its mouse pointer on that tree. They wouldn't look at the uptext. The only reason our scripts do is to make sure we did things right. So, using WaitOption, we continue on as soon as we can, thus seeming more human like.
Here are some of the best functions in timing.scar:
{************************************************* ******************************
function WaitOption(S: String; Time: Integer): Boolean;
By: N1ke!
Description: Waits for an Option and selects it
************************************************** *****************************}
{************************************************* ******************************
function WaitOptionMulti(S: TStringArray; Time: Integer): Boolean;
By: Marpis, N1ke! & Rasta Magician
Description: Waits for a TStringArray of options and selects one of them
************************************************** *****************************}
{************************************************* ******************************
function WaitUptext(S: String; Time: Integer): Boolean;
By: Marpis edited by N1ke!
Description: Waits for an UpText, returns true if found
************************************************** *****************************}
{************************************************* ******************************
function WaitUpTextMulti(S: TStringArray; Time: integer): Boolean;
By: Marpis & N1ke!
Description: Waits for a TStringArray of UpText, returns true if found
************************************************** *****************************}
{************************************************* ******************************
function WaitFunc(Func: Function: Boolean; WaitPerLoop, MaxTime: Integer): Boolean;
By: Rasta Magician, small edit by EvilChicken!
Description: Waits for function Func to be true. WaitPerLoop is how often you
want to call "Func" function.
Example: "WaitFunc(@BankScreen, 10 + Random(15), 750);" will check if BankScreen
is open every 10-25th millisecond, for a maximum of 750 milliseconds.
Notice the '@'.
************************************************** *****************************}
//^Personal favorite
{************************************************* ******************************
function WaitFindColors(var x, y: integer; Color, Tol, x1, y1, x2, y2, MaxTime: integer): Boolean;
By: IceFire908 based completely off WaitFindColor
Description: Waits for a color at (x, y) with tolerance Tol, returns true if found
************************************************** *****************************}
{************************************************* ******************************
function WaitInvCount(Count, MaxTime: Integer; CountType: (MaxCT, MinCT, ExactCT)): boolean;
By: Rasta Magician
Description: Waits for a maximum inv count. Returns true if InvCount <= Count
************************************************** *****************************}
//all found in timing.scar of SRL
It's small, but it can make a huge difference in the human-likeness and efficiency of your scripts.
Here are some examples of when using these functions could be used.
Ex 1: Result.
Using some of these functions could be used to return a boolean in a function.
function OpenTheBank: Boolean;
begin
//banking stuff
Result := WaitFunc(@BankScreen, 10 + Random(5), 4000);
end;
you could also use WaitInvCount.
function WithdrawSomeItem: Boolean;
begin
//stuff here
Result := WaitInvCount(1, 4000, MinCT);
end;
Ex 2: Uptext, Options
you could replace this
function ClickRock: Boolean;
var
Rock: TPoint;
begin
Rock := FindRock;
MMouse(Rock.X, Rock.Y, 4, 4);
Wait(200 + Random(20));
if IsUptext('oal') then
begin
ClickMouse2(False);
Result := ChooseOption('ine');
end;
end;
with
function ClickRock: Boolean;
var
Rock: TPoint;
begin
Rock := FindRock;
MMouse(Rock.X, Rock.Y, 4, 4);
if WaitUptext('oal', 1200) then //see here
begin
ClickMouse2(False);
Result := WaitOption('ine', 1200); //and here
end;
end;
Protip: When searching for options or uptext, i generally make the max time be 400 * number of chars you're searching for.