SRL Archive - OSR Help

Finding HP Bars


YoHoJo

2011-11-20 18:52:45

Anyone have a premade function(boolean) that results true if any HP bars are found on the screen?

The one in SRL doesn't work for right before the enemy dies and the HP bar is all red, I need one that accounts for that.

DeSnob

2011-11-20 19:17:46

I'm gonna make a simple bitmap searching function for my own script in a sec, I'll share with ya when I'm done.

Coh3n

2011-11-20 19:37:15

Fix the SRL one so it takes it into account?

DeSnob

2011-11-20 19:38:34

Here:
Function HPExists: Boolean;
var
HP: integer;
begin
HP := BitmapFromString(56, 1, 'meJxjYrdmYMhhYGgCIkaGLgw0iZl' +
'hFjJiYVgIR6wMq+CIg2EjDO3EhTgZDgARhIFHGQZazcRuDQB2WiWA');
Result := FindBitmap(HP, x, y);
end;

mormonman

2011-11-20 19:41:54

The green outline and red outline are both constant colors. Just do a tpa search.

I use this to find if they are dead(TPoint of the middle of the tracked npc).
function FindDeath(P: TPoint): Boolean;
var
TPA: TPointArray;
ATPA: T2DPointArray;
B, tB: TBox;
Len, i, Dist: Integer;
begin
Result := False;
if not LoggedIn then Exit;
B := IntToBox(P.x - 45, P.y - 55, P.x + 45, P.y + 20);
if (B.X1 < MSX1) then B.X1 := MSX1;
if (B.Y1 < MSY1) then B.Y1 := MSY1;
if (B.X2 > MSX2) then B.X2 := MSX2;
if (B.Y2 > MSY2) then B.Y2 := MSY2;
if FindColorsSpiralTolerance(MSCX, MSCY, TPA, 132923, B.X1, B.Y1, B.X2, B.Y2, 0) then
begin
ATPA := SplitTPA(TPA, 10);
SortATPASize(ATPA, True);
if not (Length(ATPA) > 0) then Exit;

for i := 0 to High(ATPA) do
begin
Len := Length(ATPA[i]);
if (Len > 0) then
begin
tB := GetTPABounds(ATPA[i]);
Dist := Distance(tB.X1, tB.Y1, tB.X2, tB.Y2);
m_Debug('HP bar dist: ' + ToStr(Dist), False);
Result := (Dist > 54);
if Result then
begin
if Debug then
begin
SMART_DrawBoxEx(False, B, clBlue);
SMART_DrawBoxEx(False, GetTPABounds(ATPA[i]), clWhite);
end;
Exit;
end;
end;
end;
end;
end;

YoHoJo

2011-11-20 20:45:17

@Marpis, thanks.

@Cohen yeah I would, now that I know that green/red of HP are constant I'll maybe make one. I don't feel like I'd make it as 'perfect' as a more able scripter even though it's easy to do.

YoHoJo

2011-11-20 20:59:50

Function YoHoIsFightAt: Boolean;
var
arP: TPointArray;
tmpCTS: Integer;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(5.33, 1.31);

FindColorsSpiralTolerance(MMCX, MMCY, arP, 78384, MSX1, MSY1, MSX2, MSY2, 3);

WriteLn(Length(Arp));
If Length(arP) > 30 Then
Result:=True;
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

End;

That works. Just find ANY HP bars on the mainscreen.

SetColorSpeed2Modifiers(5.33, 1.31);

FindColorsSpiralTolerance(MMCX, MMCY, arP, 78384, MSX1, MSY1, MSX2, MSY2, 3);

Is the main part that just fins the HP bar colors. Edit/use it however you wish.

mormonman

2011-11-21 03:04:15

You really really really don't need to do that. I'm going to revamp my procedure tomorrow to find HPPercent instead of just checking for the length(this will include finding the green outline as well, plus a better splitting of the tpa). I'll post it here when i'm done.

Main

2011-11-21 03:31:03

Am not sure what you need it for, but I had a function that will check if an player/monster that is in fight by checking if an hp bar is within certain range (varies depends on its location on rs screen as well!).