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

Function

processLineOfSight

Server and clientWorldModified from MTA:SA

Finds 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 returns false at once. On the server it uses a simplified model (element spheres, no terrain or buildings).

Syntax

bool, float... processLineOfSight(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, bool shootThroughStuff = false, element ignoredElement = nil, bool includeWorldModelInformation = false, bool throughMapObjects = false])

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.
checkObjectsbool, optional = true
Include objects.
checkDummiesbool, optional = true
Include dummy objects (client).
seeThroughStuffbool, optional = false
See through transparent things (client).
ignoreSomeObjectsForCamerabool, optional = false
Skip objects the camera skips (client).
shootThroughStuffbool, optional = false
Pass through things bullets pass through (client).
ignoredElementelement, optional = nil
An element ignored in the test.
includeWorldModelInformationbool, optional = false
Also return the map object model, its position, rotation and LOD model (client).
throughMapObjectsbool, optional = false
Pass through trees, bushes and map objects (lamps, benches, fences); terrain, buildings, cars, peds and script objects still stop the ray (client).

Differences from MTA:SA

  • These MTA:SA arguments are not here: bool bIncludeExtraMateriaInfo = false

In MTA:SA

processLineOfSight(float startX, float startY, float startZ, float endX, float endY, float endZ, bool checkBuildings = true, bool checkVehicles = true, bool checkPlayers = true, bool checkObjects = true, bool checkDummies = true, bool seeThroughStuff = false, bool ignoreSomeObjectsForCamera = false, bool shootThroughStuff = false, element ignoredElement = nil, bool includeWorldModelInformation = false, bool bIncludeCarTyres = false, bool bIncludeExtraMateriaInfo = false)

Returns

hit, hit x, y, z, element, nx, ny, nz, material, lighting, part, (world model, x, y, z, rx, ry, rz, LOD); false when nothing was hit.

Example

addCommandHandler("cel", function()
    local x1, y1, z1, x2, y2, z2 = getCameraMatrix()
    local hit, hx, hy, hz, element = processLineOfSight(x1, y1, z1, x1 + (x2 - x1) * 50, y1 + (y2 - y1) * 50, z1 + (z2 - z1) * 50)
    if hit then outputChatBox(("Celujesz w %.1f %.1f %.1f %s"):format(hx, hy, hz, element and getElementType(element) or "")) end
end)

See also