Changing Fatigue Loss Values

Discuss modding questions and implementation details.
Post Reply
alephnaught
Posts: 11
Joined: Fri Apr 08, 2016 3:34 am

Changing Fatigue Loss Values

Post by alephnaught »

I'm working on a mod which will - assuming I succeed - make fatigue into a more dynamic stat, like in later TES games. Actions will use up far more fatigue, but it will also regenerate more quickly.

I should say I'm not a programmer at all, this is my first time dabbling in Unity or C#, so there is a lot of trial and error here (and looking at other people's mods - Kirk O.'s Basic Magic Regen has been invaluable here, since it's doing some similar things).

I've got the regeneration part mostly working. I'm hitting a wall though when it comes to changing the fatigue loss associated with certain actions. This is defined in PlayerEntity.cs:

Code: Select all

        // Fatigue loss per in-game minute
        public const int DefaultFatigueLoss = 11;
        public const int ClimbingFatigueLoss = 22;
        public const int RunningFatigueLoss = 88;
        public const int SwimmingFatigueLoss = 44;
        public const int JumpingFatigueLoss = 11;
Fatigue loss itself is then applied later in PlayerEntity.cs.

I want to change these values from my mod script, but the fact that they're consts means I can't use the override method. I'm not sure if there is any way to change them - I know consts are fixed at compile-time, but I don't know if there's a way for a mod script to inject a different value during compile-time or whether these are already set in stone by the time mod scripts are loaded.

The alternative will be to implement a totally new method for fatigue loss which runs in the mod, alongside the vanilla method, which seems messy.

Anyone have any bright ideas?

User avatar
DunnyOfPenwick
Posts: 275
Joined: Wed Apr 14, 2021 1:58 am
Location: Southeast US

Re: Changing Fatigue Loss Values

Post by DunnyOfPenwick »

You could copy the logic in the PlayerEntity Update() method and reverse it.
In your mod's Update() method, do the same logic except it increases fatigue rather than decreases it.
That would offset the changes from the PlayerEntity logic.
Then you could implement additional logic to calculate actual fatigue loss.

Make sure to test your code for cases where fatigue is almost zero. Once it hits zero that will trigger additional logic.
In fact, if fatigue is zero I would probably just avoid attempting changes .

alephnaught
Posts: 11
Joined: Fri Apr 08, 2016 3:34 am

Re: Changing Fatigue Loss Values

Post by alephnaught »

DunnyOfPenwick wrote: Sat Jan 13, 2024 2:45 pm You could copy the logic in the PlayerEntity Update() method and reverse it.
I've been trying just that actually, but for some reason the compiler is telling me my class doesn't have permission to query playerMotor (needed to see whether the player is jumping, climbing, swimming etc). Which is weird, because as far as I can tell, all the relevant declarations are public. :|

Post Reply