Gamemode.OnPlayerChat

From GMod Wiki

Jump to: navigation, search
Event Hook
Hook NameOnPlayerChat
SyntaxGM:OnPlayerChat( Player player, String text, Boolean TeamChat, Boolean PlayerIsDead )
DescriptionCalled when a player types and enters a text message.
ReturnsNil
Lua StateNewerShared.png
BBCode[b][url=wiki.garrysmod.com/?title=Gamemode.OnPlayerChat]Gamemode.OnPlayerChat [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]


Examples

DescriptionHow it's defined in the base gamemode
Used onNewerClient.png
Code
 
function GM:OnPlayerChat( ply, strText, bTeamOnly, bPlayerIsDead )
 
	-- I've made this all look more complicated than it is. Here's the easy version
	-- chat.AddText( ply:GetName(), Color( 255, 255, 255 ), ": ", strText )
 
	local tab = {}
 
	if ( bPlayerIsDead ) then
		table.insert( tab, Color( 255, 30, 40 ) )
		table.insert( tab, "*DEAD* " )
	end
 
	if ( bTeamOnly ) then
		table.insert( tab, Color( 30, 160, 40 ) )
		table.insert( tab, "(TEAM) " )
	end
 
	if ( IsValid( ply ) ) then
		table.insert( tab, ply:GetName() )
	else
		table.insert( tab, "Console" )
	end
 
	table.insert( tab, Color( 255, 255, 255 ) )
	table.insert( tab, ": "..strText )
 
	chat.AddText( unpack(tab) )
 
	return true
 
end
OutputN/A


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox