Garry's Mod Wiki

GM:PlayerSay

string GM:PlayerSay( Player sender, string text, boolean teamChat )

Description

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

Arguments

1 Player sender
The player which sent the message.
2 string text
The message's content
3 boolean teamChat
Is team chat?

Returns

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

Example

Adds a coin flip command to the chat. Player should type /flip (/FLIP and /Flip will work too)

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*

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)") -- 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 player typed /len Hello

Page Links


Special Pages


Wikis

?

Render Time: 42ms

DB GetPage 4
Generate Html 7
SaveChanges (1) 22
Render Body 0
Render Sidebar 7