SRL Archive - SRL Archives

All my functions


Cazax

2009-01-19 10:48:58

SRL/SRL/Core/Bank.scar:
Function WithdrawSearch(ItemName : String; Amount : Integer): Boolean;
Begin
If Not LoggedIn Then
Exit;
SearchBank(ItemName);
Wait(250 + Random(500));
Result := CountColor(65536, 29, 90, 146, 138) <> 0;
If Result Then
Begin
If Amount = 1 Then
MouseBox(36, 98, 70, 123, 1)
Else
Begin
MouseBox(36, 98, 70, 123, 2);
Wait(100 + Random(100));
If InIntArray([5, 10], Amount) Then
ChooseOption('Withdraw-' + IntToStr(Amount))
Else
Begin
ChooseOption('X');
Wait(250 + Random(250));
TypeSend(IntToStr(Amount));
End;
End;
Wait(500 + Random(500));
End Else
MouseBox(31, 52, 67, 80, 1);
End;
Withdraws an item using the search item tool. Will withdraw the first item.

SRL/SRL/Core/Text.scar:
Function IsOption(Text : String): Boolean;
Var
TPA : TPointArray;
Box : TBox;
Begin
FindColorsTolerance(TPA, 4674653, 0, 0, 764, 502, 0);
Box := GetTPABounds(TPA);
Result := FindText(X, Y, Text, UpChars, Box.X1, Box.Y1, Box.X2, Box.Y2);
End;
Similar to chooseOption but without choosing the option. Useful with the new bank withdraw option:
Withdraw-1
Withdraw-5
Withdraw-10
Withdraw-LastWithdraw
Withdraw-X


Function FastMSFindText(Text : String): Boolean;
Var
TPA, TPA2, temp2 : TPointArray;
temp : Integer;
Begin
FindColorsTolerance(TPA, 65535, MSX1, MSY1, MSX2, MSY2, 0);
TPA2 := LoadTextTPA(Text, UpChars, temp);
Result := FindTPAinTPA(TPA2, TPA, temp2);
End;
Finds the texts in the main screen and searches if your text was found there(useful for autoresponders).


(New): SRL/SRL/Misc/ClanChat.scar:

Function InChat: Boolean;
Begin
Result := GetColor(599, 449) = 0;
End;

Function JoinClanChat(Name : String): Boolean;
Var
temp : Integer;
Begin
temp := GetCurrentTab;
GameTab(10);
Result := Not InChat;
If Result Then
Begin
MouseBox(569, 438, 629, 458, 1);
Wait(235 + Random(250));
TypeSend(Name);
End;
GameTab(temp);
End;

Function LeaveClanChat: Boolean;
Var
temp : Integer;
Begin
temp := GetCurrentTab;
GameTab(10);
Result := InChat;
If Result Then
MouseBox(569, 438, 629, 458, 1);
GameTab(temp);
End;
Function InChat:
Returns true if the player is in a clan chat.

function JoinClanChat:
Returns true if joined to a clan chat,

function LeaveClanChat:
Returns true if clan chat was left.

(New)SRL/SRL/Misc/WorldMap.scar:

Procedure OpenWorldMap;
Begin
If Not LoggedIn Then
Exit;
MouseBox(531, 125, 559, 156);
End;

Function IsLoading: Boolean;
Begin
Result := GetColor(20, 80) = 0;
End;

Procedure WaitWhileLoading;
Var
TFM : Integer;
Begin
MarkTime(TFM);
While IsLoading Do
If TimeFromMark(TFM) > 3000 Then
Begin
MMouse(Random(700), Random(700), Random(100), Random(100));
MarkTime(TFM);
End;
End;

Procedure CloseWorldMap;
Begin
MouseBox(741, 11, 754, 24, 1);
Wait(750 + Random(751));
End;

procedure OpenWorldMap:
Opens world map

function IsLoading:
returns true if the screen is loading

procedure WaitWhileLoading:
Waits until the world map has loaded

procedure CloseWorldMap:
closes the world map


Somewhere in SRL:
Function MiddleBox(Xs, Ys, Xe, Ye : Integer): TPoint;
Begin
Result.X := (Xs + Xe) Shr 1;
Result.Y := (Ys + Ye) Shr 1;
End;


and here is my little include:

Type
TCol = Record
R, G, B : Integer; // R G B Values
H, S, L : Extended; // H S L Values
X, Y, Z : Extended; // X Y Z Values

RGBTolerance : Integer; //RGB Tolerance
HSLTolerance : Integer;// HSL Tolerance
XYZTolerance : Integer;// XYZ Tolerance

Color : TColor; // The Color
End;

TColorArray = Array Of TCol;

TColorSpace = (RGB, HSL, XYZ);

{*******************************************************************************
function SetupColor(Color : TColor): TCol;
By: Cazax
Description: Returns RGB, HSL and XYZ values in TCol
*******************************************************************************}
Function SetupColor(Color : TColor): TCol;
Begin
ColorToRGB(Color, Result.R, Result.G, Result.B);
ColorToHSL(Color, Result.H, Result.S, Result.L);
ColorToXYZ(Color, Result.X, Result.Y, Result.Z);
Result.Color := Color;
End;

{*******************************************************************************
function SetupColors(Colors : TIntegerArray): TColorArray;
By: Cazax
Description: Returns RGB, HSL and XYZ values of all colors in a TColorArray
*******************************************************************************}
Function SetupColors(Colors : TIntegerArray): TColorArray;
Var
I, H : Integer;
Begin
H := High(Colors);
SetLength(Result, Length(Colors));
For I := 0 To H Do
Result[I] := SetupColor(Colors[I]);
End;

{*******************************************************************************
function GetTolerance(Col1, Col2 : TColor; CTS : TColorSpace): Integer;
By: Cazax
Description: Finds the tolerance between two colors.
Col1: Color 1
Col2: Color 2
CTS: The ColorToleranceSpeed to compare colors with (if you don't know what it is just put RGB). Can RGB, HSL or XYZ

*******************************************************************************}
Function GetTolerance(Col1, Col2 : TColor; CTS : TColorSpace): Integer;
Var
I : Integer;
V : Variant;
Begin
V := CTS;
ColorToleranceSpeed(V);
For I := 0 To 442 Do
If SimilarColors(Col1, Col2, I) Then
Begin
Result := I;
Exit;
End;
ColorToleranceSpeed(1);
End;

{*******************************************************************************
function AutoColorIt(Color : TColor): Integer;
By: Cazax
Description: Finds the most similar color in the minimap. Use it for autocoloring

*******************************************************************************}

Function AutoColorIt(Color : TColor): Integer;
Var
TPA, TPA2 : TPointArray;
I, J, bestCol, maxTol : Integer;
Cols : TIntegerArray;
Begin
SetLength(TPA2, 0);
FindColorsTolerance(TPA, Color, MMX1, MMY1, MMX2, MMY2, 25);
For I := 0 To High(TPA) Do
If rs_OnMinimap(TPA[i].X, TPA[i].Y) Then
Begin
SetArrayLength(TPA2, Length(TPA2) + 1);
TPA2[High(TPA2)] := TPA[i];
End;
Cols := GetColors(TPA2);
maxTol := 50;
For I := 0 To High(Cols) Do
If SimilarColors(Cols[i], Color, maxTol) And (Cols[i] <> bestCol) Then
Begin
bestCol := Cols[I];
maxTol := GetTolerance(Cols[I], Color, RGB);
End;
If maxTol > 30 Then
Exit;
Result := bestCol;
Writeln('Max Tolerance Found = ' + IntToStr(maxTol));
Writeln('Color = ' + IntToStr(Color));
End;


{*******************************************************************************
function FindColorsHSL(Var TPA : TPointArray; Color : TColor; Tolerance, Xs, Ys, Xe, Ye : Integer; SMod, HMod : Extended): Boolean;
By: Cazax
Description: Finds all similar colors. Uses HSL.
Note:
HMod and SMod default's value is 0.2.
*******************************************************************************}
Function FindColorsHSL(Var TPA : TPointArray; Color : TColor; Tolerance, Xs, Ys, Xe, Ye : Integer; SMod, HMod : Extended): Boolean;
Var
TPA2 : TPointArray;
I, H : Integer;
Cols : TColorArray;
Begin
Result := FindColorsTolerance(TPA2, Color, Xs, Ys, Xe, Ye, Tolerance);
If Not Result Then
Exit;
SortTPAfrom(TPA2, Point((Xs + Xe) Shr 1, (Ys + Ye) Shr 1));
H := High(TPA2);
Cols := SetupColors(GetColors(TPA2));
SetColorSpeed2Modifiers(HMod, SMod);
For I := 0 To H Do
If GetTolerance(Color, Cols[I].Color, HSL) <= Tolerance Then
Begin
SetLength(TPA, Length(TPA) + 1);
TPA[High(TPA)] := TPA2[I];
End;
SetColorSpeed2Modifiers(0.2, 0.2);
Result := Length(TPA) <> 0;
End;

{*******************************************************************************
function FindColorsXYZ(Var TPA : TPointArray; Color : TColor; Tolerance, Xs, Ys, Xe, Ye : Integer; Sensitivity : Integer): Boolean;
By: Cazax
Description: Finds all similar colors. Uses XYZ.
Note:
Sensitivity default's value is 4.
*******************************************************************************}

Function FindColorsXYZ(Var TPA : TPointArray; Color : TColor; Tolerance, Xs, Ys, Xe, Ye : Integer; Sensitivity : Integer): Boolean;
Var
TPA2 : TPointArray;
I, H : Integer;
Cols : TColorArray;
Begin
Result := FindColorsTolerance(TPA2, Color, Xs, Ys, Xe, Ye, Tolerance);
If Not Result Then
Exit;
SortTPAfrom(TPA2, Point((Xs + Xe) Shr 1, (Ys + Ye) Shr 1));
H := High(TPA2);
Cols := SetupColors(GetColors(TPA2));
SetColorSpeed3Modifiers(Sensitivity);
For I := 0 To H Do
If GetTolerance(Color, Cols[I].Color, XYZ) <= Tolerance Then
Begin
SetLength(TPA, Length(TPA) + 1);
TPA[High(TPA)] := TPA2[I];
End;
SetColorSpeed3Modifiers(4);
Result := Length(TPA) <> 0;
End;

{*******************************************************************************
function SmartFindObject(Var Cols : TColorArray; Color : Integer; UpText : String; Var X, Y : Integer): Boolean;
By: Cazax
Description:
Cols: Declare a TColorArray variable. The function will use it to save values and colors
Color: To color to search with
UpText: The uptext of the object
X, Y: The coordinates where the object will be saved.
*******************************************************************************}

Function SmartFindObject(Var Cols : TColorArray; Color : Integer; UpText : String; Var X, Y : Integer): Boolean;
Var
I, C, H, J, K : Integer;
TPA, TPA2, TPA3 : TPointArray;
ATPA : T2DPointArray;
Cols2 : TColorArray;
Begin
If C = 0 Then
Begin
SetLength(Cols, 1);
Cols[0] := SetupColor(Color);
Cols[0].XYZTolerance := 8;
End;
H := High(Cols);
For I := H DownTo 0 Do
Begin
ColorToleranceSpeed(3);
FindColorsTolerance(TPA, Cols[I].Color, MSX1, MSY1, MSX2, MSY2, Cols[I].XYZTolerance);
TPA2 := CombineTPA(TPA, TPA2);
End;
ColorToleranceSpeed(1);
SortTPAFrom(TPA2, Point(MSCX, MSCY));
H := High(TPA2);
SetLength(Cols2, Length(TPA2));
For I := 0 To H Do
Begin
Cols2[I].Color := GetColor(TPA2[I].X, TPA2[I].Y);
ColorToXYZ(Cols2[I].Color, Cols2[I].X, Cols2[I].Y, Cols2[I].Z);
End;
For J := High(Cols) DownTo 0 Do
For I := 0 To H Do
If (Abs(Cols2[I].X - Cols[J].X) >= (Cols[J].X - 3)) And (Abs(Cols2[I].X - Cols[J].X) <= (Cols[J].X + 3)) Then
If (Abs(Cols2[I].Y - Cols[J].Y) >= (Cols[J].Y - 3)) And (Abs(Cols2[I].Y - Cols[J].Y) <= (Cols[J].Y + 3)) Then
If (Abs(Cols2[I].Z - Cols[J].Z) >= (Cols[J].Z - 3)) And (Abs(Cols2[I].Z - Cols[J].Z) <= (Cols[J].Z + 3)) Then
Begin
SetLength(Cols, Length(Cols) + 1);
Cols[High(Cols)] := SetupColor(Cols2[I].Color);
Cols[High(Cols)].XYZTolerance := GetTolerance(Cols[High(Cols)].Color, Cols2[I].Color, XYZ);
ColorToleranceSpeed(3);
FindColorsSpiralTolerance(MSCX, MSCY, TPA3, Cols[High(Cols)].Color, MSX1, MSY1, MSX2, MSY2, Cols[High(Cols)].XYZTolerance);
ColorToleranceSpeed(1);
If Length(TPA3) = 0 Then
Exit;
Writeln('Object Color = ' + IntToStr(Cols[High(Cols)].Color));
Writeln('XYZ Tolerance = ' + IntToStr(Cols[High(Cols)].XYZTolerance));
ATPA := TPAtoATPAEx(TPA3, 5, 5);
For K := 0 To High(ATPA) Do
Begin
MiddleTPAex(ATPA[K], X, Y);
MMouse(X, Y, 5, 5);
Wait(100 + Random(100));
If IsUpText(UpText) Then
Begin
GetMousePos(X, Y);
Result := True;
Exit;
End;
End;
End;
End;
Must use as include. This is useful for autocoloring, finding colors, anything related to colors.
These functions have their own instruction, if you have any question, just ask. If you have any function request, just tell me :)

Smarter Child

2009-01-19 12:58:10

Could this be added to SRL?

Kasi

2009-01-19 15:14:12

mistakes on withdrawsearch
says iemname then item name
and where did u get Quantity from? shouldnt that be amount?
looking for more…
Edit : found no more errors but love ur include

Cazax

2009-01-19 16:31:25

From: pur3b100d
mistakes on withdrawsearch
says iemname then item name
and where did u get Quantity from? shouldnt that be amount?
looking for more…
Edit : found no more errors but love ur include


Thanks, I forgot to change amount to Quantity, i'm glad you liked it :)

Kasi

2009-01-19 16:40:26

still forgot the item thing


Function WithdrawSearch(IemName : String; Amount : Integer): Boolean; // Says IemName
Begin
If Not LoggedIn Then
Exit;
SearchBank(ItemName); // Says ItemName
Wait(250 + Random(500));
Result := CountColor(65536, 29, 90, 146, 138) <> 0;
If Result Then
Begin
If Amount = 1 Then
MouseBox(36, 98, 70, 123, 1)
Else
Begin
MouseBox(36, 98, 70, 123, 2);
Wait(100 + Random(100));
If InIntArray([5, 10], Amount) Then
ChooseOption('Withdraw-' + IntToStr(Amount))
Else
Begin
ChooseOption('X');
Wait(250 + Random(250));
TypeSend(IntToStr(Amount));
End;
End;
Wait(500 + Random(500));
End Else
MouseBox(31, 52, 67, 80, 1);
End;
hope that helps XD

Cazax

2009-01-19 16:58:44

From: pur3b100d
still forgot the item thing


Function WithdrawSearch(IemName : String; Amount : Integer): Boolean; // Says IemName
Begin
If Not LoggedIn Then
Exit;
SearchBank(ItemName); // Says ItemName
Wait(250 + Random(500));
Result := CountColor(65536, 29, 90, 146, 138) <> 0;
If Result Then
Begin
If Amount = 1 Then
MouseBox(36, 98, 70, 123, 1)
Else
Begin
MouseBox(36, 98, 70, 123, 2);
Wait(100 + Random(100));
If InIntArray([5, 10], Amount) Then
ChooseOption('Withdraw-' + IntToStr(Amount))
Else
Begin
ChooseOption('X');
Wait(250 + Random(250));
TypeSend(IntToStr(Amount));
End;
End;
Wait(500 + Random(500));
End Else
MouseBox(31, 52, 67, 80, 1);
End;
hope that helps XD

Thanks, fixed :)