Project Zomboid

Project Zomboid

More Traits
curveo Jul 18 @ 12:37pm
1
XP Multipliers Conflict – Error with Fitness/Strength XP when multiple traits are active
Disclaimer:
This is a quick and dirty patch I made to fix a specific issue in the More Traits mod.
I’m sharing it here in case it helps others, but I’m not the mod author.
If you want a clean, official fix, you’ll have to wait for the mod owner.
Please don’t come complaining to me – this is just a "works for now" solution.

🛠 Issue
When multiple traits that modify XP are active (e.g. GymGoer + spec* traits), gaining XP in Fitness or Strength causes:
    Errors in the console.Incorrect XP values.
  • In some cases, the game might even crash.

🔍 What I Found
The original code in the functions Specialization and GymGoer doesn’t handle multiple XP multipliers stacking properly.
Variables like skipxpadd and hardcoded if/else blocks cause conflicts.

✅ Quick Fix
I created a helper function GetXPModifier(player, perk) that calculates all XP bonuses dynamically.
I then patched Specialization and GymGoer to use this function instead of their old logic.

📜 How to Apply
    Go to your Project Zomboid Workshop mods folder.Open the MoreTraits.lua file (usually under C:\Program Files (x86)\Steam\steamapps\workshop\content\108600\1299328280\mods\More Traits\42\media\lua\client).
  • Add the following function near the top (just above AddXP):

local function GetXPModifier(player, perk) local m = 1.0 -- GymGoer bonus if player:HasTrait("gymgoer") and (perk == Perks.Fitness or perk == Perks.Strength) and player:getCurrentState() == FitnessState.instance() then local gymMod = SandboxVars.MoreTraits.GymGoerPercent or 200 m = m * ((gymMod * 0.01) - 1) * 0.1 end -- Auto-detect spec* traits local specMod = (SandboxVars.MoreTraits.SpecializationXPPercent or 75) * 0.01 for i = 0, player:getTraits():size()-1 do if player:getTraits():get(i):sub(1,4) == "spec" then m = m * specMod end end return m end

  • Replace the body of Specialization with:

function Specialization(player, perk, amount) if perk == Perks.Fitness or perk == Perks.Strength then return end local finalAmount = amount * GetXPModifier(player, perk) AddXP(player, perk, finalAmount) end

  • Replace the body of GymGoer with:

function GymGoer(player, perk, amount) if player:HasTrait("gymgoer") and (perk == Perks.Fitness or perk == Perks.Strength) and player:getCurrentState() == FitnessState.instance() then local finalAmount = amount * GetXPModifier(player, perk) AddXP(player, perk, finalAmount) end end
🎯 Results
With this patch:

No more XP errors with Fitness/Strength.

XP from multiple traits stacks correctly.

The mod remains compatible with future traits that start with spec.

💬 Final Note
This is a quick workaround, not an official fix.
If you want to revert, just restore your original MoreTraits.lua file.
Last edited by curveo; Jul 18 @ 12:48pm
< >
Showing 1-8 of 8 comments
can u upload video instruction ?
chaos Aug 2 @ 10:46am 
Thanks ! It works ! There are no more those annoying errors any more.You save my game !
Great fix thank you
Going to try this out, my game keeps deciding I'm not allowed to become stronger and crashes out my game every time I try to exercise. The problem you explained sounds like mine so here I go to "Code" for the first time :spiffo:

Edit: It worked, thank you so much! You made that super easy.
Last edited by MaxWolfChaos07; Aug 9 @ 5:31am
curveo Aug 10 @ 7:37am 
No problem if you want you can find in official Github (https://github.com/hypnotoadtrance/MoreTraits) the last version with update of systeme fitness gain xp (Just DL moretrait.lua in github if you want last version)
Originally posted by curveo:
No problem if you want you can find in official Github (https://github.com/hypnotoadtrance/MoreTraits) the last version with update of systeme fitness gain xp (Just DL moretrait.lua in github if you want last version)
Thank you again!
Thank you for this. I was going crazy trying to find the mod that crashed me every time I did burpees
Alkaline Aug 22 @ 8:00am 
Maybe I'm stupid but I think I must be replacing the wrong code.
Currently I'm swapping everything between and including

function Specialization(_player, _perk, _amount)
local player = _player;

and

else
skipxpadd = false;
end
end

any help appreciated :steamthumbsup:
< >
Showing 1-8 of 8 comments
Per page: 1530 50