IsElementInRange

From Multi Theft Auto: Wiki
Revision as of 21:36, 3 August 2012 by Ken Xeiko (talk | contribs) (Created page with "__NOTOC__ {{Useful Function}} This function allows you to find out is the element in range of the main point. ==Syntax== <syntaxhighlight lang="lua"> bool isElementInRange( element theElement,...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This function allows you to find out is the element in range of the main point.

Syntax

bool isElementInRange( element theElement, float x, float y, float z, fload range )

Required Arguments

  • theElement: the element whose range we want to check.
  • x: the x coordinate of the main point.
  • y: the y coordinate of the main point.
  • z: the z coordinate of the main point.
  • range: the range of the main point to the element.

Returns

  • Returns true if the element is in range of the main point, false otherwise.

Code

Click to collapse [-]
Function source
function isElementInRange(element, x, y, z, range)
   if element and x and y and z and range then
      local px,py,pz = getElementPosition (player)
      return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5 <= range -- returns true if it the range of the element to the main point is smaller than (or as big as) the maximum range.
   else
      return false
   end
end
 
end