SRL Archive - OSR Help

Rotate camera to nearest yellow dot


mr. pali

2012-12-28 17:21:57

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

J J

2012-12-28 18:06:35

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.

mr. pali

2012-12-28 19:50:47

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

P1ng

2012-12-28 20:18:53

Credit to Flight for this cool function!

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…

  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

mr. pali

2012-12-28 20:42:15

From: P1ng
Credit to Flight for this cool function!

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…

  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?

mr. pali

2012-12-28 23:39:29

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

mr. pali

2012-12-29 06:26:07

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

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;

Wardancer

2012-12-29 06:55:40

From: mr. pali
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.

P1ng

2012-12-29 22:27:22

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.