I would set it up so each room is room_1, room_2, etc., and each safe is safe_1, safe_2, etc. (in fact I would create a start script to generate the rooms).
Say room_no is the number of the room sent to the function, you can grab the safe object using the GetObject function, then do what you like with it.
safe = GetObject ("safe_" + room_no)
safe.locked = false