SRL Archive - Simba (Testing) Scripts

Having trouble with GetXp (Simba OCR)


Wanted

2011-01-19 20:42:19

function GetXP(Skill: Variant): Integer;
var
B: TBox;
p: TPoint;
tx, ty: Integer;
TPA: TPointArray;
begin
Result := -1;
if (not TabExists(tab_Stats)) then exit;
GameTab(tab_Stats);
if (GetCurrentTab <> tab_Stats) then exit;
P := SkillToCoords(Skill);
if (P.x < 1) then exit;
MMouse(P.x, P.y + 5, 12, 4);
if (not WaitFindColors(TPA, 10551295, MIX1, MIY1, MIX2, MIY2, 0, 4000)) then exit;
B := GetTPABounds(TPA);
Wait(200 + Random(150));
if IsTextInAreaEx(B.X1, B.Y1, B.X2, B.Y2, tx, ty, 'urrent', 0, SmallChars, False, False, 0, 1, 0) then
Result := StrToIntDef(GetNumbers(GetTextAtEx(tx, ty, 0, SmallChars, False, True, 0, 1, 0, 50, False, tr_AllChars)), -1);
end;

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

begin
ActivateClient;
SetUpSRL;
Wait(1000);
WriteLn(GetXp(Skill_Range));
end.

Always coming up -1 (in simba), I've tried everything to get it to work.

Wanted

2011-01-20 03:01:42

Sorta rigged it, and it works 99%. But every now and then it appends another number it gets from I have no idea where.

function GetXP(Skill: Variant): Integer;
var
B: TBox;
p: TPoint;
tx, ty: Integer;
TPA: TPointArray;
begin
Result := -1;
if (not TabExists(tab_Stats)) then exit;
GameTab(tab_Stats);
if (GetCurrentTab <> tab_Stats) then exit;
P := SkillToCoords(Skill);
if (P.x < 1) then exit;
MMouse(P.x, P.y + 5, 12, 4);
if (not WaitFindColors(TPA, 10551295, MIX1, MIY1, MIX2, MIY2, 0, 4000)) then exit;
B := GetTPABounds(TPA);
Wait(400 + Random(150));
{$IFDEF Simba}
Result := StrToIntDef(GetNumbers(GetTextAt(B.X1 + 15, B.Y1 + 15, 0, 1, 4, clBlack, 0, 75, SmallChars)), -1);
{$ELSE}
if IsTextInAreaEx(B.X1, B.Y1, B.X2, B.Y2, tx, ty, 'urrent', 0, SmallChars, False, False, 0, 1, 0) then
Result := StrToIntDef(GetNumbers(GetTextAtEx(tx, ty, 0, SmallChars, False, True, 0, 1, 0, 50, False, tr_AllChars)), -1);
{$ENDIF}
end;

lordsaturn

2011-01-20 03:02:19

okay let me try,

edit: ^ ninja'd somehow even tho a day later. it works, didn't experience the error you mentioned.

Wanted

2011-01-20 03:17:31

From: lordsaturn
okay let me try,

edit: ^ ninja'd somehow even tho a day later. it works, didn't experience the error you mentioned.


The previous code from the revision before I updated it works? I don't think so.

Try again with the older rev, see if you can up for a better solution, the one I have in place isn't perfect and probably not the best.

lordsaturn

2011-01-20 03:38:33

From: IceFire908
The previous code from the revision before I updated it works? I don't think so.

Try again with the older rev, see if you can up for a better solution, the one I have in place isn't perfect and probably not the best.


i meant the code from the second post works, i didn't test the first post. since you asked, i will try and fix the first post.

Wanted

2011-01-20 19:05:24

Come up with anything? :S

lordsaturn

2011-01-22 03:25:57

This proves to me that FindTextTPAinTPA doesn't work correctly:
    var a,b,c:tpointarray;w,h:integer;
begin
SetupSRL;
a := TPAFromText('Current', SmallChars, w, h);
b := TPAFromText('urrent', SmallChars, w, h);
FindTextTPAinTPA(h, b, a, c); writeln(length(c));
end.
writes 0.

Edit: Replacing FindTextTPAinTPA with FindTPAinTPA writes 1.

Wizzup?

2011-01-22 04:50:55

From: lordsaturn
This proves to me that FindTextTPAinTPA doesn't work correctly:
    var a,b,c:tpointarray;w,h:integer;
begin
SetupSRL;
a := TPAFromText('Current', SmallChars, w, h);
b := TPAFromText('urrent', SmallChars, w, h);
FindTextTPAinTPA(h, b, a, c); writeln(length(c));
end.
writes 0.

Edit: Replacing FindTextTPAinTPA with FindTPAinTPA writes 1.


A quick guess: FindTextTPAinTPA takes a height (h in this case) parameter. You're leaving it at 0 there, that's why it doesn't work.

lordsaturn

2011-01-22 05:23:34

From: Wizzup?
A quick guess: FindTextTPAinTPA takes a height (h in this case) parameter. You're leaving it at 0 there, that's why it doesn't work.


writeln(h); –> 16

edit: function TPAFromText(const text; font: String;var w,h : integer): TPointArray;

Wizzup?

2011-01-22 05:38:05

From: lordsaturn
writeln(h); –> 16

edit: function TPAFromText(const text; font: String;var w,h : integer): TPointArray;


Ah, I just woke up. :p

lordsaturn

2011-01-22 05:46:06

here is the code, for all to scrutinize:


{/\
Looks for the TPA SearchTPA in the TPA TotalTPA and returns the matched points
\\ to the TPA Matches. Returns true if there were atleast one match(es).
/\}

function FindTPAinTPA(SearchTPA : TPointArray; const TotalTPA: TPointArray; var Matches: TPointArray): Boolean;
var
Len, I,II,LenSearch,xOff,yOff : integer;
tx,ty,MatchCount : integer;
Screen : T2DBoolArray;
ScreenBox,SearchBox : TBox;
Found: Boolean;
begin;
Result := False;
Len := High(TotalTPA);
LenSearch := High(SearchTPA);
if LenSearch < 0 then Exit;
if Len < LenSearch then Exit;
MatchCount := 0;
ScreenBox := GetTPABounds(TotalTPA);
SearchBox := GetTPABounds(SearchTPA);
try
SetLength(Screen,ScreenBox.x2 + 1,ScreenBox.y2 + 1);
for i := ScreenBox.x2 downto 0 do
FillChar(Screen[i][0],screenbox.y2+1,0);
except
Exit;
end;
if (SearchBox.x1 > 0) or (SearchBox.y1 > 0) then
begin;
for I := 0 to LenSearch do
begin;
SearchTPA[I].x := SearchTPA[I].x - SearchBox.x1;
SearchTPA[I].y := SearchTPA[I].y - SearchBox.y1;
end;
SearchBox.x2 := SearchBox.x2 - SearchBox.x1;
SearchBox.y2 := SearchBox.y2 - SearchBox.y1;
SearchBox.x1 := 0;
SearchBox.y1 := 0;
end;
xOff := SearchBox.x2;
yOff := SearchBox.y2;
for I := 0 to LenSearch do
begin;
if (SearchTPA[I].x = 0) and (SearchTPA[I].y < yOff) then
yOff := SearchTPA[I].y;
if (SearchTPA[I].y = 0) and (SearchTPA[I].x < xOff) then
xOff := SearchTPA[I].x;
end;
for I := 0 to Len do
Screen[TotalTPA[I].x][TotalTPA[I].y] := True;
for I := 0 to Len do
begin;
tx := TotalTPA[I].x - xOff;
ty := TotalTPA[I].y;// - yOff;
if tx > 0 then
if ty > 0 then
if ((SearchBox.x2 + tx) <= ScreenBox.x2) and ((SearchBox.y2 + ty) <= ScreenBox.y2) then
begin;
Found := false;
For II := 0 to LenSearch do
if Screen[tx + SearchTPA[II].x ][ty + SearchTPA[II].y] = False then
begin
Found := True;
Break;
end;
if not found then
// if II > LenSearch then
begin;
MatchCount := MatchCount + 1;
SetLength(Matches,MatchCount);
Matches[MatchCount - 1].x := TotalTPA[I].x;
Matches[MatchCount - 1].y := TotalTPA[I].y;
end;
end;
end;
if (MatchCount > 0) then
Result := True;
end;

{/\
Read the description of FindTPAinTPA. Additional Height parameter.
/\}

function FindTextTPAinTPA(Height : integer;const SearchTPA, TotalTPA: TPointArray; var Matches: TPointArray): Boolean;
var
Len, I,II,LenSearch,LenTPA,xOff,yOff,x,y: integer;
tx,ty,MatchCount : integer;
Found : boolean;
Screen : T2DBoolArray;
ScreenBox,SearchBox : TBox;
InversedTPA : TPointArray;
begin;
Result := False;
Len := High(TotalTPA);
LenSearch := High(SearchTPA);
if LenSearch < 0 then Exit;
if Len < LenSearch then Exit;
MatchCount := 0;
xOff := -5;
yOff := 0;
ScreenBox := GetTPABounds(TotalTPA);
SearchBox := GetTPABounds(SearchTPA);
if height > SearchBox.y2 then
Screenbox.y2 := Screenbox.y2 + (height - SearchBox.y2);
SearchBox.y2 := Height;
SetLength(Screen, SearchBox.x2 + 1,SearchBox.y2 + 1);
for i := SearchBox.x2 downto 0 do
FillChar(screen[i][0],SearchBox.y2+1,0);
SetLength(InversedTPA,(SearchBox.x2 + 1) * (Searchbox.y2 + 1));
for I := 0 to LenSearch do
Screen[ SearchTPA[I].x,SearchTPA[I].y] := True;
LenTPA := -1;
for y := 0 to SearchBox.y2 do
for x := 0 to SearchBox.x2 do
if Screen[X][Y] = False then
begin;
LenTPA := LenTPA + 1;
InversedTPA[LenTPA].x := x;
InversedTPA[LenTPA].y := y;
end;
for x := 0 to SearchBox.x2 do
begin;
for y := 0 to SearchBox.y2 do
if Screen[x][y] = True then
begin;
xOff := x;
yOff := y;
Break;
end;
if xOff >= 0 then
Break;
end;
try
SetLength(Screen,0);
SetLength(Screen,ScreenBox.x2 + 1,ScreenBox.y2 + 1);
for i := ScreenBox.x2 downto 0 do
FillChar(screen[i][0],screenbox.y2+1,0);
except
Exit;
end;
for I := 0 to Len do
Screen[TotalTPA[I].x][TotalTPA[I].y] := True;
for I := 0 to Len do
begin;
tx := TotalTPA[I].x - xOff;
ty := TotalTPA[I].y - yOff;
if tx > 0 then
if ty > 0 then
if ((SearchBox.x2 + tx) <= ScreenBox.x2) and ((SearchBox.y2 + ty) <= ScreenBox.y2) then
begin;
Found := false;
For II := 0 to LenSearch do
if Screen[tx + SearchTPA[II].x ][ty + SearchTPA[II].y] = False then
begin
Found := true;
Break;
end;
if (not Found) then
begin;
Found := false;
For II := 0 to LenTPA do
if Screen[tx + InversedTPA[II].x ][ty + InversedTPA[II].y] = True then
begin
Found := true;
Break;
end;
if (not Found) then
begin;
MatchCount := MatchCount + 1;
SetLength(Matches,MatchCount);
Matches[MatchCount - 1].x := TotalTPA[I].x;
Matches[MatchCount - 1].y := TotalTPA[I].y;
end;
end;
end;
end;
if (MatchCount > 0) then
Result := True;
end;

Wizzup?

2011-01-22 05:51:51

Yeah; I was looking at that before. I'll have a look later. But is this a problem with the OCR or with FindTextTPAinTPA?

lordsaturn

2011-01-22 05:55:38

From: Wizzup?
Yeah; I was looking at that before. I'll have a look later. But is this a problem with the OCR or with FindTextTPAinTPA?


FindTextTPAinTPA, I think FindTPAinTPA is broke too (I've had trouble with it in the past) / they aren't working correctly.

OCR works, see Icefire's second post.

Wanted

2011-01-22 14:55:53

From: Wizzup?
Yeah; I was looking at that before. I'll have a look later. But is this a problem with the OCR or with FindTextTPAinTPA?


No idea, probably FindTextTPAInTPA which is simba's IsTextInArea. I was getting really frustrated trying to fix GetXP so I made this thread hoping to find the answer.