Building codes do definitely play a role. A lot of them are written in reaction to some tragedy (fire, earthquake, structural failure, etc). Here's an interesting assertion:
"the biggest potential saving of lives in rural areas lies in compliance with better building standards, so that homes and schools do not collapse so easily"
(https://www.scmp.com/comment/insight-opinion/article/2106507...)