SRL Archive - SRL Archives

Gasfinding..


JuKKa

2008-05-11 16:15:34

I just noticed that the gas color has changed!

Due to this i made a function which also works pretty well!

program New;

{.Include SRL/SRL.Scar}
{.Include SRL/SRL/Skill/Mining.Scar}

function n_GasMove(Var gx, gy: Integer): Boolean;
var
clientcanvas, gascanvas1, gascanvas2: TCanvas;
X1, Y1, X2, Y2, xG, yG, count: Integer;
pic1, pic2: Integer;
begin
X1 := gX - 30;
Y1 := gY - 50;
X2 := gX + 30;
Y2 := gY + 50;

pic1 := BitmapFromString(60, 100, '');
pic2 := BitmapFromString(60, 100, '');

gascanvas1 := GetBitmapCanvas(pic1);
gascanvas2 := GetBitmapCanvas(pic2);

clientcanvas := getclientcanvas;

CopyCanvas(clientcanvas, gascanvas1, X1, Y1, X2, Y2, 0, 0, 40, 40);
Wait(100);
CopyCanvas(clientcanvas, gascanvas2, X1, Y1, X2, Y2, 0, 0, 40, 40);

count := 0;

for yG := 1 to 100 do
for xG := 1 to 60 do
if ((gascanvas1.pixels[xG, yG]) <> (gascanvas2.pixels[xG, yG])) then
Inc(Count);

if ( (Count/6000)*100 > 40) then
begin
writeln('gas change ' + IntTostr(Round((Count/6000)*100))+'%');
Result := True;
end;

FreeBitmap(pic1);
FreeBitmap(pic2);
end;

Function n_FindGas(Var gX, gY: Integer; Avoid: Boolean): Boolean;
Var
I, X1, Y1, X2, Y2, CTS: Integer;
aTPA: Array [0..6] Of TPointArray;
TIntArr, TIntArr2: TIntegerArray;
TPA: TPointArray;
Begin
If(gX - 30 < 0)Or(gY - 50 < 0)Or(gX + 30 > MSX2)Or(gY + 50 > MSY2)Then
Exit;

X1 := gX - 30;
Y1 := gY - 50;
X2 := gX + 30;
Y2 := gY + 50;

CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);

FindColorsTolerance(aTPA[0], 10397609, X1, Y1, X2, Y2, 20);
FindColorsTolerance(aTPA[1], 9740966, X1, Y1, X2, Y2, 20);
FindColorsTolerance(aTPA[2], 11055025, X1, Y1, X2, Y2, 20);
FindColorsTolerance(aTPA[3], 10464173, X1, Y1, X2, Y2, 20);
FindColorsTolerance(aTPA[4], 10792881, X1, Y1, X2, Y2, 20);
FindColorsTolerance(aTPA[5], 9214622, X1, Y1, X2, Y2, 20);
FindColorsTolerance(aTPA[6], 10924724, X1, Y1, X2, Y2, 20);

For I:= 0 To 6 Do
Begin
TIntArr2 := GetColors(aTPA[I]);
TIntArr := CombineIntArray(TIntArr2, TIntArr);
TPA := CombineTPA(aTPA[I], TPA);
End;

ClearSameIntegersAndTPA(TIntArr, TPA);

MiddleTPAEx(TPA, gX, gY);
Status(IntToStr(High(TPA)));
If(High(TIntArr) > 100)And(High(TPA) > 100)Then
Result := n_GasMove(gX, gY);

If(Result)And(Avoid)Then
Begin
Mouse(MMCx - 10, MMCY - 10, 10, 10, True);
Flag;
End;

ColorToleranceSpeed(CTS);
End;

Var
X, Y: Integer;

Begin
SetupSRL;

Repeat
GetMousePos(X, Y);
If(n_FindGas(X, Y, True))Then
Writeln('Found Gas!');
Wait(100);
Until False
End.

Forgot to save the new gas color pictures =(

but i picked quite a few. Here if someone wants to check them out or whatever..

    New Gas Colors =
10397609
9740966
11055025
10464173
10792881
9214622
10924724
Old Gas Colors =
8296866
5795704
5270391
5599613
5136998
6321275
6123901

Gu3st...

2008-05-11 17:16:08

ooh this is nice, i just got a gas and tested it out.

'Found Gas!' ;)

Harry

2008-05-11 21:32:49

Nice, I hope this doesn't find clothes like the Chicken costumes and Lederhosen :eek:

JuKKa

2008-05-12 00:23:09

From: Hy71194
Nice, I hope this doesn't find clothes like the Chicken costumes and Lederhosen :eek:


I tested it didnt find lederhosen ;)

n3ss3s

2008-05-12 06:58:48

Looks nice :)

Using Hue and Saturation modifiers might decrease the amount of FindColorsTolerances there though, I checked the first two and if I remember right Hue diff was 2 and Saturation 3, and SimilarColors using HSL uses the Hue and Sat as Tolerance * Hue / Tolerance * Sat, so SetColorSpeed2Modifers(0.3, 0.3) would decrease the amount there and also you could have only 10 tolerance :)

JuKKa

2008-05-12 07:07:50

From: n3ss3s
Looks nice :)

Using Hue and Saturation modifiers might decrease the amount of FindColorsTolerances there though, I checked the first two and if I remember right Hue diff was 2 and Saturation 3, and SimilarColors using HSL uses the Hue and Sat as Tolerance * Hue / Tolerance * Sat, so SetColorSpeed2Modifers(0.3, 0.3) would decrease the amount there and also you could have only 10 tolerance :)

Well, i let the devs do the final edit if this gets added to srl.

n3ss3s

2008-05-12 09:05:03

Added the modfs thing anyway -


Function n_FindGas(Var gX, gY: Integer; Avoid: Boolean): Boolean;
Var
I, X1, Y1, X2, Y2, CTS: Integer;
TIntArr: TIntegerArray;
TPA: TPointArray;
Begin
If(gX - 30 < 0)Or(gY - 50 < 0)Or(gX + 30 > MSX2)Or(gY + 50 > MSY2)Then
Exit;

X1 := gX - 30;
Y1 := gY - 50;
X2 := gX + 30;
Y2 := gY + 50;

CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.3, 0.3);
FindColorsTolerance(TPA, 10397609, X1, Y1, X2, Y2, 20);
SetColorSpeed2Modifiers(0.2, 0.2);
TIntArr := GetColors(TPA);
ClearSameIntegersAndTPA(TIntArr, TPA);
MiddleTPAEx(TPA, gX, gY);
Status(IntToStr(High(TPA)));
If(High(TIntArr) > 100)And(High(TPA) > 100)Then
Result := n_GasMove(gX, gY);

If(Result)And(Avoid)Then
Begin
Mouse(MMCx - 10, MMCY - 10, 10, 10, True);
Flag;
End;

ColorToleranceSpeed(CTS);
End;

JuKKa

2008-05-12 09:10:12

From: n3ss3s
Added the modfs thing anyway -


Function n_FindGas(Var gX, gY: Integer; Avoid: Boolean): Boolean;
Var
I, X1, Y1, X2, Y2, CTS: Integer;
TIntArr: TIntegerArray;
TPA: TPointArray;
Begin
If(gX - 30 < 0)Or(gY - 50 < 0)Or(gX + 30 > MSX2)Or(gY + 50 > MSY2)Then
Exit;

X1 := gX - 30;
Y1 := gY - 50;
X2 := gX + 30;
Y2 := gY + 50;

CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.3, 0.3);
FindColorsTolerance(TPA, 10397609, X1, Y1, X2, Y2, 20);
SetColorSpeed2Modifiers(0.2, 0.2);
TIntArr := GetColors(TPA);
ClearSameIntegersAndTPA(TIntArr, TPA);
MiddleTPAEx(TPA, gX, gY);
Status(IntToStr(High(TPA)));
If(High(TIntArr) > 100)And(High(TPA) > 100)Then
Result := n_GasMove(gX, gY);

If(Result)And(Avoid)Then
Begin
Mouse(MMCx - 10, MMCY - 10, 10, 10, True);
Flag;
End;

ColorToleranceSpeed(CTS);
End;


I noticed that TintArr and TPA always equals the same value xP so u could just remove one of them..

n3ss3s

2008-05-12 09:20:35

How can a TPointArray and a TIntegerArray be equal?

JuKKa

2008-05-12 09:24:40

From: n3ss3s
How can a TPointArray and a TIntegerArray be equal?

High()