SRL Archive - SRL Archives

Santy Functions!


Santa_Clause

2008-01-28 06:36:30

function FindMouse : Boolean;
var
MousePoints : TPointArrayArray;
MousePointArray : TPointArray;
CheckPoint : TPoint;
MouseColoursArray : TIntegerArray;
MouseColour, StartTime, MouseTime, X, Y, I : Integer;
CTS : Integer;
begin
CTS := GetColorToleranceSpeed;
MarkTime(StartTime);
ColorToleranceSpeed(2);
FindColorsSpiralTolerance(MSCX, MSCY, MousePointArray, 16645629, MSX1, MSY1, MSX2, MSY2, 7);
MousePoints := SplitTPA(MousePointArray, 5);
for I := 0 to High(MousePoints) do
begin
CheckPoint := MiddleTPA(MousePoints[I]);
MouseColour := GetColor(CheckPoint.X, CheckPoint.Y);
MarkTime(MouseTime);
Mouse(CheckPoint.X, CheckPoint.Y, 2, 2, False);
Wait(50 + Random(50));
if ClickOption('ouse', 1) then
begin
GetMousePos(X, Y);
Mouse(X, Y, 0, 0, True);
if not(InIntArray(MouseColoursArray, MouseColour)) then
begin
SetArrayLength(MouseColoursArray, Length(MouseColoursArray) + 1);
MouseColoursArray[High(MouseColoursArray)] := MouseColour;
WriteLn(IntToStr(MouseColour) + ' Added To MouseColour Array');
end;
Result := True;
WriteLn(IntToStr(TimeFromMark(StartTime) - TimeFromMark(MouseTime)));
ColorToleranceSpeed(CTS);
Exit;
end;
end;
end;

function FindTree : Boolean;
var
TreePointArray : TPointArrayArray;
TreePoints : TPointArray;
Centre : TPoint;
TreeBox : TBox;
X, Y, I, K, U : Integer;
CTS : Integer;
begin
CTS := GetColorToleranceSpeed;
MarkTime(U);
ColorToleranceSpeed(2);
Centre := IntToPoint(MSCX, MSCY);
FindColorsTolerance(TreePoints, 2910042, MSX1, MSY1, MSX2, MSY2, 10);
TreePointArray := SplitTPA(TreePoints, 20);
SortATPAFrom(TreePointArray, Centre);
K := TimeFromMark(U);
for I := 0 to High(TreePointArray) do
begin
TreeBox := GetTPABounds(TreePointArray[I]);
MMouse((TreeBox.X1 + TreeBox.X2)/2, (TreeBox.Y1 + TreeBox.Y2)/2, 3, 3);
Wait(50 + Random(50));
if IsUpText('hop') then
begin
GetMousePos(X, Y);
Mouse(X, Y, 0, 0, True);
Result := True;
WriteLn(IntToStr(K));
ColorToleranceSpeed(CTS);
Exit;
end;
end;
end;

function FindMeanColour(NumberArray : TIntegerArray) : TIntegerArray;
var
I : Integer;
H, S, L : Extended;
R, G, B : Integer;
X, Y, Z : Extended;

HTotal, STotal, LTotal : Extended;
HMean, SMean, LMean : Extended;

RTotal, GTotal, BTotal : Integer;
RMean, GMean, BMean : Integer;

XTotal, YTotal, ZTotal : Extended;
XMean, YMean, ZMean : Extended;
begin
SetArrayLength(Result, 3);

for I := 0 to High(NumberArray) do
begin
ColorToHSL(NumberArray[I], H, S, L);
ColorToRGB(NumberArray[I], R, G, B);
ColorToXYZ(NumberArray[I], X, Y, Z);

HTotal := HTotal + H;
STotal := STotal + S;
LTotal := LTotal + L;

RTotal := RTotal + R;
GTotal := GTotal + G;
BTotal := BTotal + B;

XTotal := XTotal + X;
YTotal := YTotal + Y;
ZTotal := ZTotal + Z;
end;

HMean := HTotal/Length(NumberArray);
SMean := STotal/Length(NumberArray);
LMean := LTotal/Length(NumberArray);

RMean := RTotal/Length(NumberArray);
GMean := GTotal/Length(NumberArray);
BMean := BTotal/Length(NumberArray);

XMean := XTotal/Length(NumberArray);
YMean := YTotal/Length(NumberArray);
ZMean := ZTotal/Length(NumberArray);

Result[0] := HSLToColor(HMean, SMean, LMean);
Result[1] := RGBToColor(RMean, GMean, BMean);
Result[2] := XYZToColor(XMean, YMean, ZMean);
end;

function FindGlobalTolerance(NumberArray : TIntegerArray) : Integer;
var
I : Integer;
begin
for I := 1 to High(NumberArray) do
while not(SimilarColors(NumberArray[I], NumberArray[I - 1], Result)) do
Inc(Result);
end;

procedure FindHSLInfo(NumberArray : TIntegerArray);
var
I : Integer;

H, S, L : TExtendedArray;
R, G, B : TIntegerArray;
X, Y, Z : TExtendedArray;

HSArray, HLArray, SLArray : TExtendedArray;
RBArray, RGArray, GBArray : TIntegerArray;
XYArray, XZArray, YZArray : TExtendedArray;

GenericColourArray : TIntegerArray;
begin
SetArrayLength(H, Length(NumberArray));
SetArrayLength(S, Length(NumberArray));
SetArrayLength(L, Length(NumberArray));

SetArrayLength(R, Length(NumberArray));
SetArrayLength(G, Length(NumberArray));
SetArrayLength(B, Length(NumberArray));

SetArrayLength(X, Length(NumberArray));
SetArrayLength(Y, Length(NumberArray));
SetArrayLength(Z, Length(NumberArray));

SetArrayLength(HSArray, Length(NumberArray));
SetArrayLength(HLArray, Length(NumberArray));
SetArrayLength(SLArray, Length(NumberArray));

SetArrayLength(RGArray, Length(NumberArray));
SetArrayLength(RBArray, Length(NumberArray));
SetArrayLength(GBArray, Length(NumberArray));

SetArrayLength(XYArray, Length(NumberArray));
SetArrayLength(XZArray, Length(NumberArray));
SetArrayLength(YZArray, Length(NumberArray));

for I := 0 to High(NumberArray) do
begin
ColorToHSL(NumberArray[I], H[I], S[I], L[I]);
ColorToRGB(NumberArray[I], R[I], G[I], B[I]);
ColorToXYZ(NumberArray[I], X[I], Y[I], Z[I]);
end;

for I := 0 to High(NumberArray) do
begin
HSArray[I] := H[I] - S[I];
HLArray[I] := H[I] - L[I];
SLArray[I] := S[I] - L[I];

RGArray[I] := R[I] - G[I];
RBArray[I] := R[I] - B[I];
GBArray[I] := G[I] - B[I];

XYArray[I] := X[I] - Y[I];
XZArray[I] := X[I] - Z[I];
YZArray[I] := Y[I] - Z[I];
end;

GenericColourArray := FindMeanColour(NumberArray);

WriteLn('Santy''s HSL Characteristic Finder!');
WriteLn(' ');
WriteLn('Generic HSL Colour : ' + IntToStr(GenericColourArray[0]));
WriteLn('Generic RGB Colour : ' + IntToStr(GenericColourArray[1]));
WriteLn('Generic XYZ Colour : ' + IntToStr(GenericColourArray[2]));

WriteLn('Max Tolerance : ' + IntToStr(FindGlobalTolerance(NumberArray)));
WriteLn(' ');
WriteLn('Min H : ' + FloatToStr(AMinE(H)) + ', Max H : ' + FloatToStr(AMaxE(H)));
WriteLn('Min S : ' + FloatToStr(AMinE(S)) + ', Max S : ' + FloatToStr(AMaxE(S)));
WriteLn('Min L : ' + FloatToStr(AMinE(L)) + ', Max L : ' + FloatToStr(AMaxE(L)));
WriteLn(' ');
WriteLn('Min H - S : ' + FloatToStr(AMinE(HSArray)) + ', Max H - S : ' + FloatToStr(AMaxE(HSArray)));
WriteLn('Min H - L : ' + FloatToStr(AMinE(HLArray)) + ', Max H - L : ' + FloatToStr(AMaxE(HLArray)));
WriteLn('Min S - L : ' + FloatToStr(AMinE(SLArray)) + ', Max S - L : ' + FloatToStr(AMaxE(SLArray)));
WriteLn(' ');
WriteLn('Min R : ' + IntToStr(AMin(R)) + ', Max R : ' + IntToStr(AMax(R)));
WriteLn('Min G : ' + IntToStr(AMin(G)) + ', Max G : ' + IntToStr(AMax(G)));
WriteLn('Min B : ' + IntToStr(AMin(B)) + ', Max B : ' + IntToStr(AMax(B)));
WriteLn(' ');
WriteLn('Min R - G : ' + IntToStr(AMin(RGArray)) + ', Max R - G : ' + IntToStr(AMax(RGArray)));
WriteLn('Min R - B : ' + IntToStr(AMin(RBArray)) + ', Max R - B : ' + IntToStr(AMax(RBArray)));
WriteLn('Min G - B : ' + IntToStr(AMin(GBArray)) + ', Max G - B : ' + IntToStr(AMax(GBArray)));
WriteLn(' ');
WriteLn('Min X : ' + FloatToStr(AMinE(X)) + ', Max X : ' + FloatToStr(AMaxE(X)));
WriteLn('Min Y : ' + FloatToStr(AMinE(Y)) + ', Max Y : ' + FloatToStr(AMaxE(Y)));
WriteLn('Min Z : ' + FloatToStr(AMinE(Z)) + ', Max Z : ' + FloatToStr(AMaxE(Z)));
WriteLn(' ');
WriteLn('Min X - Y : ' + FloatToStr(AMinE(XYArray)) + ', Max X - Y : ' + FloatToStr(AMaxE(XYArray)));
WriteLn('Min X - Z : ' + FloatToStr(AMinE(XZArray)) + ', Max X - Z : ' + FloatToStr(AMaxE(XZArray)));
WriteLn('Min Y - Z : ' + FloatToStr(AMinE(YZArray)) + ', Max Y - Z : ' + FloatToStr(AMaxE(YZArray)));
end;

function MakeDDTM(InventorySpot : Integer; ItemName : string) : Boolean;
var
I : Integer;
DDTMBox : TBox;
DDTMMainPoint : TPoint;
DDTMPoints : TPointArray;
DDTMSubPoints : TPointArrayArray;
begin
if not(InRange(InventorySpot, 1, 28)) then
begin
WriteLn('Inventory Spot Must Be Between 1 And 28, Inclusive');
WriteLn('Exiting');
Exit;
end;

DDTMBox := InvBox(InventorySpot);
DDTMMainPoint := ItemCoords(InventorySpot);
FindColorsTolerance(DDTMPoints, 65536, DDTMBox.X1, DDTMBox.Y1, DDTMBox.X2, DDTMBox.Y2, 0);

DDTMSubPoints := TPAToATPA(DDTMPoints, 10);

WriteLn(ItemName + 'Main.X := ' + IntToStr(DDTMMainPoint.X));
WriteLn(ItemName + 'Main.Y := ' + IntToStr(DDTMMainPoint.Y));
WriteLn(ItemName + 'Main.AreaSize := 0');
WriteLn(ItemName + 'Main.AreaShape := 0');
WriteLn(ItemName + 'Main.Color := ' + IntToStr(GetColor(DDTMMainPoint.X, DDTMMainPoint.Y)));
WriteLn(ItemName + 'Main.Tolerance := 255');

for I := 0 to High(DDTMSubPoints) do
begin
WriteLn(' ');
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].X := ' + IntToStr(DDTMSubPoints[I][0].X));
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].Y := ' + IntToStr(DDTMSubPoints[I][0].Y));
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].AreaSize := 0');
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].AreaShape := 0');
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].Color := 65536');
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].Tolerance := 0');
end;

Result := True;
end;

Descriptions :
  • FindMouse : Find a toy mouse on the ground. Results true if clicked. Adds mouse colour into TIntegerArray.
  • FindTree : Finds any tree on mainscreen…maybe except willows. Results true if clicked.
  • HSL Tool : Finds characteristics of a TIntegerArray. Lowest and highest H, S, L, R, G, B, X, Y, Z, while also finding the lowest and highest differences.
  • MakeDDTM : Makes a DDTM of an item in the inventory. You can choose the name and inventory spot by filling in the parameters.

This is my first function thread, rate it or hate :p Constructive criticism is appreciated…and so is flaming, gives me a chance to take out all my anger on someone. Bye now :f:

t3hl33tn00b

2008-01-28 07:11:10

the first one is brilliant :D thanks and good job

Johura

2008-01-28 07:12:07


Lol.

I dont get FindMouse. Does it look for the position of the mouse on the screen? :confused: But then you mention finding it on the ground. Is there a toy mouse object? Im confused lol.

Edit: Dam you t3hl33tn00b :P. Go and ruin my picture why dnt you.

ZephyrsFury

2008-01-28 07:12:20

Hehe, your HSL, RGB, XYZ thing is pretty much the same as mine now. :p. Good job.

EDIT:
From: Jahuro

I dont get FindMouse. Does it look for the position of the mouse on the screen? But then you mention finding it on the ground. Is there a toy mouse object? Im confused lol.


It looks for a mouse like the ones in the witches potion quest I think. (Am I right?)

Santa_Clause

2008-01-28 10:25:38

From: ZephyrsFury
Hehe, your HSL, RGB, XYZ thing is pretty much the same as mine now. :p. Good job.

EDIT:


It looks for a mouse like the ones in the witches potion quest I think. (Am I right?)


I didn't make mine while looking at yours…and our tolerance finders are a bit different :p It looks for the agility mice…the ones that you wind, release and pick up.

EvilChicken!

2008-01-28 11:05:06

The function you made for me. J00 P00N!

Aww, this was spam. Well, your functions were really good. I'll add the mousecolorarray back in when I get my head out of my ass and start thinking like a normal person. Good functions, still.

Negaal

2008-01-28 16:45:55

Hehe, good job though, if you could make me willowfinder, what does not find any ground, and finds up 150 points, then you would be my best friend:p

Edit: Hah, I'v tryed almost everything, filtering with HSL/XYZ, Finding only dark and very light colors, and combine them, finding few unique colors and make box around them and trying to use best color in that, tryed lots, lots of colours, lots of…5 days on one function for nothing ^^ beat that

1 thing Markus reminded me today, how to speed up function a bit. Instead of for i := 0 to High(x) / GetArraylength(x) - 1 do

High := High(x)
For i := 0 to High do…

So you dont have to get arrays length everytime:)

R0b0t1

2008-01-28 18:41:13

Lmao, was about to say, the computer mouse cursor won't show up on a FindColor search :p.

Santa_Clause

2008-01-28 18:44:33

I don't understand what you said R0bot…

And Negaal, High(Array) looks better and doesn't really take too much time…so I'll stick with it.

Harry

2008-01-28 18:45:51

Wow, those are the worst procedures ever. How can you stand to live being such a bad scripter like that?
Just kidding <3, VERY GOOD JOB : )

Santa_Clause

2008-01-28 18:49:19

From: Hy71194
Wow, those are the worst procedures ever.
Jk, VERY GOOD JOB : )


You're a noob.
Just kidding, thanks.

Negaal:

function FindWillow : Boolean;
var
TreePoints : TPointArray;
TreePointArray : TPointArrayArray;
X, Y : Integer;
I : Integer;
K, U : Integer;
TreeBox : TBox;
Centre : TPoint;
begin
MarkTime(U);
ColorToleranceSpeed(2);
Centre.X := MSCX;
Centre.Y := MSCY;
FindColorsTolerance(TreePoints, 4754817, MSX1, MSY1, MSX2, MSY2, 10);
TreePointArray := SplitTPA(TreePoints, 20);
SortATPAFrom(TreePointArray, Centre);
K := TimeFromMark(U);
DebugATPA(TreePointArray, '');
for I := 0 to High(TreePointArray) do
begin
TreeBox := GetTPABounds(TreePointArray[I]);
MMouse((TreeBox.X1 + TreeBox.X2)/2, (TreeBox.Y1 + TreeBox.Y2)/2, 3, 3);
Wait(50 + Random(50));
if IsUpText('illow') then
begin
GetMousePos(X, Y);
Mouse(X, Y, 0, 0, True);
Result := True;
WriteLn(IntToStr(K));
Exit;
end;
end;
end;

47 Ms…3 trees…all the points were on the trees and not the ground.

Negaal

2008-01-29 00:40:04

I lied about best friend thingy:p
But I still try it today…not sure it's going to work good…

Thank you.

ZephyrsFury

2008-01-29 03:29:20

From: R0b0t1
Lmao, was about to say, the computer mouse cursor won't show up on a FindColor search :p.


It doesn't find the mouse cursor thing. It finds the agility mice in RS. :p

Santa_Clause

2008-01-29 07:23:11

New function, MakeDDTM added.

BobboHobbo

2008-01-29 08:42:16

Nice functions/procedures. Make a santa clause photo generator in scar? like it makes a santa from stars like:

[PHP] ()
***
****
( -.- )
*******
*******
*******
** 00**
** | **
** **[/PHP]


Fingers slipped :l

Negaal

2008-01-29 09:51:38

This isn't what I was looking for =/


156
203
171
156

Mostly 140 -225 points…


Well, if I'm lucky with colors I usually do find at least 500, problem is always I get tiny piece of grass with it:S
I'v also found 2000 pts on one tree, but again litle piece of lag and grass are included =/

Santa_Clause

2008-01-29 10:05:50

There aren't any points on the ground…get on MSN and we'll discuss more.

n3ss3s

2008-01-30 05:38:33

Well, a suggestion for the tree finding to avoid finding the grass, take the color picker and look atthe willow, it isn't fully green is it? It has got green, gray and light brown.

The outer part of the willow, like if it was a circle, the arc, mainly consists of green, so, what if you would first do a FindColors for the green, and then, make a function that sweeps the whole green area empty from the TPA with a user set or automated radius, from the midpoint of the TPA you got with MiddleTPA before sweepin it empty, and then, to get how many pixel area of the circle you deleted was, use A = pi * r^2, and then, do FindColorsPie for the brown and gray colors from the midpoint with the same radius you wiped out the green ones, and then use something like


Function GrabTPA(TPA: TPointArray; x1, y1, x2, y2: Integer): TPointArray;
Var
I, Z, L: Integer;
B: TBox;
Begin
L := High(TPA);
B := IntToBox(x1, y1, x2, y2);
SetArrayLength(Result, GetArrayLength(TPA));
For I := 0 To L Do
If PointInBox(TPA[i], B) Then
Begin
Result[i] := TPA[i];
Z := Z + 1;
End;
SetArrayLength(Result, Z);
End;

for the green area, yes, it is possible, because you have a backup TPA of it, so, with the function above you will get the points of the green tpa in the circle, and then compare the amounts of gray and brown to the green, because it is mainy green, then brown and then gray.



Something like that, use your imagination.

R0b0t1

2008-01-30 21:38:52

Nice Idea.


I try to think… More simply, however.

footballjds

2008-01-31 10:15:27

From: R0b0t1
Nice Idea.


I try to think… More simply, however.


i agree, n3ss3s you confuzerate me :(

Negaal

2008-01-31 13:02:13

From: footballjds
i agree, n3ss3s you confuzerate me :(

I agree with Football, I wouldn't understand it even if you will draw me a picture.

Anyways I understood that I have to do FindColorsTolerance more than 3 times, thing is that even 2 FindColorTolerance at same time makes me 0.1 sec lagg, yesh, my PC sucks…Still it needs to be non - laggy for me, i'm not going to try it, i'm going to get confused…:duh:


A = pi * r^2

*Thats the things because why I say*

Wdf?

3,14 * Radius^2

What I get from this?
Dude you're 12
*I'm embarrising*

n3ss3s

2008-01-31 13:06:49

13 x)

Pi * Radius^2 is the area of a circle :)