GetDistance2D

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 2D points.

Syntax

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

  1. float GetDistance2D( Vector2D v1, Vector2D v2 )
  1. float GetDistance2D( float x1, float y1, float x2, float y2 )

Arguments

  • v1, v2 - These are the two points as 2D vectors
  • x1, y1, x2, y2 - These are the two points as floats

Example

This command tells the player how far another player is, ignoring the altitude.

  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 v1 = plr.Pos, v2 = player.Pos;
  12. MessagePlayer( format( "%s can be located %.2fm from your position.", player.Name, GetDistance2D( v1.x, v1.y, v2.x, v2.y ) ), 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