Results 1 to 10 of 10

Thread: How would I make the script check the health bar?

  1. #1
    Join Date
    Dec 2011
    Posts
    445
    Mentioned
    26 Post(s)
    Quoted
    256 Post(s)

    Default How would I make the script check the health orb?

    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:

    Simba 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;
    Last edited by Twinki; 04-26-2013 at 11:03 PM.

  2. #2
    Join Date
    Sep 2012
    Location
    Australia.
    Posts
    839
    Mentioned
    16 Post(s)
    Quoted
    225 Post(s)

    Default

    You can use GetMMLevels.

    Here's the snippet from gametab.simba:

    Simba Code:
    (*
    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.

  3. #3
    Join Date
    Dec 2011
    Posts
    445
    Mentioned
    26 Post(s)
    Quoted
    256 Post(s)

    Default

    Quote Originally Posted by Chris! View Post
    You can use GetMMLevels.

    Here's the snippet from gametab.simba:

    Simba Code:
    (*
    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?

  4. #4
    Join Date
    Sep 2012
    Location
    Australia.
    Posts
    839
    Mentioned
    16 Post(s)
    Quoted
    225 Post(s)

    Default

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

    Simba Code:
    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:

    Simba Code:
    (*
    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:

    Simba 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.
      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.

  5. #5
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

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


    Simba Code:
    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:

    Simba 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.
      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;

  6. #6
    Join Date
    Dec 2011
    Posts
    445
    Mentioned
    26 Post(s)
    Quoted
    256 Post(s)

    Default

    Quote Originally Posted by Chris! View Post
    Here's an example from Ashaman's LRC miner.

    Simba Code:
    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:

    Simba Code:
    (*
    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:

    Simba 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.
      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.

  7. #7
    Join Date
    Sep 2012
    Location
    Australia.
    Posts
    839
    Mentioned
    16 Post(s)
    Quoted
    225 Post(s)

    Default

    Quote Originally Posted by Twinki View Post
    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.

  8. #8
    Join Date
    Mar 2006
    Location
    Belgium
    Posts
    3,564
    Mentioned
    111 Post(s)
    Quoted
    1475 Post(s)

    Default

    Quote Originally Posted by Twinki View Post
    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.

    Creds to DannyRS for this wonderful sig!

  9. #9
    Join Date
    Dec 2011
    Posts
    445
    Mentioned
    26 Post(s)
    Quoted
    256 Post(s)

    Default

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



    Simba Code:
    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;

  10. #10
    Join Date
    Dec 2011
    Posts
    445
    Mentioned
    26 Post(s)
    Quoted
    256 Post(s)

    Default

    Got it working, thanks guys

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •