The issue with trying to unlock the door with itself is something that happens when there’s nothing else in the room above a certain priority (not the player, parts of the player, or scenery–not sure what else won’t work) [EDIT: As Hanon just said, ha ha]. If you put a random object in the room where the locked door is, you’ll get the “What do you want to unlock the door with?” message. And if the player is carrying one thing, it will automatically try to have the player unlock the door with that.
I believe zarf has said that he solves this problem by making sure the player always has something in their inventory.
You can eliminate the actual attempt to implicitly take the door like this:
Before implicitly taking a door while unlocking:
say "You don't have anything to unlock [the noun] with."
For implicitly taking a door while unlocking: stop.
The idea being that you never want to be trying to take a door while unlocking, so this can only happen when the parser has chosen to try unlocking something with a door.
Unfortunately this won’t eliminate the “(first taking the door)” message. That’s hard to get rid of, because it’s pretty deep within the parser. If we were talking about the first noun, you could use the Clarifying the Parser’s Choice activity, but that doesn’t run on second nouns, unfortunately. (The thing after the “with” in “unlocking it with.”)
Hanon is right that you could try supplying a missing noun–in this case it’s supplying a missing second noun. This also requires writing an extra grammar line with a missing noun, like this:
Understand "unlock [door]" as unlocking it with. [note that this is one noun short--usually you need to say "unlock [something] with [something]"]
For supplying a missing second noun when unlocking:
say "You'll have to say what to unlock [the noun] with."
The problem is that this will preempt the mechanism for picking a second noun, or asking which do you mean, even when you want it to run. If you don’t mind having the game choose the second noun automatically, you could include an otherwise clause for when the player carries the matching key of the noun and choose that.
For supplying a missing second noun when unlocking:
if the player carries the matching key of the noun:
say "(with [the matching key of the noun])[command clarification break]";
now the second noun is the matching key of the noun;
otherwise:
say "You'll have to say what to unlock [the noun] with."
If you do mind–like figuring out which key unlocks it is a puzzle–then I don’t know if there’s a way to get the “What do you want to unlock the door with?” back after deciding not to print the “You’ll have to say what to unlock it with” message.
FWIW this is the complete compilable code I have to do my stuff:
yard is a room. front hall is a room.
The front door is a locked door. It is north of yard and south of front hall.
A flower is scenery in the yard.
Before implicitly taking a door while unlocking:
say "You don't have anything to unlock [the noun] with."
For implicitly taking a door while unlocking: stop.
The driveway is south of yard. A rock and a key are in the driveway. The key unlocks the front door.
Understand "unlock [door]" as unlocking it with.
For supplying a missing second noun when unlocking:
if the player carries the matching key of the noun:
say "(with [the matching key of the noun])[command clarification break]";
now the second noun is the matching key of the noun;
otherwise:
say "You'll have to say what to unlock [the noun] with."
test me with "unlock door/s/take all/n/unlock door".
Another thing is that the extension Locksmith by Emily Short has lots of convenient stuff involving locks and might help, but I don’t know if it does anything about this particular set of problems.