SRL Archive - Research & Development Lounge

function FindHPBarsTPA(var Count : Integer; Var Position : TPointArray) : boolean;


Metagen

2008-04-14 19:04:51

finds hp bars on MS. Returns how many there are, and the midpoints in a TPA. returns false if none found.

little bug i'm working out: it can take up to 7 seconds on my pc to run, but it doesn't lag your screen.


function FindHPBarsTPA(var Count : Integer; Var Position : TPointArray) : boolean;
var PointsTPA, FinalTPA : TPointArray;
TPAA : T2DPointArray;
i, j, color : integer;
begin
setlength(PointsTPA, 0);
setlength(FinalTPA, 0);
for i := msx1 to msx2 do
begin
for j := msy1 to msy2 do
begin
Color := getcolor(i, j)
if (Color = 255) or (Color = 65280) then
begin
SetLength(PointsTPA, Length(PointsTPA) + 1);
PointsTPA[Length(PointsTPA)-1] := IntToPoint(i,j);
end;
end;
end;
TPAA := TPAtoATPAEx(PointsTPA, 30, 5);
for i := 0 to Length(TPAA) -1 do
begin
if Length(TPAA[i]) = 150 then
begin
SetLength(FinalTPA, Length(FinalTPA) + 1);
FinalTPA[Length(FinalTPA) - 1 ] := MiddleTPA(TPAA[i]);
end;
end;
Count := length(FinalTPA);
Position := FinalTPA;
if count = 0 then
begin
Result := false
exit;
end;
Result := true;
end;

faster789

2008-04-14 19:41:47

Awsome…..This'll be VERY usefull…Rep+;) :D

Santa_Clause

2008-04-14 20:00:33

Holy dang…that does a GetColor on all mainscreen points. Have you tested this? I think it would take awfully long.

Metagen

2008-04-14 22:49:03

yeaaaa i know :p i did test it for about 2 minutes. Takes about 7 seconds per run for me. Any ideas to cut that down? cause thats the only slow part

munk

2008-04-15 00:00:53


for i := msx1 to msx2 do
begin
for j := msy1 to msy2 do
begin
Color := getcolor(i, j)
if (Color = 255) or (Color = 65280) then
begin
SetLength(PointsTPA, Length(PointsTPA) + 1);
PointsTPA[Length(PointsTPA)-1] := IntToPoint(i,j);
end;
end;
end;
=

findColorsTolerance(tpa1,65280,msx1,msy1,msx2,msy2,0);
findColorsTolerance(tpa2,255,msx1,msy2,msx2,msy2,0);
pointsTPA:=combineTPA(tpa1,tpa2);
:)

Santa_Clause

2008-04-15 01:12:24

I wrote this up:

function FindHPBarsTPA(var Count : Integer; HPType : string) : TPointArray;
var
I : Integer;
ResultLength : Integer;
PointArray : TPointArray;
PointArrayArray : Array of TPointArray;
SubArray : Array [0..1] of TPointArray;
TimeTaken : Integer;
begin
MarkTime(TimeTaken);

case Lowercase(HPType) of
'health' : FindColorsTolerance(PointArray, 65280, MSX1, MSY1, MSX2, MSY2, 0);
'damage' : FindColorsTolerance(PointArray, 255, MSX1, MSY1, MSX2, MSY2, 0);
'both' : begin
for I := 0 to 1 do
FindColorsTolerance(SubArray[I], 255 + (65025 * I), MSX1, MSY1, MSX2, MSY2, 0);
PointArray := CombineTPA(SubArray[0], SubArray[1]);
end;
else
begin
WriteLn('Invalid Health/Damage Parameter');
Exit;
end;
end;

PointArrayArray := TPAToATPAEx(PointArray, 30, 5);

for I := 0 to High(PointArrayArray) do
if Length(PointArrayArray[I]) = 150 then
Inc(ResultLength);

SetArrayLength(Result, ResultLength);
Count := ResultLength;
ResultLength := ResultLength xor ResultLength;

for I := 0 to High(PointArrayArray) do
if Length(PointArrayArray[I]) = 150 then
begin
Result[ResultLength] := MiddleTPA(PointArrayArray[I]);
Inc(ResultLength);
end;

WriteLn('Time Taken To Finish : ' + IntToStr(TimeFromMark(TimeTaken)));
end;

Metagen

2008-04-15 06:42:30

Santa you're my hero

n3ss3s

2008-04-15 06:56:36

Aww come on!

Look how short one I have in my goblin killer - all that is needed to find all HPs on the mainscreen (you have to edit the coords in the bar finder for full mainscreen though)


Function FindAllHPBars: Array of TPointArray;

Var
g, r: TPointArray;

Begin

FindColorsTolerance(g, 65280, MSCX - 60, MSCY - 60, MSCX + 60, MSCY + 60, 0);
FindColorsTolerance(r, 255, MSCX - 60, MSCY - 60, MSCX + 60, MSCY + 60, 0);

Result := TPAToATPAEx(CombineTPA(g, r), 31, 5);

End;


Function GetHits: TIntegerArray;

Var
TPAA: T2DPointArray;
E: Extended;
I: Integer;
TB: TBox;

Begin

TPAA := FindAllHPBars;
SetArrayLength(Result, GetArrayLength(TPAA));

For I := 0 To High(TPAA) Do
Begin
TB := GetTPABounds(TPAA[i]);
E := CountColor(65280, TB.x1, TB.y1, TB.x2, TB.y2) / 150;
Result[i] := Round(100 * E);
End;

End;


HP Percentages…

ShowerThoughts

2008-04-15 09:56:36

From: n3ss3s
Aww come on!

Look how short one I have in my goblin killer - all that is needed to find all HPs on the mainscreen (you have to edit the coords in the bar finder for full mainscreen though)


Function FindAllHPBars: Array of TPointArray;

Var
g, r: TPointArray;

Begin

FindColorsTolerance(g, 65280, MSCX - 60, MSCY - 60, MSCX + 60, MSCY + 60, 0);
FindColorsTolerance(r, 255, MSCX - 60, MSCY - 60, MSCX + 60, MSCY + 60, 0);

Result := TPAToATPAEx(CombineTPA(g, r), 31, 5);

End;


Function GetHits: TIntegerArray;

Var
TPAA: T2DPointArray;
E: Extended;
I: Integer;
TB: TBox;

Begin

TPAA := FindAllHPBars;
SetArrayLength(Result, GetArrayLength(TPAA));

For I := 0 To High(TPAA) Do
Begin
TB := GetTPABounds(TPAA[i]);
E := CountColor(65280, TB.x1, TB.y1, TB.x2, TB.y2) / 150;
Result[i] := Round(100 * E);
End;

End;


HP Percentages…


Thanks n3s3s i already was looking for something like this :D

mastaraymond

2008-04-15 10:35:23

Thats quite bad if you didn't know FindColorsTolerance existed :rolleyes:

ShowerThoughts

2008-04-15 12:07:09

From: mastaraymond
Thats quite bad if you didn't know FindColorsTolerance existed :rolleyes:


You meant me? yes i knew that -.-.


N3ss3s what does it returns? because i used a boolean i used a number but it is returning a tpa… how to use that tpa?

mastaraymond

2008-04-15 12:34:26

From: Hermpie
You meant me? yes i knew that -.-.


N3ss3s what does it returns? because i used a boolean i used a number but it is returning a tpa… how to use that tpa?

Did I reply to your message? No… No I meant the thread starter silly.

Metagen

2008-04-15 14:58:29

FindColorsTolerance is less accurate them the for loops. My function is perfectly accurate :p which is why it takes so long

Santa_Clause

2008-04-15 19:20:35

From: metagen
FindColorsTolerance is less accurate them the for loops. My function is perfectly accurate :p which is why it takes so long


What do you mean it's less accurate? It finds every single point…in Milliseconds.

n3ss3s

2008-04-16 12:49:47

Hermpie, mind scrolling down to the function that returns all the HPs on the mainscreen? -.-