StartChat not being called

I’ve been working on a custom chatbox, which worked fine yesterday. Today when I joined singleplayer again, the default chatbox showed up behind my custom box. I did some debugging and noticed that my StartChat hook wasn’t being called at all. I checked hook.GetTable(), which showed that my hook was the only one in StartChat. Then I tried on other gamemodes, didn’t work. I joined a multiplayer game with custom chatbox installed on the server, but strangely that worked.

I’ve tried completely reinstalling Garry’s Mod, which didn’t work either.

Code used for testing, in autorun/client/startchat.lua:
[lua]
print “Adding hook StartChat”
hook.Add( “StartChat”, “[StartChatTest]”, function( teamChat )
print “StartChat called!”
return true
end )

concommand.Add( “test_startchat”, function( pl, cmd, args )
print( ({ gamemode.Call( “StartChat”, false ) })[1] )
end )
[/lua]

Console log:



Unknown command "sv_rollangle"
Unknown command "sv_unlag_fixstuck"
Lua initialized (Lua 5.1)
Registering gamemode 'sandbox' derived from 'base'
ScriptEnforce is disabled
Executing listen server config file
exec: couldn't exec listenserver.cfg
InitFastCopy: only 51% fast props. Bug?
Lua initialized (Lua 5.1)
Adding hook StartChat
Registering gamemode 'sandbox' derived from 'base'
Sending 267 'User Info' ConVars to server (cl_spewuserinfoconvars to see)
Redownloading all lightmaps
Creating chatbox
Inserting parts
[KotSC] Polly: test //Here the chat text appeared both on my chatbox and the default one
] test_startchat 
StartChat called!
true


Is my Garry’s Mod broken or have I just made some stupid error? :saddowns:

[editline]06:17PM[/editline]

Apparently blocking messagemode in PlayerBindPress caused it, but I need to completely override the old chat, so I solved it by overriding chat.AddText.

It’s not worth overriding chat.AddText, just use **[Gamemode.HUDShouldDraw

http://imgur.com/eJ2Yc.png](wiki.garrysmod.com/?title=Gamemode.HUDShouldDraw)**

Using HUDShouldDraw on the normal chatbox overrides the StartChat hook getting called (Ever) and makes your view spin off when you press the chat button.

Oh god, is that what causes that?!?! Then it won’t let you open console, or hit escape (so you have to ctrl-alt-del :/) ?

Yes. It’s when the coder refuses to properly hook onto the “messagemode” bind using **[Gamemode.PlayerBindPress

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.PlayerBindPress)**

Just return true in StartChat to hide the old chatbox.