Ipquarx beat me to it as well. I don't know too much about scripting, but I could tell there are things that can be done better.
I don't usually complain about file size, but one thing I would also do is replace %chat1, %chat2, %chat3 with something easier like %c1, %c2, %c3. Same with the others.
Also I'm far from an expert but is return; unnecessary in these instances, and can be replaced with if, else if, and else?