GetDistance2d Shared function
Jump to navigation
Jump to search
This function was added in version: Server: 0.0.0, Client: 0.0.5 |
The function is returning the distance between quoted values.
Syntax
int getDistance2d(float x1, float z1, float x2, float z2)
Required Arguments
- x,z - Position of the first object.
- x2,z2 - Position of the second object.
Returns
- int: The function returns 2d distance between two positions.
Example
Server
local function commandHandler(pid, cmd, params)
{
if (cmd == "gps")
{
local pos = getPlayerPosition(pid);
local distance = getDistance2d(pos.x, pos.z, -28769, -28593);
sendMessageToPlayer(pid, 255, 255, 0, "Destination point: " + distance);
}
}
addEventHandler("onPlayerCommand", commandHandler);
Client
local function commandHandler(cmd, params)
{
if (cmd == "gps")
{
local pos = getPlayerPosition(heroId);
local distance = getDistance2d(pos.x, pos.z, -28769, -28593);
print("Destination point: " + distance);
}
}
addEventHandler("onCommand", commandHandler);