SA-MP Forums Archive
Getting new XY coordinates - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Getting new XY coordinates (/showthread.php?tid=479157)



Getting new XY coordinates - Whizion - 03.12.2013

So i have a coordinate, let's say:

x = 10, y = 2

And let's say i want to travel 20 "units" in 90° direction (west in-game).

What would be my new x and y?

Can you give me a snipet/function/explain how to do this?

Thank you.


Re: Getting new XY coordinates - ReApZ - 03.12.2013

do /save [optional(name)]
goto savedpositions.txt in samp files
and get the new x y code
\Documents\GTA San Andreas User Files\SAMP
default


Re: Getting new XY coordinates - Avi Raj - 03.12.2013

pawn Код:
new Float:X,Float:Y,Float:Z,Float:Angle;
GetPlayerPos(playerid,X,Y,Z);
GetPlayerFacingAngle(playerid,Angle);
Then do what you want to do.


Re: Getting new XY coordinates - Whizion - 03.12.2013

I don't want to manually do it, i want the server to calculate it.

For instance a function like this:

GetDistanceXY(current_x, current_y, distance, angle)

And it returns the new x/y, which are "distance" far from current_x and current_y at "angle".


Re: Getting new XY coordinates - RajatPawar - 03.12.2013

pawn Код:
stock getNewCoordinatesInDirection(playerid, Float: fNewX, Float: fNewY, Float: fDistance = 2.0)
{
       new Float: fOldX, Float: fOldY, Float: fOldZ, Float: fAngle;
       GetPlayerPos(playerid, fOldX, fOldY, fOldZ);
       GetPlayerFacingAngle(playerid, fAngle);
       fNewX = fOldX + (fDistance * (floatcos(-(fAngle + 90), degrees)));
       fNewY = fOldY + (fDistance * (floatsin(-(fAngle + 90), degrees)));
       return 1;
}
You'll have to change
pawn Код:
-(fAngle + 90),
these lines in order to get the desired effect, because this is simple polar stuff, but I am unsure as to how the GTA: SA co - ordinates work.


Re: Getting new XY coordinates - Whizion - 03.12.2013

Thanks a lot, that will help.