SRL Archive - Research & Development Lounge

GetHPPercent


YoHoJo

2007-07-13 21:03:54

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('78DA63CC6262602861644001FF21144C94B11' +
'DA8A682119B12543525F8D500005EFA05E5');
HPTL[1] := DTMFromString('78DA63CC6262602861644001FF21144C94B11' +
'DA8A682083504CC01005CFC05E5');
HPBR[0]:= DTMFromString('78DA63F46562600860644006FFA1344C94D10' +
'0530D4C118A1A1FFC6A00100A04A6');
HPBR[1]:= DTMFromString('78DA63F46562600860644001FF21144C94D18' +
'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,HPX2,HPY2,0) Else
FindColorsSpiralTolerance(x,y,HP,255,HPX1,HPY1,HPX2,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

Esteban

2007-07-13 21:14:33

Maybe add a part where it takes that remaining percent HP, multiply that by the total hp to give a HP in points instead of percent.

Here

2007-07-13 21:15:55

I would like it if real humans could count THEIR life bars by pixels.

That would be really fun. Walk up to some unsuspecting low-life:

"HAHAHAH, I SEE THAT YOU HAVE ONLY 3 PIXELS! GET A LIFE!"

Otherwise, this is really great. It can probably further running from fights efficiently.

EDIT@Esteban: Yes, but we would have to go to the skills tab for the total. Which kind of defeats the purpose.

POSTEDIT: Yohojo, you spelled percent wrong in the topic. Just thought you should know.

YoHoJo

2007-07-13 21:34:01

From: Esteban
Maybe add a part where it takes that remaining percent HP, multiply that by the total hp to give a HP in points instead of percent.


To get the total HP you have to open a gametab though =/
The point of this was to get all information from the mainscreen only, but thats a good idea.

@Here, Thanks =) and i fixed the spelling mistake.

Esteban

2007-07-13 21:41:36

well it's not like it uncommon for somebody to open up the skills tab :P? Not like you're going to have to continue to get the users hp level every few minutes, just open the skills tab once, get the hp level, and you never have to look at the skills tab again ;) (unless you up a hp level).

But yea, if you want to do EVERYTHING from only the Main screen, this won't work.

BobboHobbo

2007-07-13 21:43:55

Does it mess up if someones elses HP Bar thing shows up?

bullzeye95

2007-07-13 21:57:43

Unfortunately it does if there are a lot of bars around :(. I tried it in the goblin house and it kept picking others up.
But if I'm not in a crowded area, it works great. Good job.

YoHoJo

2007-07-13 22:27:08

From: bobbohobbo
Does it mess up if someones elses HP Bar thing shows up?


Well it still does work if there are other people around, just not if its extremely crouded like the goblin house.
I guess ill go test it there and try to fix that up.
It tires to get the centermost HP box, but i still messes up.

Maybe perfectnorth and highestangle procedures will help with that though.

Here

2007-07-13 22:34:22

Also, do HP bars overlap? If they do, that might affect it. If they don't just ignore me.

Esteban

2007-07-13 22:44:45

Does anyone know if there is a getexp procedure? I'd like to for my own scripting reasons modify this to the way i described. I'd use (if there is) something like GetExp(HP); use that for ConvertXpToLevel, then modify GetHPPercent to convert the percentage into a actual hitpoint number.

shaunthasheep

2007-07-14 00:25:11

hp bars w/h are always the same? you just have to find one corner of it
EDIT: nvm^^.. nice function, i'd like to see it perfected :P

itSchRis917

2007-07-14 00:28:36

You could just use GetSkillLevel('Hitpoints') for that Esteban. There's no reason to GetExp('hp') and then use ConvertExpToLvl..

YoHoJo

2007-07-14 00:31:00

Yea, esteban:

{*******************************************************************************
function HpPercent: Integer;
By: RsN
Description: Returns Hp left as a percentage
*******************************************************************************}

function HpPercent: Integer;
var
tlevel, tamount: Integer;
begin
tlevel := GetSkillLevel('hitpoints');
tamount := GetSkillAmount('hitpoints');
if tlevel = 0 then tlevel := 1;
Result := (tamount * 100) / tlevel;
end;

Haxor

2007-07-14 03:18:11

looks cool. could me a major antiban(not opening stats all the time.

haxor

BobboHobbo

2007-07-14 04:41:31

Hmm isnt the HP bar thing always in the middle of the screen? because if it is then it wouldnt mess up?

EDIT**
Opps i didnt see your whole post Yojo :( dang.

Dan Cardin

2007-07-14 15:21:25

well could u add a failsafe to make sure that its ur hp bar, and wait for u to get hit , then if the damage(i think wizzup? has 1 that checks for damage) takes away a number of pixels equal to the number of pixels you should have, then it's yours(then wouldnt u be able to keep track of it if it happened to move again?).

YoHoJo

2007-07-14 22:55:55

@Dan.
There is a failsafe that makes sure you are in a fight, just not one that makes sure that its getting stats from your HP bar.

  If (FindColor(x, y, 65280, 230, 130, 280, 180) or
FindColor(x, y, 255,230, 130, 280, 180)) Then
Is SRL's infight function.
It checks for that first, and then does the rest.

Dan Cardin

2007-07-15 10:33:14

i know…but what if you are in a fight, and someone else is in a fight right under you?then it might detect the other hp bar

YoHoJo

2007-07-15 13:24:11

Yea iv already said above it works if its not too crowded and im working on fixing that.

Here

2007-07-15 13:41:01

Well, one thing is, I'm sure whoever is monitoring you will NOT care at all if you open your skills tab once, twice, or even three times during a fight. What you can do is to match percents with the numbers in your skills tab, and if it's not correct, then to search for the correct one. It should only need to match twice, as it's quite unlikely that two people would be damaged the same way or have the same percent of health left.

Dan Cardin

2007-07-15 13:45:05

thats what i was saying(as a solution to the problem not to point the problem out YoHoJo) except u dont have to go t the tabs(except at the beginning of the script to check the hp lvl)

you would get the damage u took, and turn it into a percentage and see if the percentage-100 is equal to what you got on the hp bar

Here

2007-07-15 15:11:01

Basically.