Results 1 to 3 of 3

Thread: How to find closest object?

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

    Default How to find closest object?

    How do I find the closest object to the player? I tried this:

    Simba Code:
    Function PickFlax: Boolean;
    Var
      tmpCTS,i, L,Counter: Integer;
      ObjTPA: TPointArray;
      ObjATPA: T2DPointArray;
      X,Y,DMCount,Moves: Integer;
    Begin
      Moves:=0;
      DMCount:=0;

      tmpCTS := GetToleranceSpeed;
      SetColorToleranceSpeed(2);

      SetToleranceSpeed2Modifiers(0.07, 0.23);
      FindColorsTolerance(ObjTPA, 14999953, MSX1, MSY1, MSX2, MSY2, 5);
      SplitTPAWrap(ObjTPA, 10, ObjATPA);

      SortATPASize(ObjATPA,True);
      SetColorToleranceSpeed(tmpCTS);
      SetToleranceSpeed2Modifiers(0.02, 0.02);

      DMCount:=RandomRange(3,5);
      L := High(ObjATPA)
      MarkTime(Counter);
      For i := 0 To L Do
        Begin
          MiddleTPAEx(ObjATPA[i], X, Y);

          Repeat Begin
            If (P06_InvFull) Then
            Begin
              Walk_Bank;
              Bank;
            End;
            Moves:=Moves+1;
            mmouse(x, y, 1, 1);
            Wait(RandomRange(140, 200));
            If (P06_IsUpTextMultiCustom(['Flax','Pick', 'lax','ick'])) Then
            Begin
              Status := ('Picking flax');
              WriteProgress;
              clickmouse2(mouse_Left);
              Wait(RandomRange(400, 700));
              while (IsMoving) do
              wait(100);
              Exit;
            End;
          End; Until (Moves > DMCount)
          If (TimeFromMark(Counter) > 5000) Then
          Begin
            Break;
          End;
        End;
      Result:=False;
    End;


    But it seems to just randomly pick flax around the screen

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

    Default

    You are currently sorting by size, not distance away.

    instead of SortATPASize(ObjATPA,True), use SortATPAFromFirstPoint(ObjATPA, Point(MSCX, MSCY)). This will sort your ATPA by distance away from your player.
    Last edited by Nebula; 02-11-2013 at 11:04 PM.

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

    Default

    Quote Originally Posted by Nebula View Post
    You are currently sorting by size, not distance away.

    instead of SortATPASize(ObjATPA,True), use SortATPAFromFirstPoint(ObjATPA, Point(MSCX, MSCY)). This will sort your ATPA by distance away from your player.

    Thats what i was using cept i put it in bank instead of flax fml. TY

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
  •