SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 20/02/2011, 01:46 AM   #1
-=SR=-
Little Clucker
 
Join Date: Aug 2010
Posts: 5
Reputation: 0
Question Get distance between 2 points.

I been trying to figure this out, and cannot think of a way to do this.
I need to get a distance between 2 points. Anybody have any idea or some suggestions on how to do this?

Thanks, SR
-=SR=- is offline   Reply With Quote
Old 20/02/2011, 01:51 AM   #2
bigcomfycouch
Huge Clucker
 
Join Date: Feb 2009
Location: Illinois
Posts: 305
Reputation: -2
Default Re: Get distance between 2 points.

pawn Code:
stock GetDistance( Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2 )
{
    return floatround( floatsqroot( ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) + ( ( z1 - z2 ) * ( z1 - z2 ) ) ) ) );
}
bigcomfycouch is offline   Reply With Quote
Old 20/02/2011, 02:10 AM   #3
-=SR=-
Little Clucker
 
Join Date: Aug 2010
Posts: 5
Reputation: 0
Default Re: Get distance between 2 points.

thanks, gona give it a try, will post back here with results
-=SR=- is offline   Reply With Quote
Old 23/02/2011, 04:03 PM   #4
-=SR=-
Little Clucker
 
Join Date: Aug 2010
Posts: 5
Reputation: 0
Default Re: Get distance between 2 points.

It works for what I needed, thanks a lot.
-=SR=- is offline   Reply With Quote
Old 07/03/2011, 06:53 PM   #5
Stefan_Toretto
Huge Clucker
 
Join Date: Apr 2010
Location: Romania
Posts: 341
Reputation: 0
Default Re: Get distance between 2 points.

This is in meters? or Kilometers?
__________________
Code:
mysql_query("DELETE `stupidity` FROM `earth`") OR die("idiots");
Stefan_Toretto is offline   Reply With Quote
Old 04/09/2011, 09:26 PM   #6
[DRD]Rodney
Big Clucker
 
Join Date: Jan 2010
Posts: 126
Reputation: 0
Default Re: Get distance between 2 points.

I failed. wrong post.
[DRD]Rodney is offline   Reply With Quote
Old 02/03/2016, 05:59 AM   #7
rt-2
Huge Clucker
 
rt-2's Avatar
 
Join Date: Jun 2011
Location: Montréal, Québec, Canada
Posts: 284
Reputation: 26
Default Re: Get distance between 2 points.

Quote:
Originally Posted by bigcomfycouch View Post
pawn Code:
stock GetDistance( Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2 )
{
    return floatround( floatsqroot( ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) + ( ( z1 - z2 ) * ( z1 - z2 ) ) ) ) );
}
Quote:
Originally Posted by -=SR=- View Post
It works for what I needed, thanks a lot.

The code is actually:
Code:
pawn Code:
stock GetDistance( Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2 ){    return floatround( floatsqroot( ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) + ( ( z1 - z2 ) * ( z1 - z2 ) ) )  );}
You had one too many ')'
__________________
rt-2
-------------------------------------------------
rt-2 is offline   Reply With Quote
Old 02/03/2016, 09:11 AM   #8
Sascha
High-roller
 
Sascha's Avatar
 
Join Date: Jul 2009
Location: Germany
Posts: 1,494
Reputation: 70
Default Re: Get distance between 2 points.

Quote:
Originally Posted by blinkpnk View Post
The code is actually:
Code:
pawn Code:
stock GetDistance( Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2 ){    return floatround( floatsqroot( ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) + ( ( z1 - z2 ) * ( z1 - z2 ) ) )  );}
You had one too many ')'
Not really, with 3 ) at the end you just close the "floatsqroot" function
the 4th ) closes the "floatround"
__________________
Don't bother to contact me, I'm out of SA-MP
Sascha is offline   Reply With Quote
Old 05/03/2016, 02:44 AM   #9
rt-2
Huge Clucker
 
rt-2's Avatar
 
Join Date: Jun 2011
Location: Montréal, Québec, Canada
Posts: 284
Reputation: 26
Default Re: Get distance between 2 points.

IDK but I had to remove one in my code because of error.
But again, PAWNO is a very mysterious world.
__________________
rt-2
-------------------------------------------------
rt-2 is offline   Reply With Quote
Old 05/03/2016, 06:18 AM   #10
AbyssMorgan
Banned
 
Join Date: Apr 2015
Location: Poland
Posts: 1,208
Reputation: 352
Default Re: Get distance between 2 points.

distance in integer, wtf
PHP Code:
stock Float:GetDistanceBetweenPoints3D(Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2){
    return 
VectorSize(x1-x2,y1-y2,z1-z2);

AbyssMorgan is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
points +1 AleksandarAdzic Help Archive 4 25/04/2010 09:13 PM
Getting pos with least distance ziomal432 Help Archive 1 16/04/2010 08:45 PM
Adding Points, /points and Hitman into a Roleplay Script Despare Help Archive 2 27/12/2009 01:35 PM
Distance For /Ar Lajko1 Help Archive 3 12/12/2009 03:29 PM
Distance between two points NtCat Help Archive 2 27/04/2009 05:32 PM


All times are GMT. The time now is 06:10 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.