Jump to content

me chat


Dimos7

Recommended Posts

Posted (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 by Dimos7
  • Like 1
Posted

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)

 

Posted

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

 

  • Like 1
Posted
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)

 

Posted

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.

 

  • Like 1

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