Garry's Mod Wiki

GM:OnPlayerChat

  boolean GM:OnPlayerChat( Player ply, string text, boolean teamChat, boolean isDead )

Description

Called whenever a player sends a chat message. For the serverside equivalent, see GM:PlayerSay.

The input (or suppression) of this hook is based on the output from GM:PlayerSay. Chat events suppressed serverside do not call this hook.

Arguments

1 Player ply
The player
2 string text
The message's text
3 boolean teamChat
Is the player typing in team chat?
4 boolean isDead
Is the player dead?

Returns

1 boolean
Should the message be suppressed?

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.