Jump to content

I dont understand how to work with is ElementInRange


Recommended Posts

Hey,

The function isElementInRange is called a "useful" function because it's not hardcoded but you have to put it in your script.
On the documentation (^) page everything is explained.
You haven't shown us any code where we can see what you tried.

I don't know what your idea is so I'm just gonna give you an example how to use it (taken from the Wiki page).

function playerInRange(player, cmd)
	local x, y, z = 1492, 1444, 0 -- example location coordinates
	if isElementInRange (player, x, y, z, 25) then -- check if the player is near the location; range 25m
		-- do your stuff here
	else
		outputChatBox("You are not in range!", player)
	end
end
addCommandHandler("check", playerInRange)

function isElementInRange(ele, x, y, z, range)
   if isElement(ele) and type(x) == "number" and type(y) == "number" and type(z) == "number" and type(range) == "number" then
      return getDistanceBetweenPoints3D(x, y, z, getElementPosition(ele)) <= range -- returns true if it the range of the element to the main point is smaller than (or as big as) the maximum range.
   end
   return false
end

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...