SRL Archive - OSR Help

What is wrong with the FindColors functions?


bud_wis_er_420

2013-04-05 23:12:56

I made this function to get my hp lvl. Yes I know there is a SRL function for that but I want mine to work in all resolutions. The part in my function that keeps failing it the FindColors function. It is not finding the txt colors when I know they are there. For god sakes it is a constant color. It don't change. But it won't even find the color with a tol of 30. I even have a sort of debug in my function to make sure the box it is looking for the colors in, is correct.

This is so frustrating. I been going back and forth with this for hours now. Please someone tell me whats going on.

function GetHealth: Integer;
var
i, W, H: Integer;
Box, TempBox: TBox;
Colors : TIntegerArray;
TPA: TPointArray;
txt: string;
begin;
Result := -1;

GetClientDimensions(W, H);
if FixedScreen then
Box := IntToBox(719,27,745,43)
else Box := IntToBox(W - 223, 46, w - 183, 66);

//check box cords
MMouse(Box.X1, Box.Y1,0,0);
wait(2000);
MMouse(Box.X2, Box.Y2,0,0);
wait(2000);

//Loops through all 4 Health colors
Colors := [65280, 65535, 2070783, 255];
for i := 0 to 3 do
begin
writeln('Color looking for is: ' + IntToStr(Colors[i]));
if FindColorsTolerance(TPA, Colors[i], Box.X1, Box.Y1, Box.X2, Box.Y2, 30) then
begin
TempBox := GetTPABounds(TPA);
//check box cords
MMouse(TempBox.X1, TempBox.Y1,0,0);
wait(2000);
MMouse(TempBox.X2, TempBox.Y2,0,0);

//check text before number
txt := GetTextAtExWrap(TempBox.X1, TempBox.Y1, TempBox.X2, TempBox.Y2, 0, 4, 4, Colors[i], 0, statChars);
writeln(txt);

Result := StrToIntDef(GetNumbers(GetTextAtExWrap(TempBox.X1, TempBox.Y1, TempBox.X2, TempBox.Y2, 0, 4, 4, Colors[i], 0, statChars)), -1);
if (Result > -1) then
Exit;
end else writeln('The Color was not found: ' + IntToStr(Colors[i]));
end;
end;

Ian

2013-04-06 00:04:13

Why do you want it to be able to work at all resolutions?

You'd need to re-write a lot more than just that to have the include working properly at different resolutions too.

bud_wis_er_420

2013-04-06 14:05:08

Not really, the problem is it sometimes finds the colors and sometimes it don't. It's like the Simba function is failing when the color exists. Right after I posted this last night it started working again. It's weird. I made a script as simple as possible to look for the txt color in that area and it would fail. I go away for a few mins and come back and try it again and it would work. I can understand if the color changed, I might be getting the tol off or something. But it is a const color. So if I say look for color here and I know here is the right place and the color does eixist the FindColors should find it no mater what.

The health txt is the same distance from the top and right side of the screen at all resolutions exept Fixed screen which is why all that is need to read the txt is:
  GetClientDimensions(W, H);
if FixedScreen then
Box := IntToBox(719,27,745,43)
else Box := IntToBox(W - 223, 46, w - 183, 66);
with a const setting FixedScreen being True or False.

Here is my simi finished script. I still plan on adding and changing a few things but it basically works. You can uncommit the checkhealth on line 195 and it will eat too. Place food in tab slot 11. But it basically will auto activate your abilities when you are in the combat tab and it sees a target. Works in any res.

program new;
{$I SRL/SRL.Simba}

const
HealAt = 30; //Enter in percent of max health
BarMax = 12;
FixedScreen = False;
Bar = True;


var
MaxHealth: Integer;
AblBmp, AbCk: TIntegerArray;


function ActionBarSlotToBox_Custom(Slot: Integer): TBox;
var
W, H: Integer;
begin
if InRange(Slot, 1, 12) then
begin
GetClientDimensions(W, H);
with Result do
begin
X1 := 56 + (Slot - 1) * 36;
Y1 := H - 205;
X2 := X1 + 16;
Y2 := Y1 + 21;
end;
end else
writeln('ActionBarSlotToBox, Slot must be within 1-12!');
end;


function IsAbilityReady(Slot: Integer): Boolean;
var
i,x,y: Integer;
h, s, l, Avg: Extended;
TIA: TIntegerArray;
TIALum: TExtendedArray;
Box: TBox;
begin
Result := False;
Box := ActionBarSlotToBox_Custom(Slot);
TIA := GetColorsBox(Box.x1, Box.y1, Box.x2, Box.y2, False);
setLength(TIALum, High(TIA)+1);
for i := 0 to High(TIA) do
begin
ColorToHSL(TIA[i], h, s, l);
TIALum[i] := l;
//writeln(FloatToStr(l));
end;
Avg := AverageExtended(TIALum);
Result := (Avg > 10);
end;


procedure CheckActionSlotReady(abs: Integer);
var
x, y, c, rev, TempBmp: Integer;
Box: TBox;
begin
Box := ActionBarSlotToBox_Custom(abs);
if (AbCk[abs] = 0) and IsAbilityReady(abs) then
begin
//writeln('Taking a temp bmp from slot ' + IntToStr(abs));
AblBmp[abs] := BitmapFromClient(Box.x1 + 5, Box.y1 + 5, Box.x2 - 5, Box.y2 - 5);
SetBitmapName(AblBmp[abs], 'AblBmp[' + IntToStr(abs) + '].bmp');
AbCk[abs] := 1;
end;

if FindBitmapToleranceIn(AblBmp[abs], x, y, Box.x1, Box.y1, Box.x2, Box.y2, 10) then
begin
//writeln('Found bmp, using ability slot ' + IntToStr(abs));
TypeSendEx(IntToStr(abs), False);
wait(RandomRange(1800, 2000));
end;
end;

function GetTargetText: string;
var
W, H: Integer;
TPA: TPointArray;
Box: TBox;
begin
GetClientDimensions(W, H);
Box := IntToBox(W - 190, H - 360, W - 80, H - 270);
if FindColors(TPA, 3111603, Box.X1, Box.Y1, Box.X2, Box.Y2) then
begin
Box := GetTPABounds(TPA);
Result := GetTextAtExWrap(Box.X1, Box.Y1, Box.X2, Box.Y2, 0, 3, 4, 3111603, 0, UpChars);
end;
end;

function HaveTarget: Boolean;
var
x, y, W, H, TargetTxtBmp: Integer;
str: string;
TSA: TStringArray;
TPA: TPointArray;
Box: TBox;
begin
Result := False;
GetClientDimensions(W, H);
Box := IntToBox(W - 190, H - 360, W - 80, H - 270);
if FindColors(TPA, 3111603, Box.X1, Box.Y1, Box.X2, Box.Y2) then
Box := GetTPABounds(TPA);

if FindColorTolerance(x, y, 2657624, box.x1, box.y2,box.x2, box.y2 + 20, 36) then
result := True;
end;


function GetHealth: Integer;
var
i, W, H: Integer;
Box, TempBox: TBox;
Colors : TIntegerArray;
TPA: TPointArray;
txt: string;
begin;
Result := -1;

GetClientDimensions(W, H);
if FixedScreen then
Box := IntToBox(719,27,745,43)
else Box := IntToBox(W - 223, 46, w - 183, 66);

{//check box cords
MMouse(Box.X1, Box.Y1,0,0);
wait(2000);
MMouse(Box.X2, Box.Y2,0,0);
wait(2000); }

//Loops through all 4 Health colors
Colors := [65280, 65535, 2070783, 255];
for i := 0 to 3 do
begin
//writeln('Color looking for is: ' + IntToStr(Colors[i]));
if FindColorsTolerance(TPA, Colors[i], Box.X1, Box.Y1, Box.X2, Box.Y2, 30) then
begin
TempBox := GetTPABounds(TPA);
//check box cords
{MMouse(TempBox.X1, TempBox.Y1,0,0);
wait(2000);
MMouse(TempBox.X2, TempBox.Y2,0,0);

//check text before number
txt := GetTextAtExWrap(TempBox.X1, TempBox.Y1, TempBox.X2, TempBox.Y2, 0, 4, 4, Colors[i], 0, statChars);
writeln(txt); }

Result := StrToIntDef(GetNumbers(GetTextAtExWrap(TempBox.X1, TempBox.Y1, TempBox.X2, TempBox.Y2, 0, 4, 4, Colors[i], 0, statChars)), -1);
if (Result > -1) then
Exit;
end else writeln('The Color was not found: ' + IntToStr(Colors[i]));
end;
end;

procedure EatFood;
var
Health: Integer;
begin
Health := GetHealth;
repeat
KeyDown(189);
wait(RandomRange(100, 200));
KeyUp(189);
wait(RandomRange(1200, 1500));
Health := GetHealth;
until(Health > (0.8 * MaxHealth))
end;


procedure CheckHealth;
var
Health: Integer;
begin
Health := GetHealth;
//writeln('Health is: ' + IntTOStr(GetHealth));
if (Health > MaxHealth) then
MaxHealth := Health;

// check if health is below set percent
if (Health < ((0.01 * HealAt) * MaxHealth)) then
EatFood;
end;


procedure MainLoop;
var
i, slot: Integer;
begin

//Checks health
//CheckHealth;
// Checks Action bar
if HaveTarget then
begin
for i:= 0 to BarMax do
begin
case i of
0 : slot := BarMax;
1 : slot := BarMax - 1;
3 : slot := BarMax - 2;
4 : slot := BarMax - 3;
5 : slot := BarMax - 4;
6 : slot := BarMax - 5;
7 : slot := BarMax - 6;
8 : slot := BarMax - 7;
9 : slot := BarMax - 8;
10 : slot := BarMax - 9;
end;
//writeln('Checking slot: ' + IntToStr(slot));
CheckActionSlotReady(slot);
if HaveTarget then Continue;
end;
end;
end;

procedure Setup;
var
i: Integer;
begin
setLength(AbCk, BarMax + 17);
setLength(AblBmp, BarMax + 1);
for i := 0 to High(AbCk) do
begin
AbCk[i] := 0;
end;
end;
var
W, H: Integer;

Begin
SetUpSRL;
wait(5000);
Setup;
ClearDebug;
MaxHealth := GetHealth;
writeln('MaxHealth is: ' + IntToStr(MaxHealth));
repeat
MainLoop;
wait(RandomRange(200, 220));
until(false)
//writeln('Health is: ' + IntTOStr(GetHealth));
End.

Dervish

2013-04-06 15:32:38

To see if FindColor fails open up paint and paste a color then look for it in simba with a debug print. If it finds it (which I'm 99% sure it will), it would mean that either the colors you're using are wrong (which I doubt they are), or the dimensions of the box you're going through are. To be honest, just use Fixed Screen resolution, makes things easier :).

However, maybe using fullscreen and such can be a way of antiban ? :p

bud_wis_er_420

2013-04-06 16:08:49

The point of my script is to use it while actually playing rs. I don't know about you but I play in max screen size. And if others want to use my script when I finish it, I figured they'd do the same. And my screen may be a different size then yours, hence the needing it to work in all screen resolutions.

I'm 100% sure it was looking in the correct box and I'm 100% sure the color existed. That's what I been saying. The function randomly would not find the color, when I know it existed and was looking in the correct spot. I even tried with a color tol up to 30 just for the hell of it and it still didn't find it. Then later all of a sudden it worked fine.

What I been saying is I narrowed it down, thru testing, that it is the FindColors function that is failing. Was trying to find out if anyone has been thru this before and what they did to resolve it. Trust me when I tell you it's not my code that is failing it is the simba function.

Just try it for your self I posted it 2 post up

if it wasn't looking in the correct box or looking for wrong color it was within the FindColors function the error happened in. Because it you look at my code I checked the cords right b4 I passed them to the function.