Project Zomboid

Project Zomboid

194 ratings
Spear Crafting Fix
2
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
63.675 KB
19 Jan, 2023 @ 1:24am
1 Change Note ( view )

Subscribe to download
Spear Crafting Fix

Description
What does this do?

This patch fixes the durability of spears with attachments.
In the base game, when you attach a weapon to a spear, the resulting spear can not reach 100% durability without repairs.

For example: Take a hunting knife with 100% durability and a crafted spear with 100% durability and attach the knife.
The resulting `Spear with hunting knife` has ~60% durability.

This mod makes it so the spear has the proper 100% durability.



This happens because of a bug or oversight in the game code.
The maximum durability is always the minimum of weapon and spear - but in absolutes.
Crafted spears have a max durability of 5, whereas the attached variants have more.
Therefore the spears can never reach full durability after a craft. This mod fixes this.

The fix calculates the durability in percentages and takes the minimum of the percentage, then
multiplies it by the max durability.

I updated the uncrafting logic as well to ensure that you can not get additional durability by crafting + uncrafting repeatedly.


Compatibility
The mod is safe to add or remove at any time.
It should work with all other mods that add spears with attachments, as long as they are using the same methods as the base game.

Workshop ID: 2920288546
Mod ID: spearcraftingfix
27 Comments
Coldsteel 31 Jul, 2024 @ 5:02pm 
I don't mean to be rude or anything. I did it as a proof that it's possible and it works. Ideally I'd want you to take the whole thing and put it into your mod, it would reach more people that way. BTW the SOMW part is identical to the normal code, it's just SOMW has an additional separate pair of these functions specifically for spears crafted out of planks.
Coldsteel 31 Jul, 2024 @ 3:13pm 
I didn't use your code, and I didn't override anything. Which is how I'm not having issues with SOMW and WeaponModifiers compatibility.

https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=3300366479
Neidmare  [author] 31 Jul, 2024 @ 9:10am 
@Coldsteel Sure, feel free to re-use the code. I think the other mod also replaces the original method though, so depending on load order it might not work.
Coldsteel 31 Jul, 2024 @ 7:17am 
@Neidmare well you can remake it such that it doesn't needs to entirely replace it. Since you overwrite the durability value anyway, you can let the original code finish before running your own.

I'm making mod that fixes a different spear issue and I can always just throw in a fixed version of your code in there too.
Neidmare  [author] 31 Jul, 2024 @ 7:09am 
@Coldsteel Ah and the other thing is that my code replaces the vanilla method entirely
Neidmare  [author] 31 Jul, 2024 @ 7:04am 
@Coldsteel IIRC, the load order of the mods is not fixed. If the other mod gets loaded later, it will overwrite my method.
Coldsteel 31 Jul, 2024 @ 6:00am 
@Neidmare I haven't looked at your code but this sort of issue is normally remedied by daisy chaining the calls instead of overwriting them.

local originalFunction = Recipe.OnCreate.UpgradeSpear
function Recipe.OnCreate.UpgradeSpear(...)
originalFunction(...)
your_code(...)
end
Neidmare  [author] 22 Jun, 2024 @ 12:41am 
@cortex3973 I had a look at weapon modifiers. We overwrite the same method in the code. Not possible to make them compatible unfortunately.
Rezonaise 21 Jun, 2024 @ 1:34pm 
mod dont work
Borris the Conqueror 10 May, 2024 @ 5:04pm 
Cortex is indeed correct, mod doesn't work now and i too have Weapon Modifiers v1.1.3 installed as well