After disabling a custom chatbox's hook, view is puched to the upper left of the screen?

Here’s a bit of a tricky one I’m hoping people won’t mind helping me diagnose.

Right now I’m modifying a script which is heavily integrated with a slightly old version of PChat. I noticed that PChat uses a (to me) strange way of starting: it looks for a PlayerBindPress event, and checks to see if the player is pressing there chatbox bind button(s), rather than hooking to StartChat, which is what I wound imagine as the defacto method for hooking a custom chat box.

This is fairly inconvenient for me, since I’d prefer it if the chat box opens on the StartChat hook rather than anything else.

None the less, when I disable the chatbox’s hook for PlayerBindPress (and even move it something else), the normal StartChat hooks are called, but my player’s view is punched to the upper left 45 degrees, and my ability to open the escape menu and console are disabled. I can continually press Y (my chat button) and have my view punched, but the buttons are never enabled again until I kick myself from the server and rejoin.

I’ve already tried looking for anything else in my game mode that uses PlayerBindPress (either by overriding it or hooking it), and the same thing happens when they’re disabled. I’ve also tried removing all addons from the server, same result still.

Can anyone point me in the right direction in terms of what I should be looking for and where?

EDIT: I’ve made a test function that calls the PlayerBindPress hook with the parameters that the chatbox should be expecting, and this works fine, so it’s almost like it’s my key doing something else.

EDIT2: I’ve overridden StartChat from within the chatbox’s code now, and it seems to prevent the viewpunch, although my escape and tilde keys still appear to be disabled.

hey, thanks for using my chatbox :v:

the code is really old, and I’m not quite sure, but I think I used PlayerBindPress because StartChat didn’t always have a parameter for team chat, so I think I had to check the bind in PBP for ‘messagemode2.’

As for the escaping, that was supposed to act like the default chatbox where if you pressed escape it would close the chatbox, but the way I did it was really hacky (like a bunch of other stuff). To fix it, go to Chat.TextEntry.OnKeyCodeTyped function around line 338 and delete the “if(Key == KEY_ESCAPE) then” block.

I really should get around to rewriting it, instead of just updating it whenever it breaks. I did start to rewrite it at one point, but never got around to finishing it. thanks for the support though!

Using PlayerBindPress is preferable to the StartChat hook, because other coders use StartChat (eg, DarkRP uses it)

If the chatbox is using PlayerBindPress, it should also have a hook.Call for StartChat. Other things to watch for are the hooks FinishChat, ChatTextChanged, and OnChatTab, and the function chat.GetChatBoxPos().

Oh wow, of all people to respond first, I never thought the original author would :v: This is great!

You’re absolutely right though, your hook to PlayerBindPress does alternatively check for messagemode2 as well, so I wouldn’t be surprised if StartChat didn’t have extra parameters back then.

So the chatbox actually is coming up, and it’s capturing my input… or something like that? It’s strange because I think the way your chat box was implemented in this particular gamemode, all of the code, for the UI (and essentially back end functionality) is enclosed in a function called DoShit(). I thought I would have been disabling the custom chatbox entirely by stopping DoShit() from being called on start-up. None the less though, I’d really like to take a look where you mentioned when I get the chance. I just wanted to say thanks first when I found a small bit of time :smile:

By the way, I have to admit that your chatbox script looks pretty awesome by browsing through what code I have. I mean, there seems to be URL parsing, image previews, even smilies if I recall (although I might be confusing that with another chatbox). I don’t think I’ve ever seen any of this stuff before in a gamemode, and I’d really like to get it working when I can! Here’s the entire gamemode code thus far, feel free to pick around, whatever helps you out.

[editline]22nd October 2013[/editline]

The thing is though, that’s exactly why I’d like to use StartChat over PlayerBindPress, because other coders (and thus, code) use it as well. That’s a good idea though, I never thought of manually calling StartChat. Thanks for that!

It’s the default chatbox. If you don’t have your hooks stopping it from opening, but still have the hook hiding it, it’ll open in the background and cause a number of issues (most annoying of which is that you can’t open the menu).

Imagine when you’re developing a chatbox, and you accidentally create an error. Suddenly, you can’t open the console to see the error, reload the map, or even disconnect… A nightmare. Thankfully, since autorefresh, you can now disable the hook from the within code, then get everything working again without restarting gmod.

Anyway, if you want the default chatbox back, you’re looking for a “HUDShouldDraw” hook.

oh, I think hat is right, maybe StartChat didn’t want to work with DarkRP, and I do hide the default chatbox in the HideChat function around line 385.
The reason for the DoShit function in a timer is because vgui is nil when client scripts first get loaded, so I put everything in a 0 second timer just to wait a tick for vgui to initialize.
My chatbox did have url parsing, image support, and smiley support (but it was only a base, I left room in OnPlayerChat hook for people to do their own checking and stuff)

I was able to test things out this morning, it turns out the chat hud was being disabled elsewhere in the gamemode, hence why none of the chat huds were appearing :slight_smile: I just had to search for the HUDShouldDraw hook. Thanks guys!