Garry's Mod Wiki

Revision Difference

GM:PlayerSay#526580

<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> </rets> </function> <example> <description>Will put "[Global]" in front of the players message if they type "/all " before the message.</description>⤶ <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>⤶ <code> hook.Add("PlayerSay", "PlayerSayExample", function( ply, text, team ) -- Make the chat message entirely lowercase⤶ if ( string.sub(string.lower( text ),1,4) == "/all" ) then⤶ return "[Global] " .. string.sub( text, 5 ) -- add [Global] in front of the players text then display⤶ end⤶ -- 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⤶ end) </code> ⤶ </example> <output>⤶ Player 1: [Global] help us all!⤶ </output>⤶ </example>