instead of holding complicated, here's a simple code that works as AUTOGHOST, using your alternate nick on mIRC.
When someone else is using your nickname or have a bad connection, and you're using mIRC, the program automatically connects you with your alternative nickname, that lets you kill the ghost.
ON *:CONNECT: {
if ($nick == NickBot_ ) { .ns ghost NickBot password | .nick NickBot }
elseif ($nick != NickBot) { .ns ghost NickBot password | .nick NickBot }
}