Jump to content

Chat Radius


Hugos

Recommended Posts

Hey,

You could use a loop of all players, get their positions and compare it to the player who uses the chat, if it is 10 meters away or less from the player then show the message.

Something like:

for i, v in ipairs(getElementsByType("player")) do
	local x, y, z = getElementPosition(v)
	local x2, y2, z2 = getElementPosition(player) -- player represents the player who triggered the chat command.
	local distance = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
	if (distance <= 10) then
		outputChatBox("YOUR MESSAGE", v)
	end
end

 

Link to comment
Just now, HassoN said:

Hey,

You could use a loop of all players, get their positions and compare it to the player who uses the chat, if it is 10 meters away or less from the player then show the message.

Something like:


for i, v in ipairs(getElementsByType("player")) do
	local x, y, z = getElementPosition(v)
	local x2, y2, z2 = getElementPosition(player) -- player represents the player who triggered the chat command.
	local distance = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
	if (distance <= 10) then
		outputChatBox("YOUR MESSAGE", v)
	end
end

 

Thanks!

Link to comment
  • Scripting Moderators
2 hours ago, Hugos said:

Thanks!

You might use int loop version of it, if you're considered about performance.

local players = getElementsByType("player")
for i = 1, #players do
	local playerr = players[i]
	local x, y, z = getElementPosition(playerr)
	local x2, y2, z2 = getElementPosition(player) -- player represents the player who triggered the chat command.
	local distance = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
	if (distance <= 10) then
		outputChatBox("YOUR MESSAGE", playerr)
	end
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...