SRL Archive - SRL Archives

Procedure MakeCompassToPoint(cx, cy : Integer);


Metagen

2008-07-04 23:28:57

Procedure I wrote, I think it would benifit many scripters.


{*******************************************************************************
Procedure MakeCompassToPoint(cx, cy : Integer);
By: Metagen
Description: Turns the compass to point towards a set of coordinates on the
minimap
*******************************************************************************}
procedure MakeCompassToPoint(cx, cy : Integer);
begin
If not loggedin then exit;
if not rs_OnMinimap(cx, cy) then
begin
writeln('Point not on minimap');
exit;
end;
if cx > MMCX then
if cy >= MMCY then
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - (90 + degrees(ArcTan((cy-MMCY) div (cx-MMCX)))))));
else
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - (90 + degrees(ArcTan((cy-MMCY) div (cx-MMCX)))))));
else if cx < MMCX then
if cy >= MMCY then
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - (270 + degrees(ArcTan((cy-MMCY) div (cx-MMCX)))))));
else
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - (270 + degrees(ArcTan((cy-MMCY) div (cx-MMCX)))))));
else
if cy >= MMCY then
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - 180)));
else
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - 0)));
end;

Widget

2008-07-04 23:44:50

*snip*
{*******************************************************************************
Procedure MakeCompassToPoint(cx, cy : Integer);
By: Metagen
Description: Turns the compass to point towards a set of coordinates on the
minimap
*******************************************************************************}
procedure MakeCompassToPoint(cx, cy : Integer);
begin
If not loggedin then exit;
if not rs_OnMinimap(cx, cy) then
begin
writeln('Point not on minimap');
exit;
end;
if cx > MMCX then
if cy >= MMCY then
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - (90 + degrees(ArcTan((cy-MMCY) div (cx-MMCX)))))));
else
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - (90 + degrees(ArcTan((cy-MMCY) div (cx-MMCX)))))));
else if cx < MMCX then
if cy >= MMCY then
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - (270 + degrees(ArcTan((cy-MMCY) div (cx-MMCX)))))));
else
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - (270 + degrees(ArcTan((cy-MMCY) div (cx-MMCX)))))));
else
if cy >= MMCY then
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - 180)));
else
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - 0)));
end;

Metagen

2008-07-04 23:52:50

Thankyou :D

R0b0t1

2008-07-04 23:56:42


{*******************************************************************************
Procedure MakeCompassToPoint(cx, cy : Integer);
By: Metagen
Description: Turns the compass to point towards a set of coordinates on the
minimap
*******************************************************************************}
procedure MakeCompassToPoint(cx, cy : Integer);
begin
// If not loggedin then exit; <- MY GOD... This is most likely called somewhere else outside of this func.
if not rs_OnMinimap(cx, cy) then
begin
writeln('Point not on minimap');
exit;
end;

if cx > MMCX then
if cy >= MMCY then
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - (90 + degrees(ArcTan((cy-MMCY) div (cx-MMCX)))))))
else
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - (90 + degrees(ArcTan((cy-MMCY) div (cx-MMCX)))))));
else if cx < MMCX then
if cy >= MMCY then
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - (270 + degrees(ArcTan((cy-MMCY) div (cx-MMCX)))))))
else
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - (270 + degrees(ArcTan((cy-MMCY) div (cx-MMCX)))))));
end;
else
if cy >= MMCY then
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - 180)))
else
MakeCompass(inttostr(Round(rs_GetCompassAngleDegrees - 0)));
end;

I didn't have a syntax checker handy, (Damn fpc can't do that…), but it should compile.

Scaper

2008-07-05 19:29:15

metagan i accidentally voted no :(

but which part of the SRL folder will i add this plz?

Metagen

2008-07-05 20:27:59

well you dont need to, just throw it in your script if you need it ;)

Narcle

2008-07-05 21:36:16

I did this in a new fighting function of mine. It returns a array of all the Camera angles of the monsters (closests to farthest).

edit:
ArcTan2 is useful in this situation, not to make you feel bad but here:
function MakeCompassXY(pX, pY:integer): integer;
begin
result := Round(Degrees(ArcTan2(pY - MMCY, pX - MMCX)) + 90 + rs_GetCompassAngleDegrees);
If (Angle < 0) Then
result := result + 360;
If (Angle > 360) Then
result := result - 360;
MakeCompass(inttostr(result));
end;

I think this will work similarly. Idk just wrote it up real quick.

And yes I had to ask about ArcTan2 as well >.>

Metagen

2008-07-06 17:39:08

whats a arctan2? awww now my function has been written by other people better :( oh well

Daniel

2008-07-06 21:17:21

From: scaper123
metagan i accidentally voted no :(

but which part of the SRL folder will i add this plz?

Lowest part of MapWalk.scar :D

From: Metagen
whats a arctan2?

Open SCAR and press F1 then search for it ;)

From: SCAR Divi CDE Manual
function ArcCos(X: Extended): Extended;
The ArcCos function is a mathematical function giving the value in radians of the Arc Cosine of X.

function ArcTan2(Y, X: Extended): Extended;
ArcTan2 calculates ArcTan(Y/X), and returns an angle in the correct quadrant.
IN: |Y| < 2^64, |X| < 2^64, X <> 0
OUT: [-PI..PI] radians

Metagen

2008-07-06 22:14:10

oh, arctan2 is so sexy.