$chan has no value in a raw event, therefor they get redirected to your status window. Replace all instances of $chan with $2 . And where exactly the haltdef is located in the code is irrelevant, mIRC will execute it anywhere and then move on to the next line, unlike halt which generally is the last line because it stops execution of the script. Haltdef does not.