In a text adventure, use the command "finish", which generates a game over message. However, note that any other scripts that are running may still finish and display more output before the end of the turn.
In a gamebook, you can simply create a game over page which doesn't have any links anywhere else.
One, create a game over room where all the stats are returned to 0, and the player's items are all taken.
Two, use the Finish function.