SRL Archive - OSR Help

How would I make the script check the health bar?


Twinki

2013-04-26 18:57:48

I'd like to make my script check my health bar / HP by the minimap and when it get's too low and it starts blinking red i'd like it to eat some food. I already have the DTM setup for the food and everything, i'm just confused on how it'd grab the HP. I've tried FindColorTolerance but it doesn't find it lol.

This is on a RSPS.. but it's a 714 and the graphics and uptext are pretty much the exact same as current EoC.

Code:

procedure EatFood;
var
X, Y, RockTail :Integer;
begin
if FindColorTolerance(X, Y, 255, 725, 32, 743, 47, 5) then //made it check the HP orb by the minimap and when it turns red it's supposed to eat food.
begin
if FindDTM(RockTail, x, y, 885, 228, 1068, 466) then
begin
MMouse(x, y, 0, 0);
ClickMouse2(True);
WriteLn('Eating Rocktail...');
end;
end;
end;

Chris!

2013-04-26 19:04:05

You can use GetMMLevels.

Here's the snippet from gametab.simba:

(*
GetMMLevels
~~~~~~~~~~~

.. code-block:: pascal

Function GetMMLevels(LevelType : String;var ColorSign : String): integer;

Returns the level shown next to the minimap.
Colorsign returns the color of the text (Green,Yellow,Orange,Red).
Returns -1 if failed.

.. note::

by Raymond / Wizzup / Sabzi / NCDS

Example:

.. code-block:: pascal

Value := GetMMLevels( 'hp' ) ; // Will retrieve your Hit Points
Value := GetMMLevels( 'pray' ) ; // Will retrieve your Prayer Points
Value := GetMMLevels( 'run' ) ; // Will retrieve your Run energy
Value := GetMMLevels( 'summon' ) ; // Will retrieve your Summoning Points

*)
function GetMMLevels(LevelType: string; var ColorSign: string): Integer;
var
Colors : TIntegerArray;
Signs: TStringArray;
P: TPointArray;
I: Integer;
B: TBox;
begin;
Result := -1;
ColorSign := '';
case LowerCase(Leveltype) of
'health', 'hp', 'hitpoints', 'constitution': B := IntToBox(719,27,745,43);
'prayer', 'pray' : B := IntToBox(735,66,762,82);
'run','energy' : B := IntToBox(735,103,762,122);
'summon', 'summoning' : B := IntToBox(719,119,745,156);
else
begin;
srl_Warn('GetMMLevels', 'Invalid LevelType: ''' + LevelType + '', warn_AllVersions);
Exit;
end;
end;
Colors := [65280, 65535, 2070783, 255];
Signs := ['Green', 'Yellow', 'Orange', 'Red'];
for I := 0 to 3 do
begin
With B do
FindColorsTolerance(P, Colors[i], x1, y1, x2, y2, 30);
if Length(P) < 1 then
Continue;
Result := StrToIntDef(GetNumbers(GetTextAtExWrap(B.X1, B.Y1, B.X2, B.Y2, 0, 4, 4, Colors[i], 20, statChars)), -1);
if (Result > -1) then
begin
ColorSign := Signs[i];
Exit;
end;
end;
end;

Good luck.

Twinki

2013-04-26 19:11:40

From: Chris!
You can use GetMMLevels.

Here's the snippet from gametab.simba:

(*
GetMMLevels
~~~~~~~~~~~

.. code-block:: pascal

Function GetMMLevels(LevelType : String;var ColorSign : String): integer;

Returns the level shown next to the minimap.
Colorsign returns the color of the text (Green,Yellow,Orange,Red).
Returns -1 if failed.

.. note::

by Raymond / Wizzup / Sabzi / NCDS

Example:

.. code-block:: pascal

Value := GetMMLevels( 'hp' ) ; // Will retrieve your Hit Points
Value := GetMMLevels( 'pray' ) ; // Will retrieve your Prayer Points
Value := GetMMLevels( 'run' ) ; // Will retrieve your Run energy
Value := GetMMLevels( 'summon' ) ; // Will retrieve your Summoning Points

*)
function GetMMLevels(LevelType: string; var ColorSign: string): Integer;
var
Colors : TIntegerArray;
Signs: TStringArray;
P: TPointArray;
I: Integer;
B: TBox;
begin;
Result := -1;
ColorSign := '';
case LowerCase(Leveltype) of
'health', 'hp', 'hitpoints', 'constitution': B := IntToBox(719,27,745,43);
'prayer', 'pray' : B := IntToBox(735,66,762,82);
'run','energy' : B := IntToBox(735,103,762,122);
'summon', 'summoning' : B := IntToBox(719,119,745,156);
else
begin;
srl_Warn('GetMMLevels', 'Invalid LevelType: ''' + LevelType + '', warn_AllVersions);
Exit;
end;
end;
Colors := [65280, 65535, 2070783, 255];
Signs := ['Green', 'Yellow', 'Orange', 'Red'];
for I := 0 to 3 do
begin
With B do
FindColorsTolerance(P, Colors[i], x1, y1, x2, y2, 30);
if Length(P) < 1 then
Continue;
Result := StrToIntDef(GetNumbers(GetTextAtExWrap(B.X1, B.Y1, B.X2, B.Y2, 0, 4, 4, Colors[i], 20, statChars)), -1);
if (Result > -1) then
begin
ColorSign := Signs[i];
Exit;
end;
end;
end;

Good luck.


Is there any way you can provide me with an example?

Chris!

2013-04-26 19:20:58

Here's an example from Ashaman's LRC miner.

If ((HPLevel < (HP*10*0.65))) Then  //HPLevel is a procedure he made. It utilises GetMMLevels.
Begin
If HPLevel=-1 Then
Exit;
If Debug Then
Writeln('HP LOW '+ToStr(HPLevel)+' RUNNING AWAY');
If Debug Then
Writeln('HP Threshold '+ToStr((HP*10*0.65)));

Oh, I also found another thing:

(*
HPPercent
~~~~~~~~~

.. code-block:: pascal

function HpPercent: Integer;

Returns Hp left as a percentage.
Does not switch tabs if Players[CurrentPlayer].Level[SKILL_HITPOINTS] (HP level) is set.
Returns -1 if failed.

.. note::

by Wizzup?

Example:

.. code-block:: pascal
*)
function HPPercent: Integer;
var
ColorString: string;
begin
if (Players[CurrentPlayer].Level[SKILL_HITPOINTS] < 1) then
Players[CurrentPlayer].Level[SKILL_HITPOINTS] := Max(1, GetSkillInfo('hitpoints', False));

if (Players[CurrentPlayer].Level[SKILL_HITPOINTS] > 1) then
Result := Round(GetMMLevels('hp', ColorString) * 10 / Players[CurrentPlayer].Level[SKILL_HITPOINTS])
else
Result := -1;
end;

So you could something like:

procedure EatFood;
var
X, Y, RockTail :Integer;
begin
//if FindColorTolerance(X, Y, 255, 725, 32, 743, 47, 5) then //made it check the HP orb by the minimap and when it turns red it's supposed to eat food.
if (HPPercent < 20) then
begin
if FindDTM(RockTail, x, y, 885, 228, 1068, 466) then
begin
MMouse(x, y, 0, 0);
ClickMouse2(True);
WriteLn('Eating Rocktail...');
end;
end;
end;

Not entirely sure that will work, but give it a shot. And I'm not familiar with GetMMLevels so I can't aid you further with that.

rj

2013-04-26 19:24:00

Write a function that will look for the red HP on the minimap such as:


function LowHP: Boolean;
Var
X,Y:Integer;
begin
Result := FindColorTolerance(X, Y, COLOR, X1, Y1, X2, Y2, TOLERANCE)
end;

So your procedure would look like:

procedure EatFood;
var
X, Y, RockTail :Integer;
begin
//if FindColorTolerance(X, Y, 255, 725, 32, 743, 47, 5) then //made it check the HP orb by the minimap and when it turns red it's supposed to eat food.
if (LowHP) then
begin
if FindDTM(RockTail, x, y, 885, 228, 1068, 466) then
begin
MMouse(x, y, 0, 0);
ClickMouse2(True);
WriteLn('Eating Rocktail...');
end;
end;
end;

Twinki

2013-04-26 19:30:53

From: Chris!
Here's an example from Ashaman's LRC miner.

If ((HPLevel < (HP*10*0.65))) Then  //HPLevel is a procedure he made. It utilises GetMMLevels.
Begin
If HPLevel=-1 Then
Exit;
If Debug Then
Writeln('HP LOW '+ToStr(HPLevel)+' RUNNING AWAY');
If Debug Then
Writeln('HP Threshold '+ToStr((HP*10*0.65)));

Oh, I also found another thing:

(*
HPPercent
~~~~~~~~~

.. code-block:: pascal

function HpPercent: Integer;

Returns Hp left as a percentage.
Does not switch tabs if Players[CurrentPlayer].Level[SKILL_HITPOINTS] (HP level) is set.
Returns -1 if failed.

.. note::

by Wizzup?

Example:

.. code-block:: pascal
*)
function HPPercent: Integer;
var
ColorString: string;
begin
if (Players[CurrentPlayer].Level[SKILL_HITPOINTS] < 1) then
Players[CurrentPlayer].Level[SKILL_HITPOINTS] := Max(1, GetSkillInfo('hitpoints', False));

if (Players[CurrentPlayer].Level[SKILL_HITPOINTS] > 1) then
Result := Round(GetMMLevels('hp', ColorString) * 10 / Players[CurrentPlayer].Level[SKILL_HITPOINTS])
else
Result := -1;
end;

So you could something like:

procedure EatFood;
var
X, Y, RockTail :Integer;
begin
//if FindColorTolerance(X, Y, 255, 725, 32, 743, 47, 5) then //made it check the HP orb by the minimap and when it turns red it's supposed to eat food.
if (HPPercent < 20) then
begin
if FindDTM(RockTail, x, y, 885, 228, 1068, 466) then
begin
MMouse(x, y, 0, 0);
ClickMouse2(True);
WriteLn('Eating Rocktail...');
end;
end;
end;

Not entirely sure that will work, but give it a shot. And I'm not familiar with GetMMLevels so I can't aid you further with that.


Yeah not working :(

Also on this PS the HP level doesn't go down when you get hit. So let's say you have 99/99 HP. You get hit like 100, it'd stay at 99/99. If that's where HPPercent is grabbing it from in the skilltab.

Chris!

2013-04-26 19:32:04

From: Twinki
Yeah not working :(

Also on this PS the HP level doesn't go down when you get hit. So let's say you have 99/99 HP. You get hit like 100, it'd stay at 99/99. If that's where HPPercent is grabbing it from in the skilltab.


Does it flash red when it's low? If it does, do what Officer Barbrady said. :)

Sjoe

2013-04-26 19:37:53

From: Twinki
Yeah not working :(

Also on this PS the HP level doesn't go down when you get hit. So let's say you have 99/99 HP. You get hit like 100, it'd stay at 99/99. If that's where HPPercent is grabbing it from in the skilltab.


It Grabs the numbers from your HP bar next to the minimap, not gametab.

Twinki

2013-04-26 19:48:44

I got it to find if my HP is in red now, but i't doesn't seem to be finding the DTM :(



procedure EatFood;
var
X, Y, RockTail :Integer;
begin
if (LowHP) then
begin
if FindDTM(RockTail, x, y, 553, 206, 729, 457) then
begin
MMouse(x, y, 0, 0);
ClickMouse2(True);
WriteLn('Eating Rocktail...');
end;
end;
end;

Twinki

2013-04-26 21:27:19

Got it working, thanks guys :)