- Documentation
- Shared functions
- getGroundPosition
Function
getGroundPosition
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 = falsetrue: 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)
local x, y = 2495, -1665
local ground = getGroundPosition(x, y, 100)
if ground then setElementPosition(localPlayer, x, y, ground + 1) 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
getRoofPositionReturns the height of the lowest obstacle above a point (whether there is a roof overhead), according to the server's model: only script objects, without map buildings.processLineOfSightFinds the first obstacle on the segment between two points and returns the hit details. On the client it asks the game (terrain, buildings, objects, cars, peds, collisions from .col files) and returns plenty of data: hit point, element, surface normal, material, lighting, body or vehicle part, and on request the map object model with its position. Each call waits about one game frame; while the world is still loading (loading screen) it returnsfalseat once. On the server it uses a simplified model (element spheres, no terrain or buildings).