Project Zomboid

Project Zomboid

More Traits
curveo 7 月 18 日 下午 12:37
2
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.
最后由 curveo 编辑于; 7 月 18 日 下午 12:48
< >
正在显示第 1 - 9 条,共 9 条留言
can u upload video instruction ?
chaos 8 月 2 日 上午 10:46 
Thanks ! It works ! There are no more those annoying errors any more.You save my game !
DJ WEEABOO 8 月 4 日 下午 4:19 
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.
最后由 MaxWolfChaos07 编辑于; 8 月 9 日 上午 5:31
curveo 8 月 10 日 上午 7:37 
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)
MaxWolfChaos07 8 月 14 日 下午 5:27 
引用自 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!
jbartosevich 8 月 17 日 下午 7:24 
Thank you for this. I was going crazy trying to find the mod that crashed me every time I did burpees
Alkaline 8 月 22 日 上午 8:00 
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:
Shadow Kriss17 9 月 21 日 下午 2:38 
My hero
< >
正在显示第 1 - 9 条,共 9 条留言
每页显示数: 1530 50