Entity::dist: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Function that gets the distance between two entities.
{{ServersideJsFunction}}
==Parameters==
Gets the distance between two entities
* '''position''': {{RageType|Vector3}}
 
{{JSContainer|  


==Syntax==
==Syntax==
{{ServerSide}}
<pre>entity.dist(position)</pre>
<syntaxhighlight lang="javascript">
 
entity.dist(entity2.position);
=== Required Arguments ===
</syntaxhighlight>
*'''position:''' {{RageType|Vector3}}
 
==Example==
Gets the distance between a player and a vehicle
{{ServersideCode|
<pre>
let distVeh = mp.vehicles.new(mp.joaat('turismor'), new mp.Vector3(-423.88, 1128.86, 326));
mp.events.addCommand('dist', (player) => {
let dist = player.dist(distVeh.position);
player.outputChatBox(`Distance: ${dist}`)
});
</pre>
}}
}}
 
==See also==
{{Entity_definition}}
 
[[Category:Entity API]]
[[Category:Server-side Function]]

Latest revision as of 12:25, 2 December 2019

Server-Side
Function

 JavaScript



Gets the distance between two entities

JavaScript Syntax


Syntax

entity.dist(position)

Required Arguments

  • position: Vector3

Example

Gets the distance between a player and a vehicle

Server-Side
let distVeh = mp.vehicles.new(mp.joaat('turismor'), new mp.Vector3(-423.88, 1128.86, 326));
mp.events.addCommand('dist', (player) => {
	let dist = player.dist(distVeh.position);
	player.outputChatBox(`Distance: ${dist}`)
});


See also