• Chatbox Console Manipulation
    8 replies, posted
Hi there, I am attempting to build a chatbox and I would like to modify what the server console says when a chat goes through (for administration), however I'm not sure which function to use. Right now, I am overriding GM:PlayerSay, but the message I get in console still consists of the player's nick and the message they sent, even though what I'm returning in PlayerSay is different. Thanks for your help!
[QUOTE=pqbrown;52499387]Hi there, I am attempting to build a chatbox and I would like to modify what the server console says when a chat goes through (for administration), however I'm not sure which function to use. Right now, I am overriding GM:PlayerSay, but the message I get in console still consists of the player's nick and the message they sent, even though what I'm returning in PlayerSay is different. Thanks for your help![/QUOTE] Could you elaborate by posting your code?
Not home, so I’ll post something similar. [code] function GM:PlayerSay(ply, text, team) return “[CUSTOM] “ .. ply:Nick() .. “: “ .. text end [/code] You would expect that when somebody chats now, in the console it should say “[CUSTOM] playername: whatever” but it still does “playername: message”
[QUOTE=pqbrown;52499468]Not home, so I’ll post something similar. [code] function GM:PlayerSay(ply, text, team) return “[CUSTOM] “ .. ply:Nick() .. “: “ .. text end [/code] You would expect that when somebody chats now, in the console it should say “[CUSTOM] playername: whatever” but it still does “playername: message”[/QUOTE] You want to use this instead: [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/OnPlayerChat]GM:OnPlayerChat[/url] This is what the hook looks like in the default base gamemode: [lua] --[[--------------------------------------------------------- Name: gamemode:OnPlayerChat() Process the player's chat.. return true for no default -----------------------------------------------------------]] function GM:OnPlayerChat( player, strText, bTeamOnly, bPlayerIsDead ) -- -- I've made this all look more complicated than it is. Here's the easy version -- -- chat.AddText( player, 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( player ) ) then table.insert( tab, player ) else table.insert( tab, "Console" ) end table.insert( tab, Color( 255, 255, 255 ) ) table.insert( tab, ": " .. strText ) chat.AddText( unpack(tab) ) return true end [/lua] You can see that the OnPlayerChat hook is what determines the transition between what the player types, and how it is displayed on screen. PlayerSay is only for changing the message itself, not how it is displayed.
[QUOTE=James xX;52499529]You want to use this instead: [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/OnPlayerChat]GM:OnPlayerChat[/url] This is what the hook looks like in the default base gamemode: [lua] --[[--------------------------------------------------------- Name: gamemode:OnPlayerChat() Process the player's chat.. return true for no default -----------------------------------------------------------]] function GM:OnPlayerChat( player, strText, bTeamOnly, bPlayerIsDead ) -- -- I've made this all look more complicated than it is. Here's the easy version -- -- chat.AddText( player, 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( player ) ) then table.insert( tab, player ) else table.insert( tab, "Console" ) end table.insert( tab, Color( 255, 255, 255 ) ) table.insert( tab, ": " .. strText ) chat.AddText( unpack(tab) ) return true end [/lua] You can see that the OnPlayerChat hook is what determines the transition between what the player types, and how it is displayed on screen. PlayerSay is only for changing the message itself, not how it is displayed.[/QUOTE] Thanks for the quick reply, James. This works quite well for the clientside, however this does not fix my serverside issue. The server console still displays the text in the same fashion: "playername: message". I have even overridden the hook for PlayerSay and returned "" (which worked), but then the client does not receive the intented chat message.
If you use GM:Player say, then you will need to use some networking to make it work clientside as it is serverside, whilst OnPlayerChat is clientside only. So in your way I think it's best to use GM:PlayerSay and then use some networking.
I've thought of this, however the default chat system is already networked. Whatever you return through PlayerSay comes as the "text" parameter in OnPlayerChat. My last resort is to just override all of the default chat networking and do it myself.
Could you perhaps put the code in a pastebin?
[QUOTE=pqbrown;52500244]Thanks for the quick reply, James. This works quite well for the clientside, however this does not fix my serverside issue. The server console still displays the text in the same fashion: "playername: message". I have even overridden the hook for PlayerSay and returned "" (which worked), but then the client does not receive the intented chat message.[/QUOTE] I understand. The chat messages printing in the console are handled by Source IIRC, so you'll either have to put up with it or work around it. One posibility is to return an empty string in [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerSay]GM:PlayerSay[/url], after having broadcast the the player entity, the text string and the team bool using the Net library, and printed the message in the console as you see fit. You could then receive that net message, and call the [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/OnPlayerChat]GM:OnPlayerChat[/url] hook manually using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/hook/Run]hook.Run[/url], where the 4th argument is determined by [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/Alive]Player:Alive[/url] after the "not" opperator
Sorry, you need to Log In to post a reply to this thread.