GetDistance

From Liberty Unleashed Wiki
Jump to: navigation, search
Home   |   Squirrel Scripting   |   Server Functions   |   Server Events   |   Client Functions   |   Client Events

This function returns the distance between two points in 3D space.

Syntax

GetDistance can take 2 different lists of parameters. These are:

  1. float GetDistance( Vector v1, Vector v2 )
  1. float GetDistance( float x1, float y1, float z1, float x2, float y2, float z2 )

Arguments

  • v1, v2 - These are the two points in vector form
  • x1, y1, z1, x2, y2, z2 - These are the two points as floats

Example

This command returns the player how far another player is.

  1.  
  2. function onPlayerCommand( plr, cmd, text )
  3. {
  4. if ( cmd == "dist" )
  5. {
  6. if ( text )
  7. {
  8. local player = FindPlayer( text );
  9. if ( player )
  10. {
  11. local dist = GetDistance( plr.Pos, player.Pos )
  12. MessagePlayer( format( player.Name + " is located " + dist + "ms. from your position.", plr );
  13. }
  14. else MessagePlayer( "Player '" + text + "' is not online!", plr );
  15. }
  16. }
  17. return 1;
  18. }
  19.  

Notes

The functions MessagePlayer, FindPlayer and event onPlayerCommand were used in in this example. More info about these in the corresponding pages.

Related Functions

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox