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

Function

isLineOfSightClear

Server and clientWorldIdentical to MTA:SA

Checks whether nothing blocks the segment between two points. On the client it asks the game (terrain, buildings, objects, vehicles, peds, collisions from .col files). On the server it uses a simplified model: script elements as spheres, without map terrain and buildings, so it is only an approximation.

Syntax

bool isLineOfSightClear(float sx, float sy, float sz, float ex, float ey, float ez [, bool checkBuildings = true, bool checkVehicles = true, bool checkPeds = true, bool checkObjects = true, bool checkDummies = true, bool seeThroughStuff = false, bool ignoreSomeObjectsForCamera = false, element ignoredElement = nil])

Arguments

sxfloat
Start X.
syfloat
Start Y.
szfloat
Start Z.
exfloat
End X.
eyfloat
End Y.
ezfloat
End Z.
checkBuildingsbool, optional = true
Include buildings and terrain.
checkVehiclesbool, optional = true
Include vehicles.
checkPedsbool, optional = true
Include peds and players.
checkObjectsbool, optional = true
Include objects.
checkDummiesbool, optional = true
Include game dummy objects (client).
seeThroughStuffbool, optional = false
See through transparent things like fences and glass (client).
ignoreSomeObjectsForCamerabool, optional = false
Skip objects the camera skips (client).
ignoredElementelement, optional = nil
An element ignored in the test (e.g. the player themselves).

Returns

true when nothing blocks the segment.

Example

local function canSee(target)
    local x1, y1, z1 = getCameraMatrix()
    local x2, y2, z2 = getElementPosition(target)
    return isLineOfSightClear(x1, y1, z1, x2, y2, z2, true, false, false, true, true, false, false, localPlayer)
end

Notes

Server. The server has no map collision. Called inside async(function() ... end) it asks the game of the player closest to the middle of the segment (up to 250 m, not in interiors) and waits up to 1.5 s for the answer - then terrain and buildings count. Outside async, or with nobody nearby, it only checks script elements.

See also