TestSphereAgainstWorld

From Multi Theft Auto: Wiki
Revision as of 01:52, 22 December 2024 by FileEX (talk | contribs) (Created page with "{{Client function}} __NOTOC__ {{New feature/item|3.161|1.6.0|22837| The function checks whether there is an object within the given radius and returns information about it. The function works similarly to processLineOfSight, but instead of a straight line, it operates based on the specified radius, forming a sphere.}} ==Syntax== Return values labelled for ease of reference. <syntaxhighlight lang="lua"> bool -- hit element -- hitElement floa...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

ADDED/UPDATED IN VERSION 1.6.0 r22837:
The function checks whether there is an object within the given radius and returns information about it. The function works similarly to processLineOfSight, but instead of a straight line, it operates based on the specified radius, forming a sphere.

Syntax

Return values labelled for ease of reference.

bool               -- hit
element            -- hitElement
float float float  -- worldModelPositionX,Y,Z
float float float  -- worldModelRotationX,Y,Z
int                -- worldModelID
int                -- worldLODModelID
string             -- entity type (vehicle, ped, object etc.)
                 testSphereAgainstWorld ( float startX, float startY, float startZ, 
                                       float radius, 
                                       [ bool ignoredElement = nil, 
                                       bool checkBuildings = true, 
                                       bool checkVehicles = true, 
                                       bool checkPeds = true, 
                                       bool checkObjects = true, 
                                       bool checkDummies = true, 
                                       bool ignoreSomeObjectsForCamera = false ] )

Required Arguments

  • startX: The start x position
  • startY: The start y position
  • startZ: The start z position
  • radius: The radius of the sphere.

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.

  • ignoredElement: Specifies the element to be excluded from collision detection within the sphere.
  • checkBuildings: Specifies whether buildings should be detected, i.e., elements of the default GTA map or those created using createBuilding.
  • checkVehicles: Specifies whether vehicles should be detected.
  • checkPeds: Specifies whether peds (including players) should be detected.
  • checkObjects: Specifies whether objects should be detected.
  • checkDummies: Specifies whether internal GTA dummies should be detected. These are not used in the current MTA version so this argument can be set to false.
  • ignoreSomeObjectsForCamera: Specifies whether certain elements should be ignored. These are objects that have the (K) property in the 'object.dat' file. (i.e. Most dynamic objects like boxes or barrels).

Returns

The modelID, lodID, worldModelPositionX,Y,Z, worldModelRotationX,Y,Z and entityType parameters are returned even if hitElement is nil.

  • hit: true if there is a collision, false otherwise.
  • hitElement: the MTA element hit if any, nil otherwise.
  • worldModelPositionX,Y,Z: World position of the detected element.
  • worldModelRotationX,Y,Z: World rotation of the detected element.
  • modelID: The ID of the element.
  • lodID: The ID of the element's LOD (or 0).
  • entityType: The type of the element (building, vehicle, ped, object, dummy).

Examples

Accessories-text-editor.png Script Example Missing Function TestSphereAgainstWorld needs a script example, help out by writing one.

Before submitting check out Editing Guidelines Script Examples.


See Also