Is it possible to create a script that outputs text to chat whenever I build a sentry?

I was curious if it was possible to make a script where when I build a sentry it says something like "Sentry up" in chat?


One idea is to do something like this:

bind mouse4 "build 2 0; wait 132; say_team Sentry up!"

This will make it so when you press MOUSE4 (forward on most mice), you'll pull up the diagram for a sentry, wait 132 ticks (2 seconds on most servers), then tell your team "Sentry up!". Note that you would still manually have to place the sentry with MOUSE1, and that the message is not actually tied to placing the sentry, so cancelling (or taking too long) would still result in such a message being sent.

You could also write a more complicated script, where pressing MOUSE4 (or whichever other key) would rebind MOUSE1 to place the sentry and also send the message, but that gets complicated (you'd want to undo this binding if you cancel, and you'd have to manually unbind it if you die during placement). Feel free to try and implement that yourself :-)