Dimos7 Posted March 5, 2017 Share Posted March 5, 2017 (edited) hello i make a me chat the them is have and default and mine me when do /me also when do that the message apear at the default not mine help please chat_range=30 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 msg = table.concat({...}, " ") local nick=getPlayerName(player) for _,v in ipairs(getElementsByType("player")) do if isPlayerInRangeOfPoint(v, px, py, pz, chat_range) then outputChatBox("* "..nick.." "..msg,v,182,100,127,true) end end outputServerLog("* "..nick.." ".. msg) end addCommandHandler("me",onChat) addEventHandler("onPlayerChat", root, function(message, messageType) if messageType == 1 then onChat(source, message) end end) Edited March 5, 2017 by Dimos7 1 Link to comment
pa3ck Posted March 5, 2017 Share Posted March 5, 2017 You have to cancel the onPlayerChat event after the if statement like so: addEventHandler("onPlayerChat", root, function(message, messageType) if messageType == 1 then cancelEvent() onChat(source, message) end end) Link to comment
Dimos7 Posted March 5, 2017 Author Share Posted March 5, 2017 i did that but the them is the message not apear on my me chat 1 Link to comment
Bonsai Posted March 5, 2017 Share Posted March 5, 2017 Remove the "me" command handler and fix the parameters of the "onChat" function. Link to comment
Dimos7 Posted March 5, 2017 Author Share Posted March 5, 2017 what parameters to chnage? i have same problem and with say:D apear default and mine i try make it like that and still apear after have cancelEvent 1 Link to comment
Dimos7 Posted March 5, 2017 Author Share Posted March 5, 2017 chat_range=50 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 msg = table.concat({...}, " ") local players = getPlayerName(player) nick = tostring ( players ):gsub( "_", " " ); for _,v in ipairs(getElementsByType("player")) do if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then outputChatBox(""..nick.." says: "..msg,v,255,255,255,true) end end outputServerLog("[IC]: "..nick.." says: ".. msg) end addEventHandler("onPlayerChat", root, function(message, messageType) if messageType == 0 then cancelEvent() onChat(source, _, message) end end) Link to comment
Mr.Loki Posted March 6, 2017 Share Posted March 6, 2017 5 hours ago, Dimos7 said: 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 Why not just getDistanceBetweenPoints3D? function inRange(player,x,y,z,range) local isInRange = getDistanceBetweenPoints3D(x,y,z,getElementPosition(player)) <= range and true or false return isInRange end 1 Link to comment
Dimos7 Posted March 6, 2017 Author Share Posted March 6, 2017 its the same now i want know why post my test twice in deafult and mine 1 Link to comment
Bonsai Posted March 6, 2017 Share Posted March 6, 2017 How can this be so hard. If you use cancelEvent() the message will not appear in chat. Then you have to use your own function which outputs it in chat instead. Just do some tests until you find out whats wrong. Remove your own function and check if the messages still appear in chat even with cancelEvent(). If so, then you maybe have another function outputting it to the chat. 1 Link to comment
Dimos7 Posted March 6, 2017 Author Share Posted March 6, 2017 yes it apear the message and not have something outpouts 1 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