Results 1 to 9 of 9

Thread: Rotate camera to nearest yellow dot

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

    Default Rotate camera to nearest yellow dot

    I was wondering, with the SRL include, if it would be possible to return a value of the nearest yellow dot on the minimap as a positive or negative angle between -180 and 180 depending on where it is on the minimap compared to where you're facing?

    and then to take it a further step, i would rotate the camera to this angle, with some minor randomness, if the absolute value > 60 (or whatever the viewangle of the runescape screen is).

    thanks

    -pali

  2. #2
    Join Date
    Dec 2011
    Location
    The Netherlands
    Posts
    1,631
    Mentioned
    47 Post(s)
    Quoted
    254 Post(s)

    Default

    GetMMDots('npc') returms a tpa with the results
    You know the middle; Point(MMCX, MMCY).
    Find the nearest by using Distance(p1, p2)
    Find the angle by using sinus .
    Rotate there by using makecompass

    Everything might be called different but should be close. If you havent managed to make the code tomorrow Ill make it.

    Script source code available here: Github

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

    Default

    Thanks! I'll Post the result when I get home and write it

  4. #4
    Join Date
    Apr 2012
    Location
    Australia
    Posts
    1,252
    Mentioned
    1 Post(s)
    Quoted
    22 Post(s)

    Default

    Credit to Flight for this cool function!

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

      MakeCompass(Result);
    end;

    Then in my script the way I do exactly what you are after...

    Simba Code:
    NPCArray := GetMinimapDots('NPC'); //grab yellow dots

      if Length(NPCArray) < 1 then  //if no yellow dots exit
        Exit;

      SortTPAFrom(NPCArray, Point(MMCX, MMCY));   //sort to the closest yellow dot
      for i := 0 to High(NPCArray) do
      begin
        NPCPoint := MMToMS(NPCArray[i]);  //convert point to a mainscreen co-ord

        if NPCPoint = Point(-1, -1) then   //if after converting the point
        begin                              //the ms co-ord isnt available
          TurnToMMPoint(NPCArray[i]);        //rotate camera
          Wait(RandomRange(100,200));
        end;

    I hope this helps you out, if you'd like further explaining just let me know

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

    Default

    Quote Originally Posted by P1ng View Post
    Credit to Flight for this cool function!

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

      MakeCompass(Result);
    end;

    Then in my script the way I do exactly what you are after...

    Simba Code:
    NPCArray := GetMinimapDots('NPC'); //grab yellow dots

      if Length(NPCArray) < 1 then  //if no yellow dots exit
        Exit;

      SortTPAFrom(NPCArray, Point(MMCX, MMCY));   //sort to the closest yellow dot
      for i := 0 to High(NPCArray) do
      begin
        NPCPoint := MMToMS(NPCArray[i]);  //convert point to a mainscreen co-ord

        if NPCPoint = Point(-1, -1) then   //if after converting the point
        begin                              //the ms co-ord isnt available
          TurnToMMPoint(NPCArray[i]);        //rotate camera
          Wait(RandomRange(100,200));
        end;

    I hope this helps you out, if you'd like further explaining just let me know
    im confused about if NPCPoint = Point(-1,-1) then

    why this?

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

    Default

    Still having trouble creating a reliable function. Can anyone chime in with some insight?

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

    Default

    I've solved it. These two functions work together to accomplish what I wanted: thanks for the help guys

    Simba Code:
    function TurnToMMPoint(P: TPoint): Extended;
    var
    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(-10,10))
    end;

    procedure turnToNpc();
    var
    i:integer;
    NPCArray : TPointArray;
    NPCPoint:Tpoint;
    begin
    NPCArray := GetMinimapDots('NPC');
      if Length(NPCArray) < 1 then
        Exit;
      SortTPAFrom(NPCArray, Point(MMCX, MMCY));   //sort to the closest yellow dot
      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);

    wait(randomrange(200,500));
          TurnToMMPoint(NPCPoint);
          wait(randomrange(1,500));
        exit;
    end;
    end;
    Last edited by mr. pali; 12-29-2012 at 11:51 AM.

  8. #8
    Join Date
    Jul 2012
    Posts
    279
    Mentioned
    5 Post(s)
    Quoted
    46 Post(s)

    Default

    Quote Originally Posted by mr. pali View Post
    im confused about if NPCPoint = Point(-1,-1) then

    why this?
    This is related to MMtoMS. It basically checks if you can find the NPC on the main screen and only rotate the screen if it can't.

  9. #9
    Join Date
    Apr 2012
    Location
    Australia
    Posts
    1,252
    Mentioned
    1 Post(s)
    Quoted
    22 Post(s)

    Default

    Wardancer is correct. I wrote the function such that there is no point turning the camera if this NPC that is closest is already within view.

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
  •