YoHoJo
07-14-2007, 01:03 AM
I saw a help thread in SRL Help asking for a function that gets HP without having to constantly open the skills tab because it seems detectable.
Well, after working on it for a while i came up with GetHPPercent.
It detects if you are in a fight, if true, it then gets the corner points of the HP box above your head and then calcs the number of green pixel in the HP bar, puts it over 150 and multiples my 100.
Giving you the percentage of HP you have left, without opening the skills gametab.
One thing that can be a bit more improved is the box coordiantes of the corner finder, but except for that it works well =).
program New;
{.include SRL/SRL.scar}
Var
HP:TpointArray;
HPX1,HPY1,HPX2,HPY2,I:Integer;
HPTL,HPBR: array[0..1] of Integer;
Procedure Load;
Begin
HPTL[0] := DTMFromString('78DA63CC6262602861644001FF21144C94B 11' +
'DA8A682119B12543525F8D500005EFA05E5');
HPTL[1] := DTMFromString('78DA63CC6262602861644001FF21144C94B 11' +
'DA8A682083504CC01005CFC05E5');
HPBR[0]:= DTMFromString('78DA63F46562600860644006FFA1344C94D 10' +
'0530D4C118A1A1FFC6A00100A04A6');
HPBR[1]:= DTMFromString('78DA63F46562600860644001FF21144C94D 18' +
'048353EF8D500000F0B04A6');
End;
Procedure GetHPCorners;
Begin
For I:=0 To 1 Do
Begin
X:=MSCX;
Y:=MSCY;
If FindDTM(HPTL[I],x,y,MSCX-40,MSCY-40,MSCX+40,MSCY+40) Then
Begin
HPX1:=X;
HPY1:=Y;
// Writeln(IntToStr(HPX1)+','+IntToStr(HPY1))
Break;
End;
End;
For I:=0 To 1 Do
Begin
X:=MSCX;
Y:=MSCY;
If FindDTM(HPBR[I],x,y,MSCX-40,MSCY-40,MSCX+40,MSCY+40) Then
Begin
HPX2:=X;
HPY2:=Y;
// Writeln(IntToStr(HPX2)+','+IntToStr(HPY2))
Break;
End;
End;
End;
Function FindHPPercent(Green:Boolean):Integer;
Begin
If (FindColor(x, y, 65280, 230, 130, 280, 180) or
FindColor(x, y, 255,230, 130, 280, 180)) Then
Begin
If Green Then
FindColorsSpiralTolerance(x,y,HP,65280,HPX1,HPY1,H PX2,HPY2,0) Else
FindColorsSpiralTolerance(x,y,HP,255,HPX1,HPY1,HPX 2,HPY2,5);
Result:=Round( ( (GetArrayLength(HP)/150.0)*100.0));
Writeln('There Are '+IntToStr(GetArrayLength(HP))+' Green HP Pixels');
Writeln('You Have ' + IntToStr(Result)+' % HP Remaining');
End;
End;
begin
SetupSRL;
Load;
GetHPCorners;
FindHPPercent(True);
end.
Here are some test results:
There Are 125 Green HP Pixels
You Have 83 % HP Remaining
There Are 24 Green HP Pixels
You Have 16 % HP Remaining
There Are 60 Green HP Pixels
You Have 40 % HP Remaining
There Are 65 Green HP Pixels
You Have 43 % HP Remaining
Please test and give feedback and tell of any improvements you see that can be made.
Thanks to whiteshadow for showing me FindColorsSpiral a long time ago, its one of my favorite functions :p.
Thanks,
Yohojo
Well, after working on it for a while i came up with GetHPPercent.
It detects if you are in a fight, if true, it then gets the corner points of the HP box above your head and then calcs the number of green pixel in the HP bar, puts it over 150 and multiples my 100.
Giving you the percentage of HP you have left, without opening the skills gametab.
One thing that can be a bit more improved is the box coordiantes of the corner finder, but except for that it works well =).
program New;
{.include SRL/SRL.scar}
Var
HP:TpointArray;
HPX1,HPY1,HPX2,HPY2,I:Integer;
HPTL,HPBR: array[0..1] of Integer;
Procedure Load;
Begin
HPTL[0] := DTMFromString('78DA63CC6262602861644001FF21144C94B 11' +
'DA8A682119B12543525F8D500005EFA05E5');
HPTL[1] := DTMFromString('78DA63CC6262602861644001FF21144C94B 11' +
'DA8A682083504CC01005CFC05E5');
HPBR[0]:= DTMFromString('78DA63F46562600860644006FFA1344C94D 10' +
'0530D4C118A1A1FFC6A00100A04A6');
HPBR[1]:= DTMFromString('78DA63F46562600860644001FF21144C94D 18' +
'048353EF8D500000F0B04A6');
End;
Procedure GetHPCorners;
Begin
For I:=0 To 1 Do
Begin
X:=MSCX;
Y:=MSCY;
If FindDTM(HPTL[I],x,y,MSCX-40,MSCY-40,MSCX+40,MSCY+40) Then
Begin
HPX1:=X;
HPY1:=Y;
// Writeln(IntToStr(HPX1)+','+IntToStr(HPY1))
Break;
End;
End;
For I:=0 To 1 Do
Begin
X:=MSCX;
Y:=MSCY;
If FindDTM(HPBR[I],x,y,MSCX-40,MSCY-40,MSCX+40,MSCY+40) Then
Begin
HPX2:=X;
HPY2:=Y;
// Writeln(IntToStr(HPX2)+','+IntToStr(HPY2))
Break;
End;
End;
End;
Function FindHPPercent(Green:Boolean):Integer;
Begin
If (FindColor(x, y, 65280, 230, 130, 280, 180) or
FindColor(x, y, 255,230, 130, 280, 180)) Then
Begin
If Green Then
FindColorsSpiralTolerance(x,y,HP,65280,HPX1,HPY1,H PX2,HPY2,0) Else
FindColorsSpiralTolerance(x,y,HP,255,HPX1,HPY1,HPX 2,HPY2,5);
Result:=Round( ( (GetArrayLength(HP)/150.0)*100.0));
Writeln('There Are '+IntToStr(GetArrayLength(HP))+' Green HP Pixels');
Writeln('You Have ' + IntToStr(Result)+' % HP Remaining');
End;
End;
begin
SetupSRL;
Load;
GetHPCorners;
FindHPPercent(True);
end.
Here are some test results:
There Are 125 Green HP Pixels
You Have 83 % HP Remaining
There Are 24 Green HP Pixels
You Have 16 % HP Remaining
There Are 60 Green HP Pixels
You Have 40 % HP Remaining
There Are 65 Green HP Pixels
You Have 43 % HP Remaining
Please test and give feedback and tell of any improvements you see that can be made.
Thanks to whiteshadow for showing me FindColorsSpiral a long time ago, its one of my favorite functions :p.
Thanks,
Yohojo