Well, I'll give you the some commands you need to do the script.
It's up to you to find out how to use them.
Comments behind a // are not read by the script, so you can put info in there.
NPC Code:
if (created) //When the NPC is first made.
if (playertouchsme) //When the player touches the NPC
if (playerchats) { //The Player Says Something
if (strequals(#c,TheWordToOpenTheDoor) //The player says a specific thing/
if (strequals(#c,TheWordToCloseTheDoor) //Ditto
}