GetDistance2D
From Liberty Unleashed Wiki
This function returns the distance between two 2D points.
Syntax
GetDistance2D can take 2 different lists of parameters. These are:
float GetDistance2D( Vector2D v1, Vector2D v2 )
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.
function onPlayerCommand( plr, cmd, text ) { if ( cmd == "dist" ) { if ( text ) { local player = FindPlayer( text ); if ( player ) { local v1 = plr.Pos, v2 = player.Pos; MessagePlayer( format( "%s can be located %.2fm from your position.", player.Name, GetDistance2D( v1.x, v1.y, v2.x, v2.y ) ), plr ); } else MessagePlayer( "Player '" + text + "' is not online!", plr ); } } return 1; }
Notes
The functions MessagePlayer, FindPlayer and event onPlayerCommand were used in in this example. More info about these in the corresponding pages.
Related Functions
- GetDistance
- GetDistance2D
- GetFullTime
- GetTickCount
- GetTime
- GetTok
- InPoly
- IsIn
- IsNum
- NumTok
- RandomString