Project Zomboid

Project Zomboid

More Traits
Even More Traits conflict fix
I found a quick bug fix for when you try to work out with both gym goer traits from More Traits and Anabolic trait from Even More Traits spamming hundreds of errors.

Basically edit MoreTraits.lua like this:

-- Add this near other global variables or before GymGoer function in MoreTraits.lua
local moreTraits_GymGoer_XPLock = false

Then replace GymGoer function like this:

function GymGoer(_player, _perk, _amount)
if moreTraits_GymGoer_XPLock then return end -- Check the lock at the beginning

local player = _player;
local perk = _perk;
local amount = _amount;
local modifier = 200;

if SandboxVars.MoreTraits.GymGoerPercent then
modifier = SandboxVars.MoreTraits.GymGoerPercent;
end
modifier = modifier * 0.01;

if player:HasTrait("gymgoer") and player:getCurrentState() == FitnessState.instance() then
if perk == Perks.Fitness or perk == Perks.Strength then
-- Original amount calculation (from XP event)
local original_event_amount = _amount; -- Use the original _amount from the event for calculation

-- Calculate the bonus XP GymGoer wants to add
-- The original code was doing `amount = amount * (modifier - 1)`
-- then `amount = amount * 0.1`.
-- It implies the 'amount' passed to AddXP should be the *bonus only*.
-- And the original amount from the event is what it's based on.
local bonus_xp_to_add = original_event_amount * (modifier - 1);
bonus_xp_to_add = bonus_xp_to_add * 0.1; -- The 'stopgap fix'

if bonus_xp_to_add == 0 then return end -- Don't do anything if bonus is zero

moreTraits_GymGoer_XPLock = true -- Activate the lock
AddXP(player, perk, bonus_xp_to_add); -- Call the local AddXP helper
moreTraits_GymGoer_XPLock = false -- Release the lock
end
end
end


I also added a lock to Even More Traits but maybe that's not necessary. Posting here in case helpful.

Add this global variable in LazoloMain.lua:

local evenMoreTraits_TraitAnabolic_DirectXPLock = false

Then replace TraitAnabolic function like this:

function TraitAnabolic(Player,PlayerData,StatsLib)
local Protein = Player:getNutrition():getProteins()
if Protein > 300 then
local Burning = 1 + (Protein - 300) * 0.02 -- Made 'Burning' local

-- Check if the lock is already active (to prevent re-entry)
if evenMoreTraits_TraitAnabolic_DirectXPLock then
-- If PlayerData and PlayerData.Nutrition are available, set proteins and return
if PlayerData and PlayerData.Nutrition then PlayerData.Nutrition:setProteins(Protein-Burning) end
return
end

evenMoreTraits_TraitAnabolic_DirectXPLock = true -- Activate the lock

Player:getNutrition():setProteins(Protein-Burning)
Player:getXp():AddXP(Perks.Strength, Burning * 9, false, false, false)

evenMoreTraits_TraitAnabolic_DirectXPLock = false -- Release the lock
end

if Player:getCurrentState() == FitnessState.instance() then
if StatsLib then -- Ensure StatsLib is not nil
StatsLib.StressChange = (StatsLib.StressChange or 0) - 0.7/60
StatsLib.UnhappyChange = (StatsLib.UnhappyChange or 0) - 0.5/60
end
end
end


Worked for me.
< >
Showing 1-1 of 1 comments
ElBr Jun 12 @ 6:48pm 
How to I edit "MoreTraits.lua"? I try to find it in the local files
< >
Showing 1-1 of 1 comments
Per page: 1530 50