Pentti
07-14-2007, 10:12 AM
Just made these today, and worked pretty good for me, takes about 100milliseconds to find hp bar + calcute the hp left. (No lag, no game tab) :D
Function HPBoxCanvas:TCanvas;
Function GetTopLeft(Canvas:TCanvas):TPoint;
Function GetBottomRight(Canvas:TCanvas):TPoint;
Function GetHPBarPoints:TBox;
Function HPLeft:Extended;
Please post comments!
Const ShowdaGoddamnDecimalsYesOrNoYouDecide=True;
Function HPBoxCanvas:TCanvas;
var
TempBmp:Integer;
begin
TempBmp:=BitMapFromString(0,0,'');
CopyClientToBitmap(TempBmp,240,145,285,173)
Result:=GetBitMapCanvas(TempBmp);
end;
Function GetTopLeft(Canvas:TCanvas):TPoint;
var
xx,yy:Integer;
begin
For xx:=0 to 45 do
For yy:=0 to 28 do
If(Canvas.Pixels[xx,yy]=65280)Then
begin
Result.X:=xx;
Result.Y:=yy;
Exit;
end;
end;
Function GetBottomRight(Canvas:TCanvas):TPoint;
var
xx,yy:Integer;
begin
For yy:=45 downto 0 do
For xx:=28 downto 0 do
If(Canvas.Pixels[xx,yy]=65280)or(Canvas.Pixels[xx,yy]=255)Then
begin
Result.X:=xx;
Result.Y:=yy;
Exit;
end;
end;
var
x,y:integer;
Function GetHPBarPoints:TBox;
var
TempBR,TempTL:TPoint;
DaBmpCanva:TCanvas;
begin
if(Not(FindColor(x,y,255,240,145,285,173)))then
Exit;
DaBmpCanva:=HPBoxCanvas;
TempTL:=GetTopLeft(DaBmpCanva);
TempBR:=GetBottomRight(DaBmpCanva);
if(TempTL.X+2<TempBR.X)then
begin
Result.X1:=TempTL.X;
Result.Y1:=TempTL.Y;
Result.X2:=TempBR.X;
Result.Y2:=TempBR.Y;
Writeln('X: ('+Inttostr(TempTL.X+240)+','+inttostr(TempBR.X+28 5)+')')
Writeln('Y: ('+Inttostr(TempTL.Y+145)+','+inttostr(TempBR.Y+17 3)+')')
Writeln('HP bar size (X*Y)='+inttostr( (TempBR.Y-TempTL.Y)*(TempBR.X-TempTL.X) )+' X('+inttostr(TempTL.X)+','+inttostr(TempBR.X)+') Y('+inttostr(TempTL.Y)+','+inttostr(TempBR.Y)+')')
end;
end;
Function HPLeft:Extended;
var
TempBR,TempTL:TPoint;
DaBmpCanva:TCanvas;
xx,yy:Integer;
HPBarLength:Integer;
begin
if(Not(FindColor(x,y,255,240,145,285,173)))then
Exit;
DaBmpCanva:=HPBoxCanvas;
TempTL:=GetTopLeft(DaBmpCanva);
TempBR:=GetBottomRight(DaBmpCanva);
HPBarLength:=TempBR.X - TempTL.X
yy:=TempTL.Y+3;
For xx:=TempBR.X downto TempTL.X do
If(DaBmpCanva.Pixels[xx,yy]=65280)Then
begin
Result:=((xx-TempTL.X) / HPBarLength)*100;
Exit;
end;
end;
var
Timer:integer;
begin
Repeat
ClearDebug;
Timer:=GetsystemTime;
GetHPBarPoints;
Writeln('HP bar points took: '+inttostr(GetsystemTime-Timer)+'ms')
wait(500)
Timer:=GetsystemTime;
if ShowdaGoddamnDecimalsYesOrNoYouDecide then
Writeln(FloatToStr(HPLeft)+'% HP left') else
Writeln(IntToStr(Round(HPLeft))+'% HP left')
Writeln('Hp left + points took: '+inttostr(GetsystemTime-Timer)+'ms')
wait(1000)
until(False)
end.
Function HPBoxCanvas:TCanvas;
Function GetTopLeft(Canvas:TCanvas):TPoint;
Function GetBottomRight(Canvas:TCanvas):TPoint;
Function GetHPBarPoints:TBox;
Function HPLeft:Extended;
Please post comments!
Const ShowdaGoddamnDecimalsYesOrNoYouDecide=True;
Function HPBoxCanvas:TCanvas;
var
TempBmp:Integer;
begin
TempBmp:=BitMapFromString(0,0,'');
CopyClientToBitmap(TempBmp,240,145,285,173)
Result:=GetBitMapCanvas(TempBmp);
end;
Function GetTopLeft(Canvas:TCanvas):TPoint;
var
xx,yy:Integer;
begin
For xx:=0 to 45 do
For yy:=0 to 28 do
If(Canvas.Pixels[xx,yy]=65280)Then
begin
Result.X:=xx;
Result.Y:=yy;
Exit;
end;
end;
Function GetBottomRight(Canvas:TCanvas):TPoint;
var
xx,yy:Integer;
begin
For yy:=45 downto 0 do
For xx:=28 downto 0 do
If(Canvas.Pixels[xx,yy]=65280)or(Canvas.Pixels[xx,yy]=255)Then
begin
Result.X:=xx;
Result.Y:=yy;
Exit;
end;
end;
var
x,y:integer;
Function GetHPBarPoints:TBox;
var
TempBR,TempTL:TPoint;
DaBmpCanva:TCanvas;
begin
if(Not(FindColor(x,y,255,240,145,285,173)))then
Exit;
DaBmpCanva:=HPBoxCanvas;
TempTL:=GetTopLeft(DaBmpCanva);
TempBR:=GetBottomRight(DaBmpCanva);
if(TempTL.X+2<TempBR.X)then
begin
Result.X1:=TempTL.X;
Result.Y1:=TempTL.Y;
Result.X2:=TempBR.X;
Result.Y2:=TempBR.Y;
Writeln('X: ('+Inttostr(TempTL.X+240)+','+inttostr(TempBR.X+28 5)+')')
Writeln('Y: ('+Inttostr(TempTL.Y+145)+','+inttostr(TempBR.Y+17 3)+')')
Writeln('HP bar size (X*Y)='+inttostr( (TempBR.Y-TempTL.Y)*(TempBR.X-TempTL.X) )+' X('+inttostr(TempTL.X)+','+inttostr(TempBR.X)+') Y('+inttostr(TempTL.Y)+','+inttostr(TempBR.Y)+')')
end;
end;
Function HPLeft:Extended;
var
TempBR,TempTL:TPoint;
DaBmpCanva:TCanvas;
xx,yy:Integer;
HPBarLength:Integer;
begin
if(Not(FindColor(x,y,255,240,145,285,173)))then
Exit;
DaBmpCanva:=HPBoxCanvas;
TempTL:=GetTopLeft(DaBmpCanva);
TempBR:=GetBottomRight(DaBmpCanva);
HPBarLength:=TempBR.X - TempTL.X
yy:=TempTL.Y+3;
For xx:=TempBR.X downto TempTL.X do
If(DaBmpCanva.Pixels[xx,yy]=65280)Then
begin
Result:=((xx-TempTL.X) / HPBarLength)*100;
Exit;
end;
end;
var
Timer:integer;
begin
Repeat
ClearDebug;
Timer:=GetsystemTime;
GetHPBarPoints;
Writeln('HP bar points took: '+inttostr(GetsystemTime-Timer)+'ms')
wait(500)
Timer:=GetsystemTime;
if ShowdaGoddamnDecimalsYesOrNoYouDecide then
Writeln(FloatToStr(HPLeft)+'% HP left') else
Writeln(IntToStr(Round(HPLeft))+'% HP left')
Writeln('Hp left + points took: '+inttostr(GetsystemTime-Timer)+'ms')
wait(1000)
until(False)
end.