kowixd 0 Posted March 21, 2018 Hello have local chat in freeroam server I am new at this I try to make it look in one dimension. For example, if I am in dimension 5, only those in dimension 5 can see it Help please chat_range=100 addEventHandler("onPlayerJoin",getRootElement(), function () bindKey(source,"u","down","chatbox","Local") end) addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), function () for index, player in pairs(getElementsByType("player")) do bindKey(player,"u","down","chatbox","Local") end end) function isPlayerInRangeOfPoint(player,x,y,z,range) local px,py,pz=getElementPosition(player) return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range end function onChat(player,_,...) local px,py,pz=getElementPosition(player) local dm = getElementDimension(player) local msg = table.concat({...}, " ") local nick=getPlayerName(player) local r,g,b = getPlayerNametagColor(player) for _,v in ipairs(getElementsByType("player")) do if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then outputChatBox("(Local) "..nick..": "..msg,v,r,g,b,true) end -- outputServerLog("(Local) "..nick..": "..msg,true) end end addCommandHandler("Local",onChat) Share this post Link to post
WorthlessCynomys 82 Posted March 21, 2018 (edited) chat_range=100 addEventHandler("onPlayerJoin",getRootElement(), function () bindKey(source,"u","down","chatbox","Local") end) addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), function () for index, player in pairs(getElementsByType("player")) do bindKey(player,"u","down","chatbox","Local") end end) function isPlayerInRangeOfPoint(player,x,y,z,range) local px,py,pz=getElementPosition(player) return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range end function onChat(player,_,...) local px,py,pz=getElementPosition(player) local dm = getElementDimension(player) local msg = table.concat({...}, " ") local nick=getPlayerName(player) local r,g,b = getPlayerNametagColor(player) for _,v in ipairs(getElementsByType("player")) do if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then outputChatBox("(Local) "..nick..": "..msg,v,r,g,b,true) end -- outputServerLog("(Local) "..nick..": "..msg,true) end end addCommandHandler("Local",onChat) Next time use the this code thing. It's the "<>" button. You have to use a for iteration btw, where you get the dimension of the players nearby (or all the players) and make an if that checks if the players' dimension is the same. If it is, only then do the outputChatBox for that player. getElementDimension return the dimension an element is in. Edited March 21, 2018 by WorthlessCynomys Share this post Link to post
kowixd 0 Posted March 24, 2018 On 21/3/2018 at 09:29, WorthlessCynomys said: chat_range=100 addEventHandler("onPlayerJoin",getRootElement(), function () bindKey(source,"u","down","chatbox","Local") end) addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), function () for index, player in pairs(getElementsByType("player")) do bindKey(player,"u","down","chatbox","Local") end end) function isPlayerInRangeOfPoint(player,x,y,z,range) local px,py,pz=getElementPosition(player) return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range end function onChat(player,_,...) local px,py,pz=getElementPosition(player) local dm = getElementDimension(player) local msg = table.concat({...}, " ") local nick=getPlayerName(player) local r,g,b = getPlayerNametagColor(player) for _,v in ipairs(getElementsByType("player")) do if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then outputChatBox("(Local) "..nick..": "..msg,v,r,g,b,true) end -- outputServerLog("(Local) "..nick..": "..msg,true) end end addCommandHandler("Local",onChat) Next time use the this code thing. It's the "<>" button. You have to use a for iteration btw, where you get the dimension of the players nearby (or all the players) and make an if that checks if the players' dimension is the same. If it is, only then do the outputChatBox for that player. getElementDimension return the dimension an element is in. Can you explain me more please? what do you mean by "for iteration btw" Sorry, I'm still starting on this Share this post Link to post
^iiEcoo'x_) 619 Posted March 24, 2018 chat_range=100 addEventHandler("onPlayerJoin",getRootElement(), function () bindKey(source,"u","down","chatbox","Local") end) addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), function () for index, player in pairs(getElementsByType("player")) do bindKey(player,"u","down","chatbox","Local") end end) function isPlayerInRangeOfPoint(player,x,y,z,range) local px,py,pz=getElementPosition(player) return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range end function onChat(player,_,...) local px,py,pz=getElementPosition(player) local dm = getElementDimension(player) local msg = table.concat({...}, " ") local nick=getPlayerName(player) local r,g,b = getPlayerNametagColor(player) for _,v in ipairs(getElementsByType("player")) do if ( getElementDimension ( v ) == 5 ) then if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then outputChatBox("(Local) "..nick..": "..msg,v,r,g,b,true) end end -- outputServerLog("(Local) "..nick..": "..msg,true) end end addCommandHandler("Local",onChat) Share this post Link to post
Pirulax 78 Posted March 24, 2018 (edited) --> client bindKey("b", "down", "chatbox", "Local") --> server local CHAT_RANGE = 100--> meters local function localChat(source, _, ...) local dm = getElementDimension(source) local msg = "(Local) "..(getPlayerName(source) or "Unknown")..": "..table.concat({...}, " ") local r, g, b = getPlayerNametagColor(source) local sourceDim = getElementDimension(source) local sourcePos = Vector3(getElementPosition(source)) for _, player in pairs(getElementsByType("player")) do if (getElementDimension(player)==sourceDim) then if (getDistanceBetweenPoints3D(sourcePos, getElementPosition(player))<=CHAT_RANGE) then --If hes in the same dimension as the source[player] outputChatBox(msg, player, r, g, b, true)--> It will output the msg to chatbox with colorcodes[So, if he types #10FFFF, then it will be a redish text.]. Set 'true' to 'false' to disable this. end end end end addCommandHandler("local", localChat, false, false) addCommandHandler("Local", localChat) Edited March 24, 2018 by Pirulax 1 Share this post Link to post
kowixd 0 Posted March 24, 2018 13 hours ago, DABL said: chat_range=100 addEventHandler("onPlayerJoin",getRootElement(), function () bindKey(source,"u","down","chatbox","Local") end) addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), function () for index, player in pairs(getElementsByType("player")) do bindKey(player,"u","down","chatbox","Local") end end) function isPlayerInRangeOfPoint(player,x,y,z,range) local px,py,pz=getElementPosition(player) return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range end function onChat(player,_,...) local px,py,pz=getElementPosition(player) local dm = getElementDimension(player) local msg = table.concat({...}, " ") local nick=getPlayerName(player) local r,g,b = getPlayerNametagColor(player) for _,v in ipairs(getElementsByType("player")) do if ( getElementDimension ( v ) == 5 ) then if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then outputChatBox("(Local) "..nick..": "..msg,v,r,g,b,true) end end -- outputServerLog("(Local) "..nick..": "..msg,true) end end addCommandHandler("Local",onChat) thanks but, it only makes it look in the dimension 5 4 hours ago, Pirulax said: --> client bindKey("b", "down", "chatbox", "Local") --> server local CHAT_RANGE = 100--> meters local function localChat(source, _, ...) local dm = getElementDimension(source) local msg = "(Local) "..(getPlayerName(source) or "Unknown")..": "..table.concat({...}, " ") local r, g, b = getPlayerNametagColor(source) local sourceDim = getElementDimension(source) local sourcePos = Vector3(getElementPosition(source)) for _, player in pairs(getElementsByType("player")) do if (getElementDimension(player)==sourceDim) then if (getDistanceBetweenPoints3D(sourcePos, getElementPosition(player))<=CHAT_RANGE) then --If hes in the same dimension as the source[player] outputChatBox(msg, player, r, g, b, true)--> It will output the msg to chatbox with colorcodes[So, if he types #10FFFF, then it will be a redish text.]. Set 'true' to 'false' to disable this. end end end end addCommandHandler("local", localChat, false, false) addCommandHandler("Local", localChat) It works, thank you!! Share this post Link to post
Pirulax 78 Posted March 28, 2018 Consider dopping me a like at my comment(s) @kowixd Share this post Link to post
Pirulax 78 Posted March 30, 2018 local CHAT_RANGE = 100--> meters local function localChat(source, _, ...) if not (...) then return end local dm = getElementDimension(source) local msg = "(Local) "..(getPlayerName(source) or "Unknown")..": "..table.concat({...}, " ") local r, g, b = getPlayerNametagColor(source) local sourceDim = getElementDimension(source) local sourcePos = Vector3(getElementPosition(source)) for _, player in pairs(getElementsByType("player")) do if (getElementDimension(player)==sourceDim) then if (getDistanceBetweenPoints3D(sourcePos, getElementPosition(player))<=CHAT_RANGE) then --If hes in the same dimension as the source[player] outputChatBox(msg, player, r, g, b, true)--> It will output the msg to chatbox with colorcodes[So, if he types #10FFFF, then it will be a redish text.]. Set 'true' to 'false' to disable this. end end end end addCommandHandler("local", localChat, false, false) addCommandHandler("Local", localChat) @kowixd Use this instead please, i've forgot something. 1 Share this post Link to post
kowixd 0 Posted March 30, 2018 5 hours ago, Pirulax said: local CHAT_RANGE = 100--> meters local function localChat(source, _, ...) if not (...) then return end local dm = getElementDimension(source) local msg = "(Local) "..(getPlayerName(source) or "Unknown")..": "..table.concat({...}, " ") local r, g, b = getPlayerNametagColor(source) local sourceDim = getElementDimension(source) local sourcePos = Vector3(getElementPosition(source)) for _, player in pairs(getElementsByType("player")) do if (getElementDimension(player)==sourceDim) then if (getDistanceBetweenPoints3D(sourcePos, getElementPosition(player))<=CHAT_RANGE) then --If hes in the same dimension as the source[player] outputChatBox(msg, player, r, g, b, true)--> It will output the msg to chatbox with colorcodes[So, if he types #10FFFF, then it will be a redish text.]. Set 'true' to 'false' to disable this. end end end end addCommandHandler("local", localChat, false, false) addCommandHandler("Local", localChat) @kowixd Use this instead please, i've forgot something. ok, thanks Share this post Link to post