GM:PlayerSay
Description
Called when a player dispatched a chat message. For the clientside equivalent, see GM:OnPlayerChat.
Arguments
3 boolean teamChat
Return false when the message is for everyone, true when the message is for the sender's team.
Returns
Example
Adds a coin flip command to the chat. Player should type /flip
(case-insensitive).
hook.Add( "PlayerSay", "CoinFlip", function( ply, text )
if ( string.lower( text ) == "/flip" ) then
PrintMessage( HUD_PRINTTALK, ply:Nick() .. " flipped the coin and got " .. ( math.random( 2 ) == 1 and "heads" or "tails" ) )
return ""
end
end )
Output:
Player1 flipped the coin and got heads
Example
Adds a symbol counter command to the chat. Player should type /len *text*
(case-insensitive).
hook.Add( "PlayerSay", "CharCount", function( ply, text )
if ( string.StartWith( string.lower( text ), "/len " ) ) then
ply:ChatPrint( "Your message has " .. utf8.len( string.sub( text, 6 ) ) .. " symbol(s)." ) -- We use 6 in string.sub because it's a length of "/len " + 1
return ""
end
end )
Output:
Your message has 5 symbol(s). [When someone typed: "/len Hello"]