I'm not sure whether this is actually a bug or a 'feature', but thought I'd bring it up just in case. valid() is a little bit inconsistant when checking for different things; for "command", it returns 1 even if you give it the name of a valid command or a reserved command alias, whereas for "playername" it only returns 1 if %# can @name themself to it (meaning valid names in use by other players return 0). Maybe it could be changed to always return 0 for all types if the arg is otherwise valid but in use, possibly with an extra boolean arg to stop it checking for "in use"?
Would be happy to write the patch myself, but wanted to see if you thought it was worth it first. :)