To clarify, there are two ways of doing this:
1) on OPEN without the ^ prefix and /close -m, eg
on *:open:?: if (something) close -m $nick
2) on OPEN with the ^ prefix and /halt
on ^*:open:?: if (something) halt
The difference is that the first triggers just after the query window is opened, and uses /close -m to close it, thereby causing a flicker on screen, which may be significant if the "Iconify query window" option is not enabled.
The second method triggers before the query window is opened. Using /halt there stops it from opening. The latter method is obviously better as there's no flicker due to window opening/closing.
Of course, there is no need to use both /close -m and /halt in either case.