ShapeShifter
07-15-2007, 11:39 AM
Well, i thought of making my own health bar functions to find the percent of hp that you have got left. It finds the closest healthbar to your head then works out the percent. Script takes an average of 10ms.
To test it minimize it and click on a monster in runescape then press 'alt + tab' and you'll see the info in the debug every 500 ms, make sure the scar window is not in the middle where your health bar is, or else it will block the healthbar and the script won't work.
program HealthBar;//By ShapeShifter.
{.include SRL\SRL.SCAR}
var HBar:extended;
{FindStartHealthBar - Finds the green starting point of health bar}
function FindStartHealthBar(var x1,y1:integer):Boolean;
var xx,yy,XC:integer;
begin
if FindColorSpiral(xx,yy,65280,MSCx-10,MSCy-37,MSCx+10,MSCy+25) then
begin
for XC:=1 to 30 do
begin
xx:=xx-1;
if GetColor(xx,yy)<>65280 then
begin
x1:=xx+1;
y1:=yy;
Result:=True;
WriteLn('Found health bar at '+IntToStr(xx+1)+','+IntToStr(yy));
exit;
end;
end;
end;
end;
{MyGreenHealthBarPercent - Checks how much percent of hp you got left.
ONLY WORKS AT HIGHEST ANGLE}
function MyGreenHealthBarPercent(MyGHBP:extended):Boolean;
var HBx1,HBy,HBx2,HB,StartTime:integer;
WentPastEnd:boolean;
begin
MarkTime(StartTime);
if FindStartHealthBar(HBx1,HBy) then
begin
HBx2:=HBx1;
for HB:=1 to 6 do
begin
HBx2:=HBx2+5;
if GetColor(HBx2,HBy)<>65280 then
begin
WentPastEnd:=True;
break;
end;
end;
end
else
begin
WriteLn('Couldn''t find start of health bar');
exit;
end;
if WentPastEnd then
begin
for HB:=1 to 5 do
begin
HBx2:=HBx2-1;
if GetColor(HBx2,HBy)=65280 then
begin
MyGHBP:=((HBx2-(HBx1-1))/30)*100;
Result:=True;
WriteLn('Took '+IntToStr(GetSystemTime-StartTime)+' msecs');
WriteLn('Width of green pixels '+IntToStr(HBx2-(HBx1-1))+','+
FloatToStr(((HBx2-(HBx1-1))/30)*100)+' percent full');
exit;
end;
end;
WriteLn('Couldn''t find end of healthbar');
end
else
begin
WriteLn('Didn''t go past the end of the healthbar');
end;
end;
begin
SetUpSRL;
repeat
MyGreenHealthBarPercent(HBar);
wait(500);
ClearDebug;
until(false);
end.
To test it minimize it and click on a monster in runescape then press 'alt + tab' and you'll see the info in the debug every 500 ms, make sure the scar window is not in the middle where your health bar is, or else it will block the healthbar and the script won't work.
program HealthBar;//By ShapeShifter.
{.include SRL\SRL.SCAR}
var HBar:extended;
{FindStartHealthBar - Finds the green starting point of health bar}
function FindStartHealthBar(var x1,y1:integer):Boolean;
var xx,yy,XC:integer;
begin
if FindColorSpiral(xx,yy,65280,MSCx-10,MSCy-37,MSCx+10,MSCy+25) then
begin
for XC:=1 to 30 do
begin
xx:=xx-1;
if GetColor(xx,yy)<>65280 then
begin
x1:=xx+1;
y1:=yy;
Result:=True;
WriteLn('Found health bar at '+IntToStr(xx+1)+','+IntToStr(yy));
exit;
end;
end;
end;
end;
{MyGreenHealthBarPercent - Checks how much percent of hp you got left.
ONLY WORKS AT HIGHEST ANGLE}
function MyGreenHealthBarPercent(MyGHBP:extended):Boolean;
var HBx1,HBy,HBx2,HB,StartTime:integer;
WentPastEnd:boolean;
begin
MarkTime(StartTime);
if FindStartHealthBar(HBx1,HBy) then
begin
HBx2:=HBx1;
for HB:=1 to 6 do
begin
HBx2:=HBx2+5;
if GetColor(HBx2,HBy)<>65280 then
begin
WentPastEnd:=True;
break;
end;
end;
end
else
begin
WriteLn('Couldn''t find start of health bar');
exit;
end;
if WentPastEnd then
begin
for HB:=1 to 5 do
begin
HBx2:=HBx2-1;
if GetColor(HBx2,HBy)=65280 then
begin
MyGHBP:=((HBx2-(HBx1-1))/30)*100;
Result:=True;
WriteLn('Took '+IntToStr(GetSystemTime-StartTime)+' msecs');
WriteLn('Width of green pixels '+IntToStr(HBx2-(HBx1-1))+','+
FloatToStr(((HBx2-(HBx1-1))/30)*100)+' percent full');
exit;
end;
end;
WriteLn('Couldn''t find end of healthbar');
end
else
begin
WriteLn('Didn''t go past the end of the healthbar');
end;
end;
begin
SetUpSRL;
repeat
MyGreenHealthBarPercent(HBar);
wait(500);
ClearDebug;
until(false);
end.