SRL Archive - SRL Archives

More functions and procedures for SRL


Cazax

2009-04-18 05:22:12

Since I like helping SRL and I'm lazy to finish my scripts, I have made some functions/procedures for SRL…

Core/Symbols:
FindSymbols firstly finds a symbol, the gets its color and search for more symbols accordingly to the got color. That makes it fast but not always accurate. For example, the castle varrock(behind) has tree symbols and a quest symbol(greenish). Since it finds the symbol using a color and not the symbols, the quest symbols is included in the result! Don't worry, I've made a solution:
Function FindSymbolsAccurate(Var TPA : TPointArray; SymbolName : String): Boolean;
Var
tTPA : TPointArray;
tATPA : T2DPointArray;
H, I, tx, ty, tmpx, tmpy : Integer;
Begin
FindSymbols(tTPA, SymbolName);
If Length(tTPA) = 0 Then
Exit;
tATPA := TPAtoATPA(tTPA, 12);
H := High(tATPA);
For I := 0 To H Do
If MiddleTPAex(tATPA[I], tmpx, tmpy) Then
If FindSymbolIn(tx, ty, SymbolName, tmpx - 15, tmpy - 15, tmpx + 15, tmpy + 15) Then
Begin
SetLength(TPA, Length(TPA) + 1);
TPA[High(TPA)] := Point(tx, ty);
End;
Result := True;
End;

Core/MapWalk:
Mostly like an addition, I created this:
Function GetWhiteAreas: T2DPointArray;
Var
WallColor, maxL, H, I, Ca : Integer;
TPA : TPointArray;
WArr : TIntegerArray;
Begin
If Not FindColorsTolerance(TPA, 15593448, MMX1, MMY1, MMX2, MMY2, 50) Then
Exit;
WArr := GetColors(TPA);
ClearSameIntegers(WArr);
If Length(WArr) = 1 Then
WallColor := WArr[0]
Else
Begin
H := High(WArr);
For I := 0 To H Do
Begin
FindColorsTolerance(TPA, WArr[I], MMX1, MMY1, MMX2, MMY2, 0);
If Length(TPA) > maxL Then
Begin
Ca := I;
maxL := Max(Length(TPA), maxL);
End;
End;
WallColor := WArr[Ca];
End;
FindColorsSpiralTolerance(MMCX, MMCY, TPA, WallColor, MMX1, MMY1, MMX2, MMY2, 0);
Result := SplitTPAEx(TPA, 1, 1);
End;
Finds all the walls in the minimap and groups them in a 2 dimensional array(T2DPointArray). For example there are 2 houses in the minimap, the length of the result will be 2, and in each one there will be the points of the house. You could use MiddleTPA in the Result[0] to get the middle of the first house without using any DDTM :)

Core/Text:
IsOption:

Function IsOption(Text : String): Boolean;
Var
TPA : TPointArray;
Box : TBox;
X, Y : Integer;
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;
If the choose option menu is visible, it will find if text is on it. See Richard's thread for an example…http://www.villavu.com/forum/showthread.php?t=44300

TextBox:
Function TextBox(TextN : Integer): TBox;
Var
TP : TPoint;
Begin
TP := TextCoords(TextN);
Result.X1 := TP.X;
Result.Y1 := TP.Y;
Result.X2 := TP.X + 483;
Result.Y2 := TP.Y + 13;
End;
Creates a box surrounding any text on the chat screen.

GetQuickChatLines:
Function GetQuickChatLines: TIntegerArray;
Var
I : Integer;
tempBox : TBox;
tempTPA : TPointArray;
Begin
For I := 1 To 8 Do
Begin
tempBox := TextBox(I);
If FindColorsTolerance(tempTPA, 14474460, TempBox.X1, tempBox.Y1, tempBox.X2, tempBOx.Y2, 10) And (Length(tempTPA) > 15) Then
Begin
SetLength(Result, Length(Result) + 1);
Result[High(Result)] := I;
End;
End;
End;
Returns the lines with quick chat globes(when you talk).

QuickChatAt:
Function QuickChatAt(TextN : Integer): Boolean;
Var
tempT : TIntegerArray;
Begin
tempT := GetQuickChatLines;
Result := InIntArray(tempT, TextN);
End;
Returns true if quick chat blobe was found at an specific text.

FastMSFindText:
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;
Returns true if text was found on the main screen(using the yellow words). I use it in my autoresponders for example.

IsUpTextColor:
Function IsUpTextColor(Txt : String; Color, Tol : Integer): Boolean;
Var
X, Y : Integer;
Begin
Result := IsTextInAreaEx(MSX1, MSY1, 120, 25, X, Y, Txt, Tol, UpChars, False, False, 0, 2, Color);
End;
Returns true if the uptext matched with the color and tolerance. I used it for ent finding, they no longer exists.


GetChatSetting:

Function GetChatSetting(ChatN : Integer): String;
Var
TP : TPoint;
Begin
TP.X := 129 + (57 * (ChatN - 1));
TP.Y := 493;
Result := Trim(GetTextAtEx(TP.X, TP.Y, 1, SmallChars, True, False, 0, 1, 65535, 7, False, tr_NormalChars));
End;
Returns the text at the specified chat box. e.g. GetChatSettings(1) would get the text at the 'Public' box (On, Off, friends, etc). To make it work you need a special chars that friends.scar needs too. (Jagex' update…)

(mostly like for antiban.scar)
MessWithChats:
Procedure MessWithChats;
Var
S : String;
R : Integer;
Begin
R :=Random(5) + 1;
S := GetChatSetting(R);
Case Random(4) Of
0: SetChat('Hide', R);
1: SetChat('Off', R);
2: SetChat('Friends', R);
3: SetChat('On', R);
End;
Wait(1000 + Random(1000));
SetChat(S, R);
End;
This work like an antiban changing the chat preferences and setting them back(doesn't work, read above).


That's all, I'll try to make more if I get ideas

TRiLeZ

2009-04-18 10:51:36

Very good work!
You should try making a function like FindColorArray which would find try finding an array of colors.
It would be helpful for people like me making a fighting script that would find if the npc was already in a fight by searching for the colors specified.
Instead I have to do

if FindColorSpiralTolerance(cx,cy,255,X1,Y1,X2,Y2,10)
or FindColorSpiralTolerance(cx,cy,65280,X1,Y1,X2,Y2,10)
or FindColorSpiralTolerance(cx,cy,192,X1,Y1,X2,Y2,10)
or FindColorSpiralTolerance(cx,cy,16728128,X1,Y1,X2,Y2,10) then
Result:= True
Where the script finds if a npc is in a fight.
I would do it by myself but i cant find the color finding function.

WT-Fakawi

2009-04-18 12:23:35

haha MessWithChats. Nice one.

Cazax

2009-04-18 23:56:54

From: TRiLeZ
Very good work!
You should try making a function like FindColorArray which would find try finding an array of colors.
It would be helpful for people like me making a fighting script that would find if the npc was already in a fight by searching for the colors specified.
Instead I have to do

if FindColorSpiralTolerance(cx,cy,255,X1,Y1,X2,Y2,10)
or FindColorSpiralTolerance(cx,cy,65280,X1,Y1,X2,Y2,10)
or FindColorSpiralTolerance(cx,cy,192,X1,Y1,X2,Y2,10)
or FindColorSpiralTolerance(cx,cy,16728128,X1,Y1,X2,Y2,10) then
Result:= True
Where the script finds if a npc is in a fight.
I would do it by myself but i cant find the color finding function.

FindColorsTolerance saves all the points found in an array of TPoint (TPA's). They do what you want.
From: WT-Fakawi
haha MessWithChats. Nice one.

Thanks :p