hey so the 3 digit code there is a puzzle, there is a note in one of the bathrooms in the first floor, its randomised, you have to read the note and solve it, then go to the second floor which the code puzzle will be solved there, then you can proceed to the basement door. you did not lose the gun, there is a section after the basement where you will get the gun.