Revision Difference
GM:PlayerSay#526584
<function name="PlayerSay" parent="GM" type="hook">
<ishook>yes</ishook>
<description>Called when a player dispatched a chat message. For the clientside equivalent, see <page>GM:OnPlayerChat</page>.</description>
<realm>Server</realm>
<predicted>No</predicted>
<args>
<arg name="sender" type="Player">The player which sent the message.</arg>
<arg name="text" type="string">The message's content</arg>
<arg name="teamChat" type="boolean">Is team chat?</arg>
</args>
<rets>
<ret name="" type="string">What to show instead of original text.⤶
⤶
⤶
Set to "" to stop the message from displaying.</ret>⤶
<ret name="" type="string">What to show instead of original text. Set to "" to stop the message from displaying.</ret>⤶
</rets>
</function>
<example>
<description>Will put "[Global]" in front of the players message if they type "/all " before the message.<br/>⤶
**E.g.** Player 1 types "/all help us all!"</description>⤶
<description>Adds a coin flip command to the chat. Player should type `/flip` (`/FLIP` and `/Flip` will work too)</description>⤶
<code>⤶
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)⤶
</code>⤶
<output>⤶
`Player1 flipped the coin and got heads`⤶
</output>⤶
</example>⤶
⤶
<example>⤶
<description>Adds a symbol counter command to the chat. Player should type `/len *text*`</description>⤶
<code>
hook.Add("PlayerSay", "PlayerSayExample", function( ply, text, team )
-- Split the string into a table ⤶
text = string.Explode( " ", text )
if ( string.lower(text[1]) == "/all" ) then -- Make the command entirely lowercase⤶
-- Combine the table at starting position 2⤶
text = table.concat( text, " ", 2 ) ⤶
return "[Global] " .. text -- add [Global] in front of the players text then display⤶
end⤶
hook.Add("PlayerSay", "CharCount", function( ply, text )
if string.find(string.lower(text),"^/len ") then⤶
ply:ChatPrint("Your message has " .. utf8.len(string.sub(text,6)) .. " symbol(s)")
return ""⤶
end⤶
end)
</code>
<output>
Player 1: [Global] help us all!⤶
`Your message has 5 symbol(s)` when player typed `/len Hello`⤶
</output>
</example></example>⤶
⤶