Wizzup?
2007-10-20 09:56:03
You might say, oh no, another gas finder!
Today I got really mad because I not manage to 100% follow the rock, I call a GasCheck, and both SKy's and piv's didn't find it, and it keeps finding false gasses too. In my 'madness' I wrote my own gas finder.
-This one differs from all the other ones though.
-It's fast, 0-16ms for a box of 70 x 70. 110ms for the entire MS.
-It gives afaik no false positives.
-It doesn't need to wait to check for changes in pixels, it is purely based on colors.
There are 2 functions. w_GasCheck is for new rocks, w2_GasCheck for old rocks. :)
The code I post here is meant for testing on pictures, or rs if you like.
Please TEST!
It searches for gas around your mouse, don't forget to drag the cross hair.
A note: This one is for New Rocks only.
I guess when you just use colors you will have two different ones, one for new rock and one for old ones. The Old Rock gas is alot darker.
There.
Note and thanks to The Claw: His pictures, I commented names out, hope thats alright. :)



Feedback, please.
You could run it on the pictures above, or on your own? :)
EDIT: You might still want to do w_GasCheck(x, y-20) in your script, since gas is always a bit above your rock. :)
Today I got really mad because I not manage to 100% follow the rock, I call a GasCheck, and both SKy's and piv's didn't find it, and it keeps finding false gasses too. In my 'madness' I wrote my own gas finder.
-This one differs from all the other ones though.
-It's fast, 0-16ms for a box of 70 x 70. 110ms for the entire MS.
-It gives afaik no false positives.
-It doesn't need to wait to check for changes in pixels, it is purely based on colors.
There are 2 functions. w_GasCheck is for new rocks, w2_GasCheck for old rocks. :)
The code I post here is meant for testing on pictures, or rs if you like.
Please TEST!
It searches for gas around your mouse, don't forget to drag the cross hair.
A note: This one is for New Rocks only.
I guess when you just use colors you will have two different ones, one for new rock and one for old ones. The Old Rock gas is alot darker.
program New;
Function DebugTPA(Points: TPointArray; BmpName: String): Boolean;
Var
Width, Height, ClientBMP, I: Integer;
xs, ys, xe, ye: Integer;
Begin
Try
Begin
xe := xs xor xs;
ye := ys xor ys;
xs := 1 shl 20;
ys := 1 shl 20;
For I := 0 To High(Points) Do
Begin
xs := Min(xs, Points[I].X);
ys := Min(ys, Points[I].Y);
xe := Max(xe, Points[I].X);
ye := Max(ye, Points[I].Y);
End;
Width := xe - xs;
Height := ye - ys;
DisplayDebugImgWindow(0, 0);
DisplayDebugImgWindow(Width, Height);
ClientBMP := BitmapFromString(Width, Height, '');
CopyClientToBitmap(ClientBMP, xs, ys, xe, ye);
For I := 0 To High(Points) Do
FastSetPixel(ClientBMP, Points[I].X - xs, Points[I].Y - ys, 255);
If BmpName <> '' Then
SaveBitmap(ClientBMP, ScriptPath + BmpName + '.bmp');
SafeDrawBitmap(ClientBMP, GetDebugCanvas, 0, 0);
DisplayDebugImgWindow(Width, Height);
FreeBitmap(ClientBMP);
End
Except
FreeBitmap(ClientBMP);
End;
Result := True;
End;
function w_GasCheck(gx, gy: integer): boolean;
Var
x1, y1, x2, y2, I, time, c: Integer;
R, G, B: Integer;
H, S, L: ExtEnded;
X, Y, Z: ExtEnded;
Gas, Gas2: TPointArray;
Colors, C2: TIntegerArray;
begin
Try
x1 := gx - 35;
If x1 < 0 Then
x1 := 0;
y1 := gy - 35;
If y1 < 0 Then
y1 := 0;
x2 := gx + 35;
If x2 > 515 Then
x2 := 515;
y2 := gy + 35;
If y2 > 336 Then
y2 := 336;
Time := GetSystemTime;
Result := False;
c := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2ModIfiers(0.2, 0.2);
FindColorsTolerance(Gas, 8886170, x1, y1, x2, y2, 20);
ColorToleranceSpeed(c);
If length(Gas) < 10 Then
Exit;
Colors := GetColors(Gas);
C2 := Colors;
ClearSameIntegers(C2);
writeln('w_Colors Length: ' + inttostr(length(colors)));
writeln('w_C2 Length: ' + inttostr(length(C2)));
If Length(C2) < 40 Then
Exit;
For I := 0 To High(Gas) Do
Begin
ColorToRGB(Colors[I], R, G, B);
If Abs(R - G) <= 10.0 Then
Begin
ColorToHSL(Colors[I], H, S, L);
If (H > 11.5) And (H < 16.0) And (S < 12.0) Then
Begin
ColorToXYZ(Colors[I], X, Y, Z);
If (Abs(X - Y) < 5.0) And (Abs(X - Z) < 5.0) And (Abs(Y - Z) < 5.0) Then
Begin
SetLength(Gas2, Length(Gas2) + 1);
Gas2[High(Gas2)] := Gas[I];
End;
End;
End;
End;
WriteLn('w_time: ' + IntToStr(GetSystemTime - Time));
WriteLn('w_gas2 length: ' + IntToStr(Length(Gas2)));
Result := (Length(Gas2) > 30); // The only number you might want to tweak.
debugtpa(Gas2, '');
If Result Then
WriteLn('w_GasCheck gave true');
Except WriteLn('w_gasCheck ERROR: No window selected'); End;
End;
function w_GasCheckMS: boolean;
Var
x1, y1, x2, y2, I, time, c: Integer;
R, G, B: Integer;
H, S, L: Extended;
X, Y, Z: Extended;
Gas, Gas2: TPointArray;
Colors: TIntegerArray;
begin
Try
x1 := 3;
y1 := 3;
x2 := 515;
y2 := 336;
writeln('Searching in: ('+inttostr(x1) + ', '+inttostr(y1) + ')');
writeln('Searching in: ('+inttostr(x2) + ', '+inttostr(y2) + ')');
Time := GetSystemTime;
Result := False;
c := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.2, 0.2);
FindColorsTolerance(Gas, 8886170, x1, y1, x2, y2, 20);
ColorToleranceSpeed(c);
WriteLn('gas1 length: ' + IntToStr(Length(Gas)));
If length(Gas) < 10 Then
Exit;
Colors := GetColors(Gas);
For I := 0 To High(Gas) Do
Begin
ColorToRGB(Colors[I], R, G, B);
If Abs(R - G) <= 15.0 Then
Begin
ColorToHSL(Colors[I], H, S, L);
If (H > 8.0) And (H < 16.0) And (S < 12.0) Then
Begin
ColorToXYZ(Colors[I], X, Y, Z);
If (Abs(X - Y) < 5.0) And (Abs(X - Z) < 5.0) Then
Begin
SetLength(Gas2, Length(Gas2) + 1);
Gas2[High(Gas2)] := Gas[I];
End;
End;
End;
End;
WriteLn('time: ' + IntToStr(GetSystemTime - Time));
WriteLn('gas2 length: ' + IntToStr(Length(Gas2)));
result := (Length(Gas2) > 30); // The only number you might want to tweak.
debugtpa(gas2, '');
Except WriteLn('w_gasCheck ERROR: No window selected'); end;
end;
function w2_GasCheck(gx, gy: integer): boolean;
Var
x1, y1, x2, y2, I, time, c: Integer;
R, G, B: Integer;
H, S, L: ExtEnded;
X, Y, Z: ExtEnded;
Gas, Gas2: TPointArray;
Colors, C2: TIntegerArray;
begin
Try
x1 := gx - 35;
If x1 < 0 Then
x1 := 0;
y1 := gy - 35;
If y1 < 0 Then
y1 := 0;
x2 := gx + 35;
If x2 > 515 Then
x2 := 515;
y2 := gy + 35;
If y2 > 336 Then
y2 := 336;
Time := GetSystemTime;
Result := False;
c := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2ModIfiers(0.2, 0.2);
FindColorsTolerance(Gas, 6126985, x1, y1, x2, y2, 20);
ColorToleranceSpeed(c);
If length(Gas) < 10 Then
Exit;
Colors := GetColors(Gas);
C2 := Colors;
ClearSameIntegers(C2);
writeln('w2_Colors Length: ' + inttostr(length(colors)));
writeln('w2_C2 Length: ' + inttostr(length(C2)));
If Length(C2) < 40 Then
Exit;
For I := 0 To High(Gas) Do
Begin
ColorToRGB(Colors[I], R, G, B);
If Abs((R - 10) - G) <= 5.0 Then
Begin
ColorToHSL(Colors[I], H, S, L);
If (H > 10.0) And (H < 18.0) And (S > 12.0) And (S < 22.0) Then
Begin
ColorToXYZ(Colors[I], X, Y, Z);
If (Abs(X - Z) < 3.0) Then
Begin
SetLength(Gas2, Length(Gas2) + 1);
Gas2[High(Gas2)] := Gas[I];
End;
End
End;
End;
WriteLn('w2_time: ' + IntToStr(GetSystemTime - Time));
WriteLn('w2_gas2 length: ' + IntToStr(Length(Gas2)));
Result := (Length(Gas2) > 30); // The only number you might want to tweak.
debugtpa(Gas2, '');
If Result Then
WriteLn('w2_GasCheck gave true');
Except WriteLn('w2_gasCheck ERROR: No window selected'); End;
End;
function w2_GasCheckMS: boolean;
Var
x1, y1, x2, y2, I, time, c: Integer;
R, G, B: Integer;
H, S, L: Extended;
X, Y, Z: Extended;
Gas, Gas2: TPointArray;
Colors: TIntegerArray;
begin
Try
x1 := 3;
y1 := 3;
x2 := 515;
y2 := 336;
writeln('Searching in: ('+inttostr(x1) + ', '+inttostr(y1) + ')');
writeln('Searching in: ('+inttostr(x2) + ', '+inttostr(y2) + ')');
Time := GetSystemTime;
Result := False;
c := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.2, 0.2);
FindColorsTolerance(Gas, 6126985, x1, y1, x2, y2, 20);
ColorToleranceSpeed(c);
WriteLn('gas1 length: ' + IntToStr(Length(Gas)));
If length(Gas) < 10 Then
Exit;
Colors := GetColors(Gas);
For I := 0 To High(Gas) Do
Begin
ColorToRGB(Colors[I], R, G, B);
If Abs((R - 10) - G) <= 5.0 Then
Begin
ColorToHSL(Colors[I], H, S, L);
If (H > 10.0) And (H < 18.0) And (S > 12.0) And (S < 22.0) Then
Begin
ColorToXYZ(Colors[I], X, Y, Z);
If (Abs(X - Z) < 3.0) Then
Begin
SetLength(Gas2, Length(Gas2) + 1);
Gas2[High(Gas2)] := Gas[I];
End;
End;
End;
End;
WriteLn('time: ' + IntToStr(GetSystemTime - Time));
WriteLn('gas2 length: ' + IntToStr(Length(Gas2)));
result := (Length(Gas2) > 30); // The only number you might want to tweak.
debugtpa(gas, '');
Except WriteLn('w2_gasCheck ERROR: No window selected'); end;
end;
Function w_FindGas(gx, gy: Integer): Boolean;
Begin
Result := w_GasCheck(gx, gy);
If Not Result Then
Result := w2_GasCheck(gx, gy);
End;
Var
x, y: integer;
begin
{ if w2_gasCheckMS then
writeln('GAS'); }
repeat
wait(1000);
getmousepos(x, y);
if w_FindGas(x, y) then
writeln('found gas')
else
writeln('no gas');
until false;
end.There.
Note and thanks to The Claw: His pictures, I commented names out, hope thats alright. :)



Feedback, please.
You could run it on the pictures above, or on your own? :)
EDIT: You might still want to do w_GasCheck(x, y-20) in your script, since gas is always a bit above your rock. :)