GetDistance3d Shared function

From Gothic 2 Online: Wiki
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 getDistance3d(float x1, float y1, float z1, float x2, float y2, float z2)

Required Arguments

  • x,y,z - Position of the first object.
  • x2,y2,z2 - Position of the second object.

Returns

  • int: The function returns 3d distance between two positions.

Example

Server

local function commandHandler(pid, cmd, params)
{
	if (cmd == "rp")
	{
		local pos = getPlayerPosition(pid);
		for (local i = 0; i <= getPlayersCount(); ++i)
		{
			local pos2 = getPlayerPosition(i);
			if (getDistance3d(pos.x, pos.y, pos.z, pos2.x, pos2.y, pos2.z) <= 1000)
			{
				sendPlayerMessageToPlayer(pid, 255, 255, 255, params);
			}
		}
	}
}

addEventHandler("onPlayerCommand", commandHandler);

Client

local function commandHandler(cmd, params)
{
	if (cmd == "dist")
	{
		local pos = getPlayerPosition(heroId);
		local dist = getDistance3d(pos.x, pos.y, pos.z, 1000, 1000, 1000);
		print("My distance from point (1000, 1000, 1000) is: " + dist);
	}
}

addEventHandler("onCommand", commandHandler);

Related functions