Page 1 of 2 12 LastLast
Results 1 to 25 of 27

Thread: GetHPPercent

  1. #1
    Join Date
    Jan 2012
    Posts
    1,104
    Mentioned
    18 Post(s)
    Quoted
    211 Post(s)

    Default GetHPPercent

    This is a function I made on P06 server. Changed some coordinates and it works on 07Scape too.

    What does it do?
    Useful function for fighter scripts, checks current hp without looking at stats tab.
    Finds avatar's hp bar and calculates hp percentage of it. Camera angle must be on highest.


    Simba Code:
    program GetHPPercent;
    {$I SRL/SRL.simba}
    {$I SRL/SRL/misc/Debug.simba}



    procedure SetBoxToBounds(var Box : TBox; X1,Y1,X2,Y2 : Integer);
    begin
      if (Box.x1 < X1) then Box.x1 := X1;
      if (Box.x2 > X2) then Box.x2 := X2;
      if (Box.y1 < Y1) then Box.y1 := Y1;
      if (Box.y2 > Y2) then Box.y2 := Y2;
    end;



    procedure DebugTPA_ATPA(TPA: TPointArray; ATPA: Array of TPointArray; First : Integer);
    var
      BMP, Col, x, y, i, width, height: Integer;
      TPABox : TBox;
    begin

      GetClientDimensions(width,height);
      BMP := BitmapFromClient(0,0,width-1,height-1);
      DrawTPABitmap(BMP,TPA,ClWhite);

      for i:=0 to High(ATPA) do
      begin
        if i = First then
          Col := ClRed
        else
          Col := ClPurple;

        TPABox := GetTPABounds(ATPA[i]);
        SetBoxToBounds(TPABox,0,0,width-1,height-1);

        for x := TPABox.x1 to TPABox.x2 do
        begin
          FastSetPixel(BMP,x,TPABox.y1,Col)
          FastSetPixel(BMP,x,TPABox.y2,Col)
        end;
        for y := TPABox.y1 to TPABox.y2 do
        begin
          FastSetPixel(BMP,TPABox.x1,y,Col)
          FastSetPixel(BMP,TPABox.x2,y,Col)
        end;
      end;

      TPABox := IntToBox(223,127,295,175);
      for x := TPABox.x1 to TPABox.x2 do
      begin
        FastSetPixel(BMP,x,TPABox.y1,Col)
        FastSetPixel(BMP,x,TPABox.y2,Col)
      end;
      for y := TPABox.y1 to TPABox.y2 do
      begin
        FastSetPixel(BMP,TPABox.x1,y,Col)
        FastSetPixel(BMP,TPABox.x2,y,Col)
      end;

      DebugBitmap(BMP);
      FreeBitmap(BMP);
    end;



    function GetHpPercent : Integer;
    var
      CombinedTPA, GreenTPA, RedTPA : TPointArray;
      CombinedATPA, GreenATPA, FinalATPA : Array of TPointArray;
      X1,Y1,X2,Y2, i,j,k, BoxWidth,BoxHeight : Integer;
      ExcludeBoxes : Array of TBox;
      TempBox : TBox;
      BadTPA : Boolean;
    begin
      Result := -1;

      X1 := 223;
      Y1 := 127;
      X2 := 295;
      Y2 := 175;

      FindColorsTolerance(GreenTPA,65280,X1,Y1,X2,Y2,0);
      FindColorsTolerance(RedTPA,255,X1,Y1,X2,Y2,0);

      CombinedTPA := CombineTPA(GreenTPA,RedTPA);

      if (High(CombinedTPA) > 0) then
      begin

        SplitTPAWrap(CombinedTPA,1,CombinedATPA);

        SetArrayLength(ExcludeBoxes,0);
        j := -1;
        for i:=0 to High(CombinedATPA) do
        begin
          TempBox := GetTPABounds(CombinedATPA[i]);
          BoxWidth := TempBox.x2-TempBox.x1;
          BoxHeight := TempBox.y2-TempBox.y1;
          if not (BoxWidth = 29) or not (BoxHeight = 4) then
          begin
            Inc(j);
            SetArrayLength(ExcludeBoxes,j+1);
            ExcludeBoxes[j] := TempBox;
          end;
        end;

        SplitTPAWrap(GreenTPA,1,GreenATPA);

        SetArrayLength(FinalATPA,0);
        k := 0;
        for i:=0 to High(GreenATPA) do
        begin
          BadTPA := False;
          for j:=0 to High(ExcludeBoxes) do
            if PointInBox(MiddleTPA(GreenATPA[i]),ExcludeBoxes[j]) then
              BadTPA := True;
          if not BadTPA then
          begin
            SetArrayLength(FinalATPA,k+1);
            FinalATPA[k] := GreenATPA[i];
          end;
        end;

        SortATPAFrom(FinalATPA,Point(MSCX,MSCY));

        DebugTPA_ATPA(GreenTPA,FinalATPA,-1);

        if (Length(FinalATPA) < 1) then Exit;

        TempBox := GetTPABounds(FinalATPA[0]);
        BoxWidth := TempBox.x2-TempBox.x1;

        Result := Round(BoxWidth*100/29);

      end;
    end;



    var
      HPLevel, HPPerc, HP : integer;

    begin
      ClearDebug;

      HPLevel := 59;
      repeat
        HPPerc := GetHPPercent;
        ClearDebug;
        if not (HPPerc = -1) then
        begin
          HP := Round(HPLevel*HPPerc/100)
          Writeln('HP: ' + IntToStr(HP));
          if HP < 30 then
            PlaySound('C:/Simba/sound2.wav');
        end;
        Wait(100);
      until False;
    end.
    Last edited by Shatterhand; 03-24-2013 at 09:48 AM.

  2. #2
    Join Date
    Jan 2013
    Posts
    167
    Mentioned
    1 Post(s)
    Quoted
    33 Post(s)

  3. #3
    Join Date
    Mar 2013
    Posts
    6
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    I'll tried it real quick, does it just check HP or sumthin ?

    I always remember back in the day there were scripts that could benefit PKers (and everyone else for that matter) that were capable of displaying your next hit like a half a second before you hit. I don't have the knowledge to recreate that but that would be a neat tool to use.

  4. #4
    Join Date
    Dec 2011
    Location
    Hyrule
    Posts
    8,662
    Mentioned
    179 Post(s)
    Quoted
    1870 Post(s)

    Default

    Would there be chances for false positives if someone was underattack below you or right next to you? We have a general run away function for randoms when they detect the hp bar right around where your player is, but since angles and such can change a bit the search zone might pick up somebody else's from time to time and cause you to run for no reason. Have you tested this with several people in combat right next to/on top of your player?


    Only ask b/c it might be good for randoms

  5. #5
    Join Date
    Jan 2012
    Posts
    1,104
    Mentioned
    18 Post(s)
    Quoted
    211 Post(s)

    Default

    Quote Originally Posted by Ashaman88 View Post
    Would there be chances for false positives if someone was underattack below you or right next to you? We have a general run away function for randoms when they detect the hp bar right around where your player is, but since angles and such can change a bit the search zone might pick up somebody else's from time to time and cause you to run for no reason. Have you tested this with several people in combat right next to/on top of your player?

    Only ask b/c it might be good for randoms
    It only works on highest angle.
    It will return with false data if people are under you.
    If they are next to you, it should work.

  6. #6
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    This works very nicely. I didn't try it around other players but I did try it at all angles and it seems to work quite accurately. Nice job buddy.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  7. #7
    Join Date
    Jul 2011
    Location
    /home/litoris
    Posts
    2,226
    Mentioned
    0 Post(s)
    Quoted
    159 Post(s)

    Default

    This is nice! Maybe make its name ApproxHPPercent or something to differentiate from the "real" percentage function.
    Miner & Urn Crafter & 07 Chicken Killer
    SPS BlindWalk Tutorial

    Working on: Nothing

    teacher in every art, brought the fire that hath proved to mortals a means to mighty ends

  8. #8
    Join Date
    Sep 2012
    Posts
    91
    Mentioned
    0 Post(s)
    Quoted
    41 Post(s)

    Default

    Couldn't it be possible to add a function if monsters or people are underneath you, it would check the stats tab for reinsurance? Otherwise it looks awesome

  9. #9
    Join Date
    Nov 2011
    Posts
    335
    Mentioned
    0 Post(s)
    Quoted
    68 Post(s)

    Default

    Been using sth like this myself but this looks way better than mine at first glance. Thanks for sharing , will test sometime today/tomorrow.

  10. #10
    Join Date
    Jan 2012
    Posts
    1,104
    Mentioned
    18 Post(s)
    Quoted
    211 Post(s)

    Default

    Quote Originally Posted by AIex View Post
    Couldn't it be possible to add a function if monsters or people are underneath you, it would check the stats tab for reinsurance? Otherwise it looks awesome
    The usage of this should be: if you get under 50% HP with this, you check stats tab too then eat.

    Updated the code, had some silly bugs in it.

  11. #11
    Join Date
    Sep 2012
    Location
    Netherlands
    Posts
    2,752
    Mentioned
    193 Post(s)
    Quoted
    1468 Post(s)

    Default

    thank you so much!
    my fighter is now completed thanks to this.
    can i use this in my script if i give credits to you?

    (keep my script private first for some days)

  12. #12
    Join Date
    Jan 2012
    Posts
    1,104
    Mentioned
    18 Post(s)
    Quoted
    211 Post(s)

    Default

    Quote Originally Posted by hoodz View Post
    thank you so much!
    my fighter is now completed thanks to this.
    can i use this in my script if i give credits to you?

    (keep my script private first for some days)
    Sure. That's why I shared it.

  13. #13
    Join Date
    Feb 2007
    Posts
    8
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Been trying to figure out how to incorporate this into a fighting script but no luck as of yet . I know it's probably fairly simple, so hints would be appreciated!

  14. #14
    Join Date
    Jul 2011
    Location
    /home/litoris
    Posts
    2,226
    Mentioned
    0 Post(s)
    Quoted
    159 Post(s)

    Default

    Quote Originally Posted by Nubby View Post
    Been trying to figure out how to incorporate this into a fighting script but no luck as of yet . I know it's probably fairly simple, so hints would be appreciated!
    Simba Code:
    if (GetHPPercent < 50) then
      EatingProcedure;
    Miner & Urn Crafter & 07 Chicken Killer
    SPS BlindWalk Tutorial

    Working on: Nothing

    teacher in every art, brought the fire that hath proved to mortals a means to mighty ends

  15. #15
    Join Date
    Mar 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Awesome add, got it to work with the auto fight script perfectly with neat windows alerts.

    Question! How do I get DebugImgForm to stop popping up? I have commented out the world and it keeps popping up whenever I close it

  16. #16
    Join Date
    Jan 2012
    Posts
    1,104
    Mentioned
    18 Post(s)
    Quoted
    211 Post(s)

    Default

    Quote Originally Posted by rcheat6 View Post
    Awesome add, got it to work with the auto fight script perfectly with neat windows alerts.

    Question! How do I get DebugImgForm to stop popping up? I have commented out the world and it keeps popping up whenever I close it
    Simba Code:
    //DebugTPA_ATPA(GreenTPA,FinalATPA,-1);

  17. #17
    Join Date
    Mar 2012
    Location
    Over there
    Posts
    840
    Mentioned
    4 Post(s)
    Quoted
    42 Post(s)

    Default

    Looks pretty useful. Maybe I will make a combat script sometime. Thanks for sharing!

  18. #18
    Join Date
    Sep 2008
    Posts
    754
    Mentioned
    8 Post(s)
    Quoted
    275 Post(s)

    Default

    i thought i already posted but i guess i didnt, thanks alot for this, works great for combat, really really useful, thank you - using it in my fcaver script

  19. #19
    Join Date
    Dec 2011
    Location
    Holland
    Posts
    455
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    I'm trying to use the utility, but when i'm out of combat and you call it, it will still give a positive. So as long as there is no hpbar it will always say < percentage.

    Could be the way I've implemented it?
    07Scripter
    I mostly write private scripts

  20. #20
    Join Date
    Jan 2012
    Posts
    1,104
    Mentioned
    18 Post(s)
    Quoted
    211 Post(s)

    Default

    Quote Originally Posted by okokokok View Post
    I'm trying to use the utility, but when i'm out of combat and you call it, it will still give a positive. So as long as there is no hpbar it will always say < percentage.

    Could be the way I've implemented it?
    If it finds a hp bar in the box, it should return with a 0-100 (calculated from the length of the bar). If it doesnt find, it should return with -1.

  21. #21
    Join Date
    Dec 2011
    Location
    Holland
    Posts
    455
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    Quote Originally Posted by Shatterhand View Post
    If it finds a hp bar in the box, it should return with a 0-100 (calculated from the length of the bar). If it doesnt find, it should return with -1.
    The problem is that I have a Teleport when health is below 40. Now it keeps teleporting.
    I'll post the piece of the code.

    Simba Code:
    ////////////////////////////////////////////////////////
    /////////// GetHPPercent Procedures & Functions ////////
    ///////////          Made by Shatterhand        ////////
    ///////////        Credits to Shatterhand       ////////
    ////////////////////////////////////////////////////////

    procedure SetBoxToBounds(var Box : TBox; X1,Y1,X2,Y2 : Integer);
    begin
      if (Box.x1 < X1) then Box.x1 := X1;
      if (Box.x2 > X2) then Box.x2 := X2;
      if (Box.y1 < Y1) then Box.y1 := Y1;
      if (Box.y2 > Y2) then Box.y2 := Y2;
    end;



    procedure DebugTPA_ATPA(TPA: TPointArray; ATPA: Array of TPointArray; First : Integer);
    var
      BMP, Col, x, y, i, width, height: Integer;
      TPABox : TBox;
    begin

      GetClientDimensions(width,height);
      BMP := BitmapFromClient(0,0,width-1,height-1);
      DrawTPABitmap(BMP,TPA,ClWhite);

      for i:=0 to High(ATPA) do
      begin
        if i = First then
          Col := ClRed
        else
          Col := ClPurple;

        TPABox := GetTPABounds(ATPA[i]);
        SetBoxToBounds(TPABox,0,0,width-1,height-1);

        for x := TPABox.x1 to TPABox.x2 do
        begin
          FastSetPixel(BMP,x,TPABox.y1,Col)
          FastSetPixel(BMP,x,TPABox.y2,Col)
        end;
        for y := TPABox.y1 to TPABox.y2 do
        begin
          FastSetPixel(BMP,TPABox.x1,y,Col)
          FastSetPixel(BMP,TPABox.x2,y,Col)
        end;
      end;

      TPABox := IntToBox(223,127,295,175);
      for x := TPABox.x1 to TPABox.x2 do
      begin
        FastSetPixel(BMP,x,TPABox.y1,Col)
        FastSetPixel(BMP,x,TPABox.y2,Col)
      end;
      for y := TPABox.y1 to TPABox.y2 do
      begin
        FastSetPixel(BMP,TPABox.x1,y,Col)
        FastSetPixel(BMP,TPABox.x2,y,Col)
      end;

      DebugBitmap(BMP);
      FreeBitmap(BMP);
    end;

    function GetHpPercent : Integer;
    var
      CombinedTPA, GreenTPA, RedTPA : TPointArray;
      CombinedATPA, GreenATPA, FinalATPA : Array of TPointArray;
      X1,Y1,X2,Y2, i,j,k, BoxWidth,BoxHeight : Integer;
      ExcludeBoxes : Array of TBox;
      TempBox : TBox;
      BadTPA : Boolean;
    begin
      Result := -1;

      X1 := 223;
      Y1 := 127;
      X2 := 295;
      Y2 := 175;

      FindColorsTolerance(GreenTPA,65280,X1,Y1,X2,Y2,0);
      FindColorsTolerance(RedTPA,255,X1,Y1,X2,Y2,0);

      CombinedTPA := CombineTPA(GreenTPA,RedTPA);

      if (High(CombinedTPA) > 0) then
      begin

        SplitTPAWrap(CombinedTPA,1,CombinedATPA);

        SetArrayLength(ExcludeBoxes,0);
        j := -1;
        for i:=0 to High(CombinedATPA) do
        begin
          TempBox := GetTPABounds(CombinedATPA[i]);
          BoxWidth := TempBox.x2-TempBox.x1;
          BoxHeight := TempBox.y2-TempBox.y1;
          if not (BoxWidth = 29) or not (BoxHeight = 4) then
          begin
            Inc(j);
            SetArrayLength(ExcludeBoxes,j+1);
            ExcludeBoxes[j] := TempBox;
          end;
        end;

        SplitTPAWrap(GreenTPA,1,GreenATPA);

        SetArrayLength(FinalATPA,0);
        k := 0;
        for i:=0 to High(GreenATPA) do
        begin
          BadTPA := False;
          for j:=0 to High(ExcludeBoxes) do
            if PointInBox(MiddleTPA(GreenATPA[i]),ExcludeBoxes[j]) then
              BadTPA := True;
          if not BadTPA then
          begin
            SetArrayLength(FinalATPA,k+1);
            FinalATPA[k] := GreenATPA[i];
          end;
        end;

        SortATPAFrom(FinalATPA,Point(MSCX,MSCY));

        DebugTPA_ATPA(GreenTPA,FinalATPA,-1);

        if (Length(FinalATPA) < 1) then Exit;

        TempBox := GetTPABounds(FinalATPA[0]);
        BoxWidth := TempBox.x2-TempBox.x1;

        Result := Round(BoxWidth*100/29);

      end;
    end;
     
    procedure HPPercent1;
    var
      HPLevel, HPPerc, HP : integer;

    begin
      ClearDebug;

      HPLevel := 59;
      repeat
        HPPerc := GetHPPercent;
        ClearDebug;
        if not (HPPerc = -1) then
        begin
          HP := Round(HPLevel*HPPerc/100)
          Writeln('HP: ' + IntToStr(HP));
          if HP < 30 then
            Writeln('HP is FuckedUP');
        end;
        Wait(100);
      until False;
    end;                                
    ///////////////////////////////////////////////////////
    ///////////  Combat Procedures & Functions  ///////////
    ///////////          Made by OkOkOkOk       ///////////
    ///////////////////////////////////////////////////////

    procedure Fight;
    Var Count: Integer;
    begin
      FindNormalRandoms;
      SetAngle(SRL_ANGLE_HIGH);
      ClearDebug;
      AntiBan;
      FindNormalRandoms;

      repeat
      begin

        FindNormalRandoms;
        Writeln('Looking for victims');

        repeat
        Inc(Count);
        If (FightingGiants) or
           (FightingGiants2) then

      Wait(2000 + random(50));
      While (CombatCheck = True) do
        begin

          If (GetHpPercent < 50) then
            begin
              Writeln('well fuck...');
              Count:=0;
            end
            else

            FindNormalRandoms;
            If (CombatCheck = True) then
              begin
              FindNormalRandoms;
              Writeln('Still Fighting');
              Writeln('Checking for Randoms #1');
              Wait(300 + Random(400));
              FindNormalRandoms;
              Writeln('Checking for Randoms #2');
              Wait(300 + Random(400));
              FindNormalRandoms;
              Writeln('Checking for Randoms #3');
              Wait(300 + Random(400));
              FindNormalRandoms;
              Writeln('Checking for Randoms #4');
              Wait(300 + Random(400));
              FindNormalRandoms;
              Writeln('Checking for Randoms #5');
              Wait(300 + Random(400));
              FindNormalRandoms;
              Writeln('Checking for Randoms #6');
              Wait(300 + Random(400));
              FindNormalRandoms;
              Writeln('Checking for Randoms #7');
              Wait(300 + Random(400));
              FindNormalRandoms;
              Writeln('Checking for Randoms #8');
              Wait(300 + Random(400));
              FindNormalRandoms;
              Writeln('Checking for Randoms #9');
              Wait(300 + Random(400));
              FindNormalRandoms;
              Writeln('Checking for Randoms #10');
              Wait(300 + Random(400));
              FindNormalRandoms;
              Count:=0;

              While (CombatCheck = True) do
                begin

                  If (GetHpPercent < 50) then
                    begin
                        Writeln('wellf fuck...');
                        Count:=0;
                    end;
                end;
          end;
        end;

        If (Count > 3) then
          begin
            FindNormalRandoms;
            Writeln('Need to find Monsters');
            GetBackToMonsters;
            Count:=0;
            Wait(2000 + random(100));
          end;
          FindNormalRandoms;

        until (CombatCheck = False);
        Looting;
        end;
      until (InvFull);
    end;

    Tried messing around with the spot a bit.
    07Scripter
    I mostly write private scripts

  22. #22
    Join Date
    Jan 2012
    Posts
    1,104
    Mentioned
    18 Post(s)
    Quoted
    211 Post(s)

    Default

    Quote Originally Posted by okokokok View Post
    The problem is that I have a Teleport when health is below 40. Now it keeps teleporting.
    I'll post the piece of the code.

    Tried messing around with the spot a bit.
    Well, this is not 100% accurate, moving npcs or players can caues false results. So this should be like a secondary checker. Primary should be checking numbers on stats tab.
    The quote myself from previous post:
    The usage of this should be: if you get under 50% HP with this, you check stats tab too then eat.
    Ill look into my code and your modified version after like a week, im busy with exams atm.

  23. #23
    Join Date
    Dec 2011
    Location
    Holland
    Posts
    455
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    Quote Originally Posted by Shatterhand View Post
    Well, this is not 100% accurate, moving npcs or players can caues false results. So this should be like a secondary checker. Primary should be checking numbers on stats tab.
    The quote myself from previous post:

    Ill look into my code and your modified version after like a week, im busy with exams atm.
    Ok thanks!
    Gl with your exams!
    07Scripter
    I mostly write private scripts

  24. #24
    Join Date
    Apr 2013
    Location
    Las Vegas
    Posts
    111
    Mentioned
    1 Post(s)
    Quoted
    35 Post(s)

    Default

    When you are checking for randoms simply use

    FNRwait(time);

    It does exactly what you are doing, but in one simple function. M

  25. #25
    Join Date
    Jun 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    sweeeeeeeet

Page 1 of 2 12 LastLast

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
  •