Hugos Posted August 2, 2019 Share Posted August 2, 2019 Hello. Tell me how to make a chat only in a certain radius? For example, 10 meters from the player who writes. Link to comment
HassoN Posted August 2, 2019 Share Posted August 2, 2019 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
Hugos Posted August 2, 2019 Author Share Posted August 2, 2019 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 ds1-e Posted August 2, 2019 Scripting Moderators Share Posted August 2, 2019 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now