Results 1 to 8 of 8

Thread: TPA, how to ignore character when finding color?

  1. #1
    Join Date
    May 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default TPA, how to ignore character when finding color?

    Hello!

    I'm tried to make a TPA for my character and then make it not to search in that area. Becourse if you have same color on your armor it should not klick on it. So the area is the one in middle while standing still.
    The thing is, im getting errors when i try to run it

    Exception: Range check error at line 20
    The following DTMs were not freed: [SRL - Lamp bitmap, 1]
    The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap, SRL - Flag bitmap
    Line 20: TPAYou := TPAFromBox(IntToBox(205, 263, 291, 250));
    It should right click and attack Barbarians and ignore to search in the middle part of the screen.

    Maybe there is an easier way to do this?

    Simba Code:
    program new;
    {$i SRL/srl.simba}
     
    Function FindSomething : Boolean;
    Var
      CTS, x, y, I, h : Integer;
      TPAYou, TPA: TPointArray;
      ATPA: Array of TPointArray;
      CPA: T2DPointArray;
      mid: TPoint;
    Begin
      CTS := GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(3.49, 5.27);
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, 3041353, MSX1, MSY1, MSX2, MSY2, 7);
      ColorToleranceSpeed(CTS)
      ATPA := TPAToATPAEx(TPA, 25, 25);
      For I := 0 to High(ATPA) do
      Begin
      TPAYou  := TPAFromBox(IntToBox(205, 263, 291, 250));
     
        CPA := SplitTPA(TPA, 0);
     
        h := High(CPA);
        for i := 0 to h do
        begin
          if(GetArrayLength(CPA[i]) >= 2) then
          begin
            mid := MiddleTPA(CPA[i]);
            if((mid.x > 5) AND (mid.y > 2)) then
            begin
              if((NOT PointInTPA(mid, TPAYou))) then
              begin
                MMouse(mid.x, mid.y, 0, 0);
                begin
        MiddleTPAEx(ATPA[i], x, y);
        Mouse(x, y, 2, 2,False);
        If (ChooseOption('ttack')) Then
        Begin
          Wait(1000);
          Result := True;
          Exit;
                  End;
                End;
              End;
            End;
          End;
        End;
      End;
        Result := False;
     
    End;
     
    begin
      SetupSRL;
      FindSomething;
    end.

    Thanks!

    Dear // Jannemus!

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

    Default

    A couple things I noticed. First off, 'IntToBox' has the parameters in this order: X1, Y1, X2, Y2. You have:
    Simba Code:
    TPAYou := TPAFromBox(IntToBox(205, 263, 291, 250));
    According to this your box's Y1 is > than the Y2 value... So... are you sure that's correct? :/

    Another thing is you're actually never removing the 'box area' around your player from your found colour's TPA. You should do this instead:
    Simba Code:
    program new;
    {$i SRL/srl.simba}

    function FindSomething: Boolean;
    var
      CTS, x, y, I, h: Integer;
      TPAYou, TPA: TPointArray;
      ATPA: array of TPointArray;
      CPA: T2DPointArray;
      mid: TPoint;
    begin
      TPAYou := TPAFromBox(IntToBox(205, 263, 291, 250));  //You'll want to fix these parameters in the X1,Y1,X2,Y2 format
      CTS := GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(3.49, 5.27);
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, 3041353, MSX1, MSY1, MSX2, MSY2, 7);
      SetColorSpeed2Modifiers(0.2, 0.2);    //Also added this in
      ColorToleranceSpeed(CTS);
      TPA := ClearTPAFromTPA(TPA, TPAYou);  //Here's where you actually remove any of the TPA that's included in your box
      ATPA := TPAToATPAEx(TPA, 25, 25);
      for I := 0 to High(ATPA) do
      begin
        CPA := SplitTPA(TPA, 0);            //Why? :/
        h := High(CPA);
        for i := 0 to h do
        begin
          if (GetArrayLength(CPA[i]) >= 2) then
          begin
            mid := MiddleTPA(CPA[i]);
            if ((mid.x > 5) and (mid.y > 2)) then
            begin
              if ((not PointInTPA(mid, TPAYou))) then
              begin
                MMouse(mid.x, mid.y, 0, 0);
                begin
                  MiddleTPAEx(ATPA[i], x, y);
                  Mouse(x, y, 2, 2, False);
                  if (ChooseOption('ttack')) then
                  begin
                    Wait(1000);
                    Result := True;
                    Exit;
                  end;
                end;
              end;
            end;
          end;
        end;
      end;
      Result := False;
    end;

    begin
      SetupSRL;
      FindSomething;
    end.

    I used Simba's handy little 'Format Script' button to clean up your code.

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


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

    Default

    I use this in my functions.
    Simba Code:
    SortTPAFrom(TPA,Point(MSCX,MSCY));                                  
    InvertTPA(TPA);
    for i:=0 to High(TPA) do
    if (Abs(TPA[i].x - MSCX) <  25) and (Abs(TPA[i].y - MSCY) <  25) then
      Break;
    SetArrayLength(TPA,i);
    This will exclude points in the TPA which are in the 25 distant box from the (MSCX,MSCY).
    NOTE: your function should handle the case when it sets the array lenght to 0. (it breaks when i = 0)
    Last edited by Shatterhand; 07-14-2012 at 08:33 AM.

  4. #4
    Join Date
    May 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default a new error.

    Quote Originally Posted by Flight View Post
    A couple things I noticed. First off, 'IntToBox' has the parameters in this order: X1, Y1, X2, Y2. You have:
    Simba Code:
    TPAYou := TPAFromBox(IntToBox(205, 263, 291, 250));
    According to this your box's Y1 is > than the Y2 value... So... are you sure that's correct? :/

    Another thing is you're actually never removing the 'box area' around your player from your found colour's TPA. You should do this instead


    I used Simba's handy little 'Format Script' button to clean up your code.
    Thanks for all help!

    Changed TPA now in the script you sent me.
    Simba Code:
    TPAYou := TPAFromBox(IntToBox(226, 292, 133, 254));

    I thought it was x1,x2,y1,y2. hehe.

    But i get the same error, but now at line 23

    Simba Code:
    if (GetArrayLength(CPA[i]) >= 2) then

    Error: Out Of Range at line 23
    The following DTMs were not freed: [SRL - Lamp bitmap, 1]
    The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap, SRL - Flag bitmap]
    Thanks again!

    Dear // Jannemus!

  5. #5
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    I did this a while back, Im not sure how it goes (lost the code in the crash).
    I basically made 4 different boxes
    box[1] := IntToBox(50,50,100,100);
    box[2] := IntToBox(150,150,200,200);
    box[3] := IntToBox(250,250,300,300);
    box[4] := IntToBox(350,350,400,400);

    Then looped it via a for..to..do loop like this

    Simba Code:
    for i := 1 to 4 do
    begin
    if FindColorsTolerance(Box.x1[i],Box.y1[i],Box.x2[i],Box.y2[i],col,tol) then
     yadayadadaa
    end;

    That'll basically ignore the character, and search in boxes around it.

  6. #6
    Join Date
    Dec 2011
    Location
    New York, USA
    Posts
    1,242
    Mentioned
    12 Post(s)
    Quoted
    193 Post(s)

    Default

    Lol.

    RemoveDistTPointArray.

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

    Default

    Cant you do cleartpafromtpa? or something like that

  8. #8
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Wasn't there a FindColorsSkipBox function?
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

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
  •