Jump to content

chat


Recommended Posts

function chatDetect(message,mstype, ...)
if mstype == 1 then
sendMessage(source,"me",message)
cancelEvent()
--
if ... then
outputChatBox ( "not message", v, 255, 125, 125, true )
end
--
end
end
addEventHandler("onPlayerChat",root,chatDetect)

function sendMessage ( player, cmd, ... )
		local message = table.concat( {...}, " ")
		for i, v in ipairs ( getElementsByType( "player" ) ) do
			local x, y, z = getElementPosition ( player )
			local xt, yt, zt = getElementPosition ( v )
			if getDistanceBetweenPoints3D ( x, y, z, xt, yt, zt ) <= 10 then
				outputChatBox ( "** "..message.." ("..getPlayerName(player)..")", v, 255, 125, 125, true )
			end
		end
end

how do I do when a command is entered without a message, it writes an error?

like this: 

1) /me

2) /me hello

1 - need output error (not message)

2 - it's ok

Link to comment
1 hour ago, Tekken said:

Try: 




if not message or message == "" then
    --need to supply more info;
end

 

@Tekken Thank you for your responsiveness, but not working.

Any other suggestions?

function chatDetect(message,mstype, ...)
if mstype == 1 then
sendMessage(source,"me",message)
cancelEvent()
end
end
addEventHandler("onPlayerChat",root,chatDetect)

function sendMessage(player,cmd,...)
local distance
local x,y,z = getElementPosition(player)
local nick = getPlayerName(player)
local message = table.concat( {...}, " ")
if ... then --With this line, I solved the problem, but not for "me";
if cmd == "me" then
outputChatBox("* "..nick.." "..message,player,247,97,224,false)
elseif cmd == "do" then
outputChatBox("* "..nick.." "..message,player,247,97,224,false)
end
else
outputChatBox ( "not message", player, 255, 125, 125, true )
end
end
addCommandHandler("do",sendMessage)

@Tekken

I found a solution like this, but it doesn't work for the command "me"

For the command "do" works but for "me" not working.

As I understand it, this is due to the fact that the command "me" Already automatically created in the mta itself but "do" i create with addCommandHandler.

How can I solve this problem?

Edited by oggygod
Link to comment

Well, the command "me" is hardcoded and it doesn't trigger the onPlayerChat event if no text was written.
So you can't detect that.
Except if there are 2 or more SPACEs in the input.

And also unfortunately (but probably for security reasons) you can't get the arguments used in a command from onPlayerCommand event so this is not a variant as well.

So I don't think you can check if the "me" message is empty.

Edited by SpecT
  • Like 1
Link to comment

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