ProcessLineOfSight

From Multi Theft Auto: Wiki
Revision as of 14:51, 29 December 2007 by EAi (talk | contribs)
Jump to navigation Jump to search

This function checks if there is anything between 2 points in the world, and if there is, tells you where and what. The two positions must be within the local player's draw distance as the collision data is not loaded outside this area.

This function is useful for checking for collisions and for editor-style scripts. If you wish to get an element that's positioned at a particular point on the screen, use this function combined with getWorldFromScreenPosition.

Syntax

bool float float float element 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 ] )

Required Arguments

  • startX: The start x position
  • startY: The start y position
  • startZ: The start z position
  • endX: The end x position
  • endY: The end y position
  • endZ: The end z position

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • checkBuildings: Allow the line of sight to be blocked by GTA's internally placed buildings, i.e. the world map.
  • checkVehicles: Allow the line of sight to be blocked by vehicles.
  • checkPlayers: Allow the line of sight to be blocked by players.
  • checkObjects: Allow the line of sight to be blocked by objects.
  • checkDummies: Allow the line of sight to be blocked by GTA's internal dummies. These are not used in the current MTA version so this argument can be set to false.
  • seeThroughStuff: Allow the line of sight to be blocked by translucent game objects, e.g. glass.
  • ignoreSomeObjectsForCamera: Allow the line of sight to be blocked by certain objects.
  • shootThroughStuff: Allow the line of sight to be blocked by things that can be shot through
  • ignoredElement: Allow the line of sight to pass through a certain specified element.

Returns

If there is a collision, the function will return true, the collision position and MTA element hit. If no element is hit, the element return value will be nil. If there is no collision the function will return false.

Example

This example shows how you can tell what position and element the camera is looking at, up to 50 units away.

local tx, ty, tz = getWorldFromScreenPosition ( 0.5, 0.5, 50 )
local px, py, pz = getCameraPosition()
hit, x, y, z, elementHit = processLineOfSight ( px, py, pz, tx, ty, tz )
if hit then
    outputChatBox ( "Looking at " .. x .. ", " .. y .. ", " ..  z )
    if elementHit then
        outputChatBox ( "Hit element " .. getElementType(elementHit) )
    end
end

See Also