GM:OnPlayerChat
Description
Called whenever a player sends a chat message. For the serverside equivalent, see GM:PlayerSay.
The text input of this hook depends on GM:PlayerSay. If it is suppressed on the server, it will be suppressed on the client. This also means, that a message surpressed with this hook will be still visible to other clients.
Arguments
Returns
Example
How you could create a clientside only chat command.
hook.Add( "OnPlayerChat", "HelloCommand", function( ply, strText, bTeam, bDead )
if ( ply != LocalPlayer() ) then return end
strText = string.lower( strText ) -- make the string lower case
if ( strText == "/hello" ) then -- if the player typed /hello then
print( "Hello world!" ) -- print Hello world to the console
return true -- this suppresses the message from being shown
end
end )
Output: Prints
Hello world!
to the console when you type /hello
in the chat.