Simba Code:
program GetHPPercent;
{$I SRL/SRL.simba}
{$I SRL/SRL/misc/Debug.simba}
procedure SetBoxToBounds(var Box : TBox; X1,Y1,X2,Y2 : Integer);
begin
if (Box.x1 < X1) then Box.x1 := X1;
if (Box.x2 > X2) then Box.x2 := X2;
if (Box.y1 < Y1) then Box.y1 := Y1;
if (Box.y2 > Y2) then Box.y2 := Y2;
end;
procedure DebugTPA_ATPA(TPA: TPointArray; ATPA: Array of TPointArray; First : Integer);
var
BMP, Col, x, y, i, width, height: Integer;
TPABox : TBox;
begin
GetClientDimensions(width,height);
BMP := BitmapFromClient(0,0,width-1,height-1);
DrawTPABitmap(BMP,TPA,ClWhite);
for i:=0 to High(ATPA) do
begin
if i = First then
Col := ClRed
else
Col := ClPurple;
TPABox := GetTPABounds(ATPA[i]);
SetBoxToBounds(TPABox,0,0,width-1,height-1);
for x := TPABox.x1 to TPABox.x2 do
begin
FastSetPixel(BMP,x,TPABox.y1,Col)
FastSetPixel(BMP,x,TPABox.y2,Col)
end;
for y := TPABox.y1 to TPABox.y2 do
begin
FastSetPixel(BMP,TPABox.x1,y,Col)
FastSetPixel(BMP,TPABox.x2,y,Col)
end;
end;
TPABox := IntToBox(223,127,295,175);
for x := TPABox.x1 to TPABox.x2 do
begin
FastSetPixel(BMP,x,TPABox.y1,Col)
FastSetPixel(BMP,x,TPABox.y2,Col)
end;
for y := TPABox.y1 to TPABox.y2 do
begin
FastSetPixel(BMP,TPABox.x1,y,Col)
FastSetPixel(BMP,TPABox.x2,y,Col)
end;
DebugBitmap(BMP);
FreeBitmap(BMP);
end;
function GetHpPercent : Integer;
var
CombinedTPA, GreenTPA, RedTPA : TPointArray;
CombinedATPA, GreenATPA, FinalATPA : Array of TPointArray;
X1,Y1,X2,Y2, i,j,k, BoxWidth,BoxHeight : Integer;
ExcludeBoxes : Array of TBox;
TempBox : TBox;
BadTPA : Boolean;
begin
Result := -1;
X1 := 223;
Y1 := 127;
X2 := 295;
Y2 := 175;
FindColorsTolerance(GreenTPA,65280,X1,Y1,X2,Y2,0);
FindColorsTolerance(RedTPA,255,X1,Y1,X2,Y2,0);
CombinedTPA := CombineTPA(GreenTPA,RedTPA);
if (High(CombinedTPA) > 0) then
begin
SplitTPAWrap(CombinedTPA,1,CombinedATPA);
SetArrayLength(ExcludeBoxes,0);
j := -1;
for i:=0 to High(CombinedATPA) do
begin
TempBox := GetTPABounds(CombinedATPA[i]);
BoxWidth := TempBox.x2-TempBox.x1;
BoxHeight := TempBox.y2-TempBox.y1;
if not (BoxWidth = 29) or not (BoxHeight = 4) then
begin
Inc(j);
SetArrayLength(ExcludeBoxes,j+1);
ExcludeBoxes[j] := TempBox;
end;
end;
SplitTPAWrap(GreenTPA,1,GreenATPA);
SetArrayLength(FinalATPA,0);
k := 0;
for i:=0 to High(GreenATPA) do
begin
BadTPA := False;
for j:=0 to High(ExcludeBoxes) do
if PointInBox(MiddleTPA(GreenATPA[i]),ExcludeBoxes[j]) then
BadTPA := True;
if not BadTPA then
begin
SetArrayLength(FinalATPA,k+1);
FinalATPA[k] := GreenATPA[i];
end;
end;
SortATPAFrom(FinalATPA,Point(MSCX,MSCY));
DebugTPA_ATPA(GreenTPA,FinalATPA,-1);
if (Length(FinalATPA) < 1) then Exit;
TempBox := GetTPABounds(FinalATPA[0]);
BoxWidth := TempBox.x2-TempBox.x1;
Result := Round(BoxWidth*100/29);
end;
end;
var
HPLevel, HPPerc, HP : integer;
begin
ClearDebug;
HPLevel := 59;
repeat
HPPerc := GetHPPercent;
ClearDebug;
if not (HPPerc = -1) then
begin
HP := Round(HPLevel*HPPerc/100)
Writeln('HP: ' + IntToStr(HP));
if HP < 30 then
PlaySound('C:/Simba/sound2.wav');
end;
Wait(100);
until False;
end.