ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Shared functions
  3. getGroundPosition

Function

getGroundPosition

Server and clientWorldModified from MTA:SA

Returns the ground height under a point. On the client it asks the game (real terrain and buildings). The server does not know the map terrain, so there it only considers script objects and the water level; it often returns false.

Syntax

float getGroundPosition(float x, float y, float z [, bool throughMapObjects = false])

Arguments

xfloat
X coordinate (or a vector).
yfloat
Y coordinate.
zfloat
The height to search down from.
throughMapObjectsbool, optional = false
true: passes through trees, bushes and map objects (lamps, benches, fences) and stops on terrain, buildings and script objects (e.g. floors from the map editor).Not in MTA:SA

Differences from MTA:SA

  • Arguments in a different colour differ from MTA:SA.

In MTA:SA

getGroundPosition(float x, float y, float z)

Returns

The ground height, or false when unknown.

Example

The server puts a pickup on the ground.

async(function()
    local ground = getGroundPosition(2495, -1665, 100)
    if ground then createPickup(2495, -1665, ground + 0.5, 3, 1240) end
end)

Notes

Ground under trees. Without throughMapObjects a point under a tree crown or inside a bush returns the top of the plant. With throughMapObjects = true you get the ground below it, useful e.g. for lines or markers drawn along the terrain. Plants placed by scripts are passed through too.

Server. The server has no map collision. Called inside async(function() ... end) it asks the game of the player closest to the point (up to 250 m, not in interiors) and waits up to 1.5 s - then it returns the real terrain. Outside async, or with nobody nearby, it only counts script objects (createObject) and water, otherwise it returns false.

See also