Project Zomboid

Project Zomboid

Eggon's Sharpen Your Blades!
Eggon  [developer] 18 Nov, 2021 @ 5:20am
For modders: API for configuring your weapons
Configuring your weapons
ESYB will apply some default configuration to each 'unregistered' weapon of category Small Blade, Long Blade and Axe. Basically it will take the 'vanilla' parameters of a weapon and multiply them by (1 + sharpnessLevel) * 0.2 multiplier. Which results in multiplier 0.2 for zero sharpness and 1.2 for 100% sharpness and 1 for 80% (the vanilla value).

You can however configure your own configs for particular weapons that will be used by ESYB instead of the automatic configuration. You can configure modded weapons and you don't have to be the author of the mod they come from. You can create plugin mod that will require both ESYB and the mod being the source of weapons.
Structure of config table
Config table might require 1 or more weapon configs:
local yourWeaponsConfig = { ["YourModule.YourWeapon1"] = weapon1Config, ["YourModule.YourWeapon2"] = weapon2Config, -- ... more entries }

Single weapon config has the following structure:
local weapon1Config = { bladeDurability = 1, -- damage severity multiplier bladeHardness = 1, -- bluntening rate modifier equippedIconLeft = false, levels = weapon1LevelsConfig }
* Blade durability - multiplier affecting how much damage weapon takes during damage events. 1 is neutral, value above 1 means that it will take less damage (value = 1.2 => -20% damage), below 1 - more damage (value = 0.8 -> +20% damage taken).
* Blade hardness multiplier affecting the rate of bluntening. 1 is neutral, above 1 means it will blunten slower, below 1 - faster.
* EquippedIconLeft - you can decide on which side of the hotbar slot will be displayed the ornage 'equipped status' bubble. Set to true for weapons which icons are drawn from top-left to bottom-right. Set false for weapons drawn from top-right to bottom-left.

Levels config has the following structure:
local weapon1LevelsConfig = { [0] = level0Config, [1] = level1Config, [2] = level2Config, [3] = level3Config, [4] = level4Config, [5] = level5Config } local level0Config = { maxSharpness = 0, MinDamage = 0.3, MaxDamage = 1.0, CriticalChance = 4, CritDmgMultiplier = 2, TreeDamage = 5, DoorDamage = 5 }
1) 6 entries numbered 0 to 5 are obligatory.
2) maxSharpness of level 0 must be 0.
3) maxSharpness of level 5 must be 100.
4) maxSharpness of each consecutive level must be higher than the previous one, but other than that I think they can be set freely. I use steps of 20, because it plays nicely with the sharpness indicator.
5) Each level entry contains 6 combat properties of PZ's weapons. You can set them to any valid values, but generally the higher the sharpness level the higher the values should be.

You can check my configs for 7 weapons in config files in ESYB's lua/shared/weapons folder.
Calling the config
In order to register your wepons you need to call ESYB.Dict.addWeaponsToDictionary() function from a file in lua/shared directory:
if ESYB then ESYB.Dict.addWeaponsToDictionary(yourWeponsConfig) end
Full entry example
local yourWeaponConfig = { ["YourModule.YourWeapon"] = { bladeDurability = 1, bladeHardness = 1, equippedIconLeft = false, levels = { [0] = { maxSharpness = 0, MinDamage = 0.3, MaxDamage = 1.0, CriticalChance = 4, CritDmgMultiplier = 2, TreeDamage = 5, DoorDamage = 5 }, [1] = { maxSharpness = 20, MinDamage = 0.5, MaxDamage = 1.3, CriticalChance = 8, CritDmgMultiplier = 2, TreeDamage = 15, DoorDamage = 15 }, [2] = { maxSharpness = 40, MinDamage = 0.6, MaxDamage = 1.5, CriticalChance = 12, CritDmgMultiplier = 3, TreeDamage = 25, DoorDamage = 25 }, [3] = { maxSharpness = 60, MinDamage = 0.7, MaxDamage = 1.8, CriticalChance = 16, CritDmgMultiplier = 4, TreeDamage = 30, DoorDamage = 30 }, [4] = { maxSharpness = 80, MinDamage = 0.8, MaxDamage = 2, CriticalChance = 20, CritDmgMultiplier = 5, TreeDamage = 35, DoorDamage = 35 }, [5] = { maxSharpness = 100, MinDamage = 1.0, MaxDamage = 2.3, CriticalChance = 25, CritDmgMultiplier = 6, TreeDamage = 40, DoorDamage = 40 } } } }