Jump to content

Chat Radius


Hugos

Recommended Posts

Posted

Hello. Tell me how to make a chat only in a certain radius? For example, 10 meters from the player who writes.
 

Говорю на русском. Sorry for bad english.
 

Posted

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

 

* There is No God but Allah

discord: HassoN#2709

Visit my wiki profile: https://wiki.multitheftauto.com/wiki/User:Hassan_saad

13319665721.gif

Posted
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!

Говорю на русском. Sorry for bad english.
 

Posted
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

 

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...