If the bad guy has a knife, a baseball bat, or any other weapon that can cause me serious bodily harm and/or death, I would still be justified in using my firearm to defend myself (and/or family members). I could, legally speaking, also defend others, but outside of family, it’d have to be a really clear-cut case, like armed robbery of the store I’m at.
Also, there tends to be a difference in the way one carries oneself while carrying a gun (I prefer concealed, tactical reasons) which encourages criminals to not select the citizen with a gun as a victim (not universally so, but avoidance is preferable to the defensive gun usage). Even people who won’t carry a gun are partially protected when criminals aren’t sure if their potential victim might be armed (40% avoid attacking if they think the person is armed; 60% when they know). Not being a victim of crime is always better than having been a victim.