Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: TheMallard on Feb 13, 2016, 01:04 PM

Title: [QUESTION] How to get point to point distance?
Post by: TheMallard on Feb 13, 2016, 01:04 PM
Hello!
I've created a small function, and I don't know, it works properly or not.
Is this the right code?
function getPointDistanceToPoint(x1, y1, z1, x2, y2, z2)
{
return Vector(x1-x2, y1-y2, z1-z2).Length();
}
Title: Re: [QUESTION] How to get point to point distance?
Post by: KAKAN on Feb 13, 2016, 01:06 PM
Nope. You can't get the length of a class/instance.

And the length function is: len() and not Length()
Still then, I can't know what you're talking about.

 :edit: This code might help you:-
function IsPlayerInRangeOfPoint(v1, v2, range) // by Rusty_Bullet22
{
  v1.x -= v2.x, v1.y -= v2.y, v1.z -= v2.z;
  return ((v1.x * v1.x) + (v1.y * v1.y) + (v1.z * v1.z)) < (range * range);
  /*
Returns true if the player is within a range of 1500 from (0,0,0)
false if not
IsPlayerInRangeOfPoint( player.Pos, Vector( 0, 0, 0 ), 1500 );
  */
}
I haven't made it, @Cutton did.
Title: Re: [QUESTION] How to get point to point distance?
Post by: TheMallard on Feb 13, 2016, 01:08 PM
My function works properly.

Class Vector has a method, called "Length()"
Title: Re: [QUESTION] How to get point to point distance?
Post by: . on Feb 13, 2016, 01:14 PM
Quote from: KAKAN on Feb 13, 2016, 01:06 PMNope. You can't get the length of a class/instance.

And the length function is: len() and not Length()
Still then, I can't know what you're talking about.

He's not talking about the container element count /length such as array/table/string. He's talking about the the distance between two points in 3 dimensional space (http://freespace.virgin.net/hugo.elias/routines/r_dist.htm). And the method he's calling is on the Vector instance (https://bitbucket.org/stormeus/0.4-squirrel/src/dfdf3960226db784d7e807770ca3b1b46f51b16c/UtilStructs.cpp?at=master&fileviewer=file-view-default#UtilStructs.cpp-326).
Title: Re: [QUESTION] How to get point to point distance?
Post by: ysc3839 on Feb 13, 2016, 04:21 PM
Quote from: KAKAN on Feb 13, 2016, 01:06 PMNope. You can't get the length of a class/instance.

And the length function is: len() and not Length()
Still then, I can't know what you're talking about.

 :edit: This code might help you:-
function IsPlayerInRangeOfPoint(v1, v2, range) // by Rusty_Bullet22
{
  v1.x -= v2.x, v1.y -= v2.y, v1.z -= v2.z;
  return ((v1.x * v1.x) + (v1.y * v1.y) + (v1.z * v1.z)) < (range * range);
  /*
Returns true if the player is within a range of 1500 from (0,0,0)
false if not
IsPlayerInRangeOfPoint( player.Pos, Vector( 0, 0, 0 ), 1500 );
  */
}
I haven't made it, @Cutton did.
You are wrong. Vector has the "Length" method.
Title: Re: [QUESTION] How to get point to point distance?
Post by: FarisDon on Feb 13, 2016, 07:29 PM
Quote from: TheMallard on Feb 13, 2016, 01:04 PMHello!
I've created a small function, and I don't know, it works properly or not.
Is this the right code?
function getPointDistanceToPoint(x1, y1, z1, x2, y2, z2)
{
return Vector(x1-x2, y1-y2, z1-z2).Length();
}
Why did you actually create the code,
It could have been Found (http://wiki.vcmp.org/wiki/Scripting/Squirrel/Functions/DistanceFromPoint) over here, than why make functions, I'm just curious to know why?
Title: Re: [QUESTION] How to get point to point distance?
Post by: ysc3839 on Feb 13, 2016, 08:39 PM
Quote from: [TBS]Destroyer on Feb 13, 2016, 07:29 PM
Quote from: TheMallard on Feb 13, 2016, 01:04 PMHello!
I've created a small function, and I don't know, it works properly or not.
Is this the right code?
function getPointDistanceToPoint(x1, y1, z1, x2, y2, z2)
{
return Vector(x1-x2, y1-y2, z1-z2).Length();
}
Why did you actually create the code,
It could have been Found (http://wiki.vcmp.org/wiki/Scripting/Squirrel/Functions/DistanceFromPoint) over here, than why make functions, I'm just curious to know why?
Maybe he don't know there is such function. I don't know too.
Title: Re: [QUESTION] How to get point to point distance?
Post by: FarisDon on Feb 13, 2016, 08:40 PM
Quote from: ysc3839 on Feb 13, 2016, 08:39 PM
Quote from: [TBS]Destroyer on Feb 13, 2016, 07:29 PM
Quote from: TheMallard on Feb 13, 2016, 01:04 PMHello!
I've created a small function, and I don't know, it works properly or not.
Is this the right code?
function getPointDistanceToPoint(x1, y1, z1, x2, y2, z2)
{
return Vector(x1-x2, y1-y2, z1-z2).Length();
}
Why did you actually create the code,
It could have been Found (http://wiki.vcmp.org/wiki/Scripting/Squirrel/Functions/DistanceFromPoint) over here, than why make functions, I'm just curious to know why?
Maybe he don't know there is such function. I don't know too.
Okay, well that's not really a serious problem/issue thou.
Title: Re: [QUESTION] How to get point to point distance?
Post by: Thijn on Feb 14, 2016, 05:57 PM
You can use Vector.Distance( Vector) to get the distance in 3d.
function getPointDistanceToPoint(x1, y1, z1, x2, y2, z2)
{
 return Vector(x, y, z).Distance( Vector( x2, y2, z2 ) );
}