all you do is make the npc have dialog for each name. then you click the text get the action id. go to actionhandler and under that action add in a code like
if(c.playerTitle == 0) {
c.playerTitle = (or == not sure writing as i go) #;
} else {
c.sendMessage("you already have a title!");
}
}
thats the basic format of the code youll probally have to change since i didnt compile it.
This makes it so if you title is 0 then it can change, else if it has a number send a message and not change the title.