Friday, September 17, 2021

How Often Do Zombies Hit the Neck?

From what I've seen on streams, lots of Project Zomboid characters run around without any neck protection.  Neck protection is not as common as head or torso protection, so this is understandable.  What I wanted to find out was how often zombie attacks hit a character's neck.  Fortunately, this is in the code.

The BodyDamage class handles this, in the AddRandomDamageFromZombie method.

There are a number of variables can affect this, so let's start by making a few assumptions:

  • The zombie is standing (not crawling)
  • The zombie is attacking you from the front (not from behind)
  • Only 1 zombie is attacking

        if (!isoZombie.bCrawling) {
            n3 = Rand.Next((int)BodyPartType.ToIndex(BodyPartType.Hand_L), (int)(BodyPartType.ToIndex(BodyPartType.Groin) + 1));
            f = 10.0f * (float)n7;
            if (bl2) {
                f += 5.0f;
            }
            if (bl3) {
                f += 2.0f;
            }
            if (bl2 && (float)Rand.Next((int)100) < f) {
                n3 = BodyPartType.ToIndex(BodyPartType.Neck);
            }
            if (n3 == BodyPartType.ToIndex(BodyPartType.Head) || n3 == BodyPartType.ToIndex(BodyPartType.Neck)) {
                n = 70;
                if (bl2) {
                    n = 90;
                }
                if (bl3) {
                    n = 80;
                }
                if (Rand.Next((int)100) > n) {
                    bl = false;
                    while (!bl) {
                        bl = true;
                        n3 = Rand.Next((int)BodyPartType.ToIndex(BodyPartType.MAX));
                        if (n3 != BodyPartType.ToIndex(BodyPartType.Head) && n3 != BodyPartType.ToIndex(BodyPartType.Neck)) continue;
                        bl = false;
                    }
                }
            }
        }

First it picks a random body part between the Left Hand and the Groin.  You can see in the BodyPartType class that there are 11 body parts in between those, and the neck is one of them.

bl2 and bl3 come from being attacked from behind or the side, so we ignore that for this example.  You may notice that if you are attacked from behind (bl2), there is a chance that the hit location gets reassigned to the neck.  So there are more neck hits when you are attacked from behind.  But like I said, we're ignoring attacks from behind or the side for this example.

So if the randomly determined body part is the head or neck, there is a 30% (random 100 roll > 70) chance the target will be forcibly reassigned to be something other than the head or neck.  So there is a 70% chance a neck attack will stay a neck attack.

So, the result is (1/11) * .7 = 6.4%

6.4% of the time, a single zombie attacking from the front will attack the neck.

Because it might be important later (stay tuned), let me also figure out how often a single zombie attacking from the front will attack the neck OR head...

(2/11) * .7 = 12.7%

12.7% of the time, a single zombie attacking from the front will attack the neck or head.


No earth shattering news here, but it's a little interesting.  And I plan on using this information in a future investigation.


Thanks for reading!  If you see a mistake I've made, or if you have any questions you'd like me to answer by looking in the code, let me know!

No comments:

Post a Comment

Do Gloves Protect You From Broken Glass?

Yes, gloves protect you from handling broken glass - any pair of gloves.  But gloves are not needed when removing broken glass from a smashe...