local math = _G.math or {}; local Distance = {} local Element = _G.Element or {} function Distance:Get2D(x1, y1, x2, y2) local dx = x1 - x2 local dy = y1 - y2 return math.sqrt(dx * dx + dy * dy) end function Distance:Get3D(x1, y1, z1, x2, y2, z2) local half2 = 1 / 2 local vectorX, vectorY, vectorZ = x2 - x1, y2 - y1, z2 - z1 return ((vectorX * vectorX) + (vectorY * vectorY) + (vectorZ * vectorZ)) ^ half2 end Element.getDistance2D = function(Element, x, y) assert(isElement(Element), 'Element is not a valid element') local x2, y2 = getElementPosition(Element) return Distance:Get2D(x, y, x2, y2) end Element.getDistance3D = function(Element, x, y, z) assert(isElement(Element), 'Element is not a valid element') local x2, y2, z2 = getElementPosition(Element) return Distance:Get3D(x, y, z, x2, y2, z2) end Element.getDistanceFromElement3D = function(Element, Element2) assert(isElement(Element), 'Element is not a valid element') assert(isElement(Element2), 'Element2 is not a valid element') local x, y, z = getElementPosition(Element) local x2, y2, z2 = getElementPosition(Element2) return Distance:Get3D(x, y, z, x2, y2, z2) end Element.getDistanceFromElement2D = function(Element, Element2) assert(isElement(Element), 'Element is not a valid element') local x, y = getElementPosition(Element) local x2, y2 = getElementPosition(Element2) return Distance:Get2D(x, y, x2, y2) end hasGroundAbove = function (Element, Dist, Height) assert(isElement(Element), 'Element is not a valid element') local Position = { getElementPosition(Element) } if (type(Position) ~= "table" or #Position ~= 3) then return false, 'Position is not a valid table' end local TargetGroundPosition = getGroundPosition(Position[1], Position[2], Position[3]) local TargetGroundOnTopPosition = getGroundPosition(Position[1], Position[2], Position[3] + (Height or 40)) if (type(TargetGroundPosition) ~= "number" or type(TargetGroundOnTopPosition) ~= "number") then return false, 'Ground positions are not numbers' end if (math.abs(TargetGroundPosition - TargetGroundOnTopPosition) > (Dist or 2)) then return true, 'Target has ground above' end return false, 'Target does not have ground above' end function getDistance2D(...) return Distance:Get2D(...) end function getDistance3D(...) return Distance:Get3D(...) end function getElementDistanceFromElement3D(Element, Element2) return Element:getDistanceFromElement3D(Element2) end function getElementDistanceFromElement2D(Element, Element2) return Element:getDistanceFromElement2D(Element2) end function getElementDistance2D(Element, x, y) return Element:getDistance2D(x, y) end function getElementDistance3D(Element, x, y, z) return Element:getDistance3D(x, y, z) end function isPositionBetween(posX, posY, posZ, x1, y1, z1, x2, y2, z2, Tolerance) Tolerance = Tolerance or 0.01 local ABx, ABy, ABz = x2 - x1, y2 - y1, z2 - z1 local APx, APy, APz = posX - x1, posY - y1, posZ - z1 local abLenSq = ABx^2 + ABy^2 + ABz^2 local dot = APx * ABx + APy * ABy + APz * ABz local t = dot / abLenSq if (t < - Tolerance or t > 1 + Tolerance) then return false end return getDistance3D(posX, posY, posZ, x1 + ABx * t, y1 + ABy * t, z1 + ABz * t) <= Tolerance end return Distance;