Results 1 to 6 of 6

Thread: procedure TurnToNearestNPC();

  1. #1
    Join Date
    Mar 2006
    Location
    NW US
    Posts
    210
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default procedure TurnToNearestNPC();

    Hey so I recently got some code to work for this. Included is some Smart_Draw to show proof of concept. It can be removed. The function goes something like this: (I found it helpful for my autofighter). Its a two function/procedure thingy, it could easily be condensed into one.

    Simba Code:
    function TurnToMMPoint(P: TPoint,minRandomnessDegrees, maxRandomnessDegrees : integer): Extended;
    var   //credits to Fl1ght. co-written by mr. pali
      d, current,final :extended;
    begin
      d := ArcTan2((P.Y - MMCY), (P.X - MMCX ));
      Result := degrees((fixRad(d-Pi)))- 90;
      Result := radians(result);
      current := rs_GetCompassAngleDegrees();
      current := radians(current);
      final := (Result + current);
      final:= degrees(final);
      MakeCompass(final + randomrange(minRandomnessDegrees , maxRandomnessDegrees))
      DebugLines('Turning to nearest NPC');
    end;  

    procedure turnToNpc();
    var  // creds to p1ng. co-written by mr. pali
    i:integer;
    NPCArray : TPointArray;
    NPCPoint:Tpoint;
    begin
    NPCArray := GetMinimapDots('NPC');
      if Length(NPCArray) < 1 then
        Exit;
      SortTPAFrom(NPCArray, Point(MMCX, MMCY));
      for i := 0 to High(NPCArray) do
      begin
      NPCPoint := NPCArray[i];
     
      SMART_ClearCanvasArea(IntToBox(524,7,709,159));
      SMART_DrawBoxEx(false,false,IntToBox((NPCPoint.x)-3,(NPCPoint.y)-3,(NPCPoint.x)+3,(NPCPoint.y)+3),ClYellow);
      SMART_Drawline(false,NPCPoint,point(MMCX,MMCY),CLRed);
      SMART_DrawLine(false,point(MMCX,7),point(MMCX,MMCY),CLBlue);

          TurnToMMPoint(NPCPoint,-10,10);
        exit;
    end;
    end;

    If someone higher up wanted to clean this up and submit it to the SRL include, I'd be a happy camper .

  2. #2
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    Looks handy. You could put it in Snippets

  3. #3
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    The original function TurnToMMPoint that Flight posted: Can you post it here? I think that one is much neater and should work just fine.

  4. #4
    Join Date
    Mar 2006
    Location
    NW US
    Posts
    210
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by Zyt3x View Post
    The original function TurnToMMPoint that Flight posted: Can you post it here? I think that one is much neater and should work just fine.
    that function didn't work for me, i spent an hour or two modifying it to this point, where it is working.

    the problem was, his function didn't take into account the current compass position.

    Simba Code:
    function TurnToMMPoint(P: TPoint): Extended; //by flight
    begin
      Result := ArcTan2((P.Y - MMCY), (P.X - MMCX));
      Result := (Degrees(fixRad(Result-Pi))-90);

      MakeCompass(Result);
    end;

  5. #5
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Quote Originally Posted by mr. pali View Post
    that function didn't work for me, i spent an hour or two modifying it to this point, where it is working.

    the problem was, his function didn't take into account the current compass position.

    Simba Code:
    function TurnToMMPoint(P: TPoint): Extended; //by flight
    begin
      Result := ArcTan2((P.Y - MMCY), (P.X - MMCX));
      Result := (Degrees(fixRad(Result-Pi))-90);

      MakeCompass(Result);
    end;
    Simba Code:
    function TurnToMMPoint(P: TPoint): Extended; //by flight
    begin
      Result := ArcTan2((P.Y - MMCY), (P.X - MMCX));
      Result := (Degrees(fixRad(Result-Pi))-90);

      MakeCompass(rs_GetCurrentCompassDegree - Result);
    end;

  6. #6
    Join Date
    Mar 2006
    Location
    NW US
    Posts
    210
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Yea but then you're adding degrees and you're gonna have problems. You need to use radians, then at the end convert it to degrees.

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
  •