GM:PlayerSay

From Garry's Mod
Jump to: navigation, search
 GM:PlayerSay( )

Contents

Description

Called when a player dispatched a chat message. For the clientside equivalent, see GM:OnPlayerChat.

Arguments

Player sender

The player which sent the message.

Arguments

string text

The message's content

Arguments

boolean teamChat

Is team chat?

Returns

string

What to show instead of original text.
Set to "" to stop the message from displaying.

Examples

Example

Will put "[Global]" in front of the players message if they type "/all" as the first letters in the chat message

hook.Add("PlayerSay", "PlayerSayExample", function( ply, text, team )
	if ( string.sub( text, 1, 4 ) == "/all" ) then -- if the first four characters of the string are /all
		return "[Global] " .. string.sub( text, 5 ) -- add [Global] in front of the players text then display
	end
end)


Examples

Example

Create a chat command to kill the player who said it

hook.Add( "PlayerSay", "Killurself", function(ply, text, public)
	text = string.lower(text) -- Make the chat message entirely lowercase
	if ( text == "!kill" ) then
		ply:Kill()
		return ""
	end
end)


Personal tools
Navigation