Results 1 to 6 of 6

Thread: Finding HP box on monsters?

  1. #1
    Join Date
    Aug 2018
    Posts
    17
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default Finding HP box on monsters?

    Hey guys, been digging into the include and learning quite a bit. I have ran into this one roadblock though. I am trying to do combat but it attacks monsters already in combat. I think the best way to avoid this is to check if the HP Bar is present prior to clicking it.

    Is there a function to check for 2 colors at a time or a way to return the tbox params that I can adjust to fit another TBox that would search for the HP bar? My code is below.

    Edit: This is for OSRS if that makes a difference.
    Simba Code:
    {Custom clickObject function. Given I would rather do a record and then load the data in rather than type it out potentially multiple times. Nothing special just gets params for
    color finding, filtering, and doWait boolean. I added this because there are some objects that you can immediately interact with upon clicking and there is no animation (interfaces)
    so you will put doWait = false opposed to true where you need to be looking for animation and not spam clicking.}

    function clickObject(objectColor: TCTS2Color = [1, 1, 1, 1]; bounds: TBox; objectCluster: Int32; sizeFilter1: Int32; sizeFilter2: Int32; objectText: string; doWait: boolean = true; location: TPoint): boolean;
    var
      TPA, objectArray : TPointArray;
      ATPA : T2DPointArray;
      currentXP : Integer;
      HPCheckBox : TBox;
    begin
      currentXP := XPBar.Read; //Grabs current xp for comparison to see if we successfully gained xp

      if SRL.FindColors(TPA, objectColor, bounds) > 0 then
      begin
        HPCheckBox:= IntToBox(TPA.Bounds.X1 - 5, TPA.Bounds.Y1 + 5, TPA.Bounds.X2 + 20, TPA.Bounds.Y2 + 20);

        if SRL.FindColors(objectArray, $00FF00, HPCheckBox) then
          writeln('Found HP Bars');
        ATPA:= TPA.Cluster(objectCluster);
        ATPA.FilterSize(sizeFilter1, sizeFilter2);
        ATPA.SortByIndex(Mainscreen.GetMiddle);

        {$IFDEF SMART}
          //Smart.Image.DrawATPA(ATPA);
        {$ENDIF}
        for objectArray in ATPA do
        begin

          if Fail >= 5 then
          begin
            RSW.WebWalk(Location);
            Fail:= 1;
          end;
          Mouse.Move(objectArray[Random(Length(objectArray))]);
          if MainScreen.IsUpText(objectText) then
          begin
            if Mouse.Click(ctRed) then
            begin
              Minimap.WaitPlayerMoving();
              if doWait = true then //Added this to allow for clicking objects which will open an interface.
              begin
                while SRL.IsAnimating(Mainscreen.GetPlayerBox, 160, 650, 1) do
                begin
                  ChatBox.ClickContinue(); //previously had this in the while statement but half the time it didn't catch it
                  wait(100);
                end;
              end;
              Fail:= 1;
              exit(true);
            end;
            exit(false);
          end;
        end;
      end;
      WriteLn('Unable to find object, rotating camera');
      Inc(Fail);
      Minimap.RandomCompass(10, 200, false);
    end;

    Edit: wrapped Simba tags
    Last edited by Hastega; 08-20-2018 at 03:27 AM.

  2. #2
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

  3. #3
    Join Date
    Aug 2018
    Posts
    17
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    Thanks I am actually using that to detect if I am in combat. I'm trying to ensure that I'm not clicking a monster that is already in combat though. Is it possible to just add in a check from my color if dist <= x from HP Bar to filter it?

  4. #4
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    Quote Originally Posted by Hastega View Post
    Thanks I am actually using that to detect if I am in combat. I'm trying to ensure that I'm not clicking a monster that is already in combat though. Is it possible to just add in a check from my color if dist <= x from HP Bar to filter it?
    Simba Code:
    if Length(MainScreen.FindHPBars(Box(X-20, Y-10, X+20, Y+10))) > 0 then WriteLn('found nearby');

  5. #5
    Join Date
    Aug 2018
    Posts
    17
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    Thanks I'll experiment with this and see if I can't get it working. @Olly;
    Edit: So I'm doing this right now. I did a drawbox and these vary A LOT in size but I can't quite figure out how to use TPA.Remove to only remove specific ones that meet this...
    Simba Code:
    HPCheckBoc:= TPA.Bounds
    If Length(MainScreen.FindHPBars(HPCheckBox)) > 0 Then
    TPA.Remove(TPA, false)
    Last edited by Hastega; 08-20-2018 at 03:25 AM.

  6. #6
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    Quote Originally Posted by Hastega View Post
    ...
    Just check while looping?

    Simba Code:
    for objectArray in ATPA do
    begin
      b := objectArray.Bounds();
      HPCheckBox := [b.x1 - 5, b.y1 - 5, b.x2 + 5, b.y2 + 5];

      if Length(MainScreen.FindHPBars(HPCheckBox)) > 0 then
        Continue;

      Mouse.Move(objectArray.Mean());
      // etc...


    end;

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
  •