Project Zomboid

Project Zomboid

68 ratings
The Short Guide
By Undefined
A look at some of the lesser known Project Zomboid mechanics, backed up by code. I might also answer any questions that you might have if the answer is not well known.
5
2
3
4
2
   
Award
Favorite
Favorited
Unfavorite
Tree Chopping
Tree Chopping Timed Action is bugged and will roll twice for chance to lower your weapon's condition (source)[pastebin.com]

Right click > Cut Down Tree will lower your weapon's condition faster than if you had manually chopped down the tree yourself.

This is because the Timed Action for chopping trees (ISChopTreeAction.animEvent) calls the IsoTree.weaponHit java method, which has its own roll for lowering your weapon's condition, and then ISChopTreeAction.animEvent rolls to lower your weapon's condition right after.

To work around this, you can either chop trees manually or download my mod, Tree Chop Bug Fix.

https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2880299874

Tree Chopping weapon condition loss works differently than combat weapon condition loss (source)[pastebin.com]

This is aside from ISTreeChopAction.animEvent's second roll to lower your weapon's condition.

Axes have lower chance of losing condition while non-Axe weapons have a higher chance.

The formula is as follows:
// Axe Weapons WeaponConditionLowerChance * 2 + MaintenanceMod // Non-Axe Weapons WeaponConditionLowerChance / 2 + MaintenanceMod
Farming - Diseases
Devil's Water Fungi can be cured (source)[pastebin.com]

I added this to the wiki recently, so I'll just repost what I wrote.

To cure DWF, the plant must be dehydrated below 10% of the Minimum Water level.

Take, for example, a Potato plant that requires at least 65 units of water. 10% of 65 is 59, always rounded down. That is, 65 / 1.1 = 59. Therefore, your Potato plant must be below 59 units of water for Devil's Water Fungi to begin to cure. It will cure at a rate of 2 points for every interval the plant consumes water (default is 5 hours). Depending on the growth stage of the plant, if you choose not to build a shelter over the plant to avoid rain, it may be best to dig up the plant and start over, or harvest it if it's ready, as DWF can spread to other plants.

Plant disease is random (source)[pastebin.com]

The odds are 1% per disease and they increase for each unit of water below the plant's minimum water level. Each disease gets its own roll for a chance to infect the plant, so it's a 3% base chance in total.

The developer intended for the base risk to be 2% per disease and then an additional 1% for each unit of water below the plant's minimum water level, but it actually ends up being a base risk of 1% with minor increments for each unit of water below the minimum water level, at least in the beginning. This is due to how the roll for diseases was implemented.

Rather than doing the following, for example:

if (ZombRand(100) < chance) { -- Plant is infected }

The roll was written as such:

local risk = ZombRand(chance, 101) if (risk == 99) { -- Plant is infected }

In the first example, we're checking for multiple numbers. For instance, if chance was 2, we'd check if the result was less than two, which includes values of 0 and 1. By checking for two numbers within a range of 100 numbers, this would give us a 2% chance for disease (i.e., 2 / 100 = 2%)

In the second example, we're only checking for one number. For instance, if chance is 2, we'd first acquire the value of the range (101 - chance = 99), then we'd check for only one number against the value of the range (e.g., 1 / 99 = 1.01%).

Diseases only spread to plants adjacent to the infected plant (source)[pastebin.com]

Therefore, keeping your plants separated by one tile will prevent spreading of disease.

Some people have speculated that it's two tiles, but the game only checks for diseased plants adjacent to the plant in question.

The way the check is performed, whenever a plant enters a new growth phase, it will roll for diseases and check for the infection status of neighboring plants. If a neighboring plant is infected with either Devil's Water Fungi or Mildew, the plant in question will roll again for a chance to contract a disease.

Chance for diseases are rolled on every new growth phase aside from seedling (source)[pastebin.com]

Not much to say here other than you don't need to check for diseases as often as you probably normally would.
Vehicles - Car Key Spawn
Car keys have a chance to spawn on the car door (source)[pastebin.com]

Many people are missing out on this one because it's very unintuitive.

In order for this spawn to work, the car must spawn with the doors unlocked (broken locks don't matter, trunks don't count).

To check if the keys to a car are on the door.
  1. Go inside the car
  2. Lock all the doors
  3. Exit the car and try opening a door that is locked.
If the keys were on the door, you will open the door, enter the vehicle, and the keys will now be in your inventory.

Car Key Spawn Locations and Chances (source)[pastebin.com]

Car Keys can be found in:
  • The Car Door*
  • The Glovebox*
  • The Ignition*
  • In a container of type Counter, Office Drawer, Shelf, or Desk, within a 10x10 Grid "Radius" from center of vehicle
  • On a zombie that spawned within a 10x10 Grid "Radius" from center of vehicle
  • A player-accessible tile within a 10x10 Grid "Radius" from center of vehicle
*Only if car spawned with at least one door unlocked (broken locks don't disqualify)

Flowchart explaining the chances for the car keys to spawn

Vehicles - Gas Consumption
Factors Affecting Gas Consumption (source)[pastebin.com]
  • Vehicle Weight (heavier = more gas, but only when the car is accelerating)
  • Heater (bugged, off = more gas)
  • Engine Quality (lower = more gas, a penalty from 0 to 49.5% for Engine Quality from 100 to 1)
  • Delta from current speed to next gear switch speed (further = more gas)
  • RPM (higher = more gas)
  • Speed (faster = more gas)
  • Gas Tank condition (if less than 70%, 1 in (condition * 2) chance to roll for gas loss)

Using the Heater results in less gas consumption
(source)[pastebin.com]

The following video displays the amount of fuel to be deducted from the gas tank (newAmount).

At first, the Heater is off, displaying a value of 0.0015. When the Heater is turned on, the amount of fuel to be deducted is reduced to 0.0014.

I came across this bug when recreating the gas consumption formula in a spreadsheet and confirmed it in game.

Vehicles - Battery
Battery Drainage / Charging (source)[pastebin.com]

Starting a car drains 2.5% of the battery.

The battery is recharged by a tenth of a percent for every minute that passes by, or 1% every 10 minutes.

Therefore, it takes 25 minutes to undo the battery drain of starting a car. This is important to know in case you've been starting / stopping your car a lot as you could be left stranded if you're not paying attention (it happened to me one time).
Generators
Generators can charge a car's battery (source)[pastebin.com]

NOTE: As of 41.73, this feature was removed from the game.

So long as the battery is installed in the car, the car is not running, and the car is within the Generator's radius, the Generator will charge the car's battery.

This is great for parking lots where you can drop a generator, leave it running overnight (or as soon as the car has more than 10% charge), and have multiple cars with their batteries charged.

Considering the rarity of a Car Battery Charger compared to a Generator, the Generator makes for a suitable alternative to charging batteries.


Generators have a chance to catch fire or explode when its condition reaches 20% (source)[pastebin.com]

While many people are aware that Generators can catch fire or explode when its condition deteriorates, there's debate as to when that can occur, and quite a few people have stated that it's 50%, which is incorrect.

Once a Generator's condition reaches 20% or lower, there's a 10% chance to catch fire and a 5% chance to explode.

Generators have a 3.33% chance to lose 1-2% condition every hour (source)[pastebin.com]

Some people have speculated that the condition loss occurs every day, but it's actually a random chance. However, it usually ends up being about a day or more (24+ rolls) for 3.33% chance to proc.

The roll to check for condition loss (and fuel loss) occurs every new hour.

If the roll succeeds, there's a 50% chance as to whether the condition loss will be 2% instead of 1%.
Skills - Maintenance
Maintenance alone is not the determining factor for Chance To Lower Condition (source)[pastebin.com]

For combat, the game's code calls a method named "getMaintenanceMod" and multiplies that value by 2.

"Maintenance Mod" is as follows:

RoundDown((MaintenanceLevel + RoundDown(WeaponLevel / 2) / 2))

That is:
Step 1: RoundDown(WeaponLevel / 2)
Step 2: MaintenanceLevel + Step 1
Step 3: RoundDown(Step 2 / 2)

Note: while RoundDown does not appear in the game's code, due to the double-to-int type coercion that takes place, Java rounds down any double values that are converted to int.

Your weapon's "Effective Maintenance" is Maintenance Mod * 2.

Your weapon's "Effective Condition Lower Chance" is 1 in WeaponConditionLowerChance + Effective Maintenance.
Weapons - General
Weapon Level is 1 less than its actual value for every weapon type except Axe (source)[pastebin.com]

Known game mechanics affected by the bug
  • MaintenanceMod (getMaintenanceMod)
  • Weapon Damage (processHitDamage)
The method in question is getWeaponLevel.

A quick break down of method getWeaponLevel in IsoGameCharacter.java
  1. The variable where your weapon level is stored ("var2") is initialized to a value of -1.
  2. From here, we check the equipped weapon's categories for a known weapon type (e.g., Axe, Spear, LongBlade, etc.)
  3. When a match is found, the weapon type is added to "var2" rather than assigned to "var2" (as in the case of Axe weapon type)

Example: you have a Crafted Spear and your Spear level is 3.

var2 = -1; ... // weapon type found var2 += 3 // result is 2

As a result, every weapon type level (except Axe) is actually 1 less than its stated value for any game mechanic that relies on the getWeaponLevel method.

This bug was tested and confirmed in game. It dates back to at least 41.68 and is still in game as of 41.78. It was reported to TIS in this thread.

Video demonstration

I made a simple mod where, every time I level up, a message pops up displaying the return value of getWeaponLevel.

Change Log
8/27/2023
  • In version 41.73[theindiestone.com], the ability for the Generators to charge a car's battery was removed. It was considered a "bug," but it was clearly coded with the intent to echarge a car's battery. Either way, the entry has been edited to reflect this change

11/11/2022
  • Added "Weapons - General" section to document newly discovered bug

11/10/2022
  • Clarified car key spawn location so you don't have to look at the flow chart to know that certain spawns are only valid if the car spawned with a door unlocked.

10/27/2022
  • Corrected error in Tree Chopping section. WeaponLevel was replaced with WeaponConditionLowerChance.

10/25/2022
  • Release
10 Comments
Undefined  [author] 11 Nov, 2022 @ 1:09am 
Section added (Weapons - General) to document a bug that negatively effects weapon levels.

"Weapon Level is 1 less than its actual value for every weapon type except Axe"
cuksuzkurt 6 Nov, 2022 @ 12:26am 
Its really broking realism can someone make mod that when you die inside a car that your charcter dont fall from car?
cuksuzkurt 6 Nov, 2022 @ 12:25am 
When i die inside a car ı just fall of under the car is there are fix for this?
cuksuzkurt 6 Nov, 2022 @ 12:25am 
Guys ı need help
a tired face 2 Nov, 2022 @ 7:49pm 
wonderful guide, just when you know everything, you know nothing
OperatorNugget 29 Oct, 2022 @ 6:40pm 
awesome work dude, thanks a bunch :steamthumbsup:
Veryfungi3221 29 Oct, 2022 @ 1:00pm 
it gud :steamthumbsup:
Mxswat 29 Oct, 2022 @ 7:58am 
Great guide! I like this!
Undefined  [author] 27 Oct, 2022 @ 1:47pm 
@peteR 75hz: Thanks for the kind words and to everyone for the rewards!
peteR 75hz 26 Oct, 2022 @ 9:49pm 
This is GOLD INFO! Awesome work =D