granular temporarily reduced max hp? / maximum max hp?

This is probably a pretty niche issue- as I haven't encountered a game that I recall that does what I'm trying to do, so the best way to explain what I want to accomplish would be to explain my system.


In my game, hp will be called 'Vigor'.
Vigor will be not only a measure of health, but also physical energy.

A character's current vigor will gradually decrease over time, and as they preform strenuous activities to simulate them getting tired. (easy enough to do)

Taking damage will reduce maximum vigor to simulate actual wounds. (should still be relatively easy)

Resting and camping will restore current vigor, but not maximum vigor.
On the flip side, healing will restore maximum vigor, but not current vigor.
(again, not a large hurdle)

The problem I need to solve is allowing healing to restore maximum vigor without allowing the effect to increase the max beyond what it the character's actually maximum should be, without having that maximum be a static value- as it should be able to be increased by various effects and gear. (bonus gratitude if the solution includes a method of displaying current, adjusted maximum, and actual maximum)

If it helps, I have all of the Yanfly Engine Plugins installed.

Theoretically, using Buffs & States Core I could create a state that reduces max hp by 1, allow it to stack ludicrously high, and possibly convert enemy attacks to apply a number of stacks of this state = to the damage they would deal- but I imagine that would severely impact performance. (and I wouldn't know how to convert damage to stacks anyway)

Any help here would be appreciated.
There's no such thing as stacks of states - you have a state or you don't.

Why don't you just store their starting mhp in a variable, then use the built-in event command to change the parameter? Then when you want to restore it, you use the same event command to the value of that variable.
Not entirely the same, but I have a setup in which there's "HP", "max HP", and "temporary max HP". In my case, once HP gets below a certain threshold, it will drag down max HP as well (in other words it will impair your ability to recover through healing spells/items).

I can imagine numerous ways to implement this, but as @ATT_Turan suggests, using variables to keep track of the "temporary max HP" seems the most straightforward (assuming you only have a handful of actors to keep track of). Depending on how you want the max HP to behave, you may need to make a plugin though.
I have a setup in which there's "HP", "max HP", and "temporary max HP".
I think you forgot "tertiary HP" and "alternative HP" 🤣
I think you forgot "tertiary HP" and "alternative HP" 🤣
I haven’t! Those are introduced after the mid-way point in the story!
There's no such thing as stacks of states - you have a state or you don't.

Why don't you just store their starting mhp in a variable, then use the built-in event command to change the parameter? Then when you want to restore it, you use the same event command to the value of that variable.
Right- sorry, I misspoke; I'm used to referring to buffs and debuffs collectively as states, but should have been more clear because states refers to something else in this context.


How could I ensure that effects can't increase this variable can't go above a certain adjustable number? would it be easier to make a variable that tracks the wounds and reduce max hp by that amount?
How could I ensure that effects can't increase this variable can't go above a certain adjustable number? would it be easier to make a variable that tracks the wounds and reduce max hp by that amount?
If I understand you correctly, this is all in your most basic event commands - Control Variables and Conditional Branch.

You haven't explained whether the max HP is increasing with levels throughout the game, like normal, or if it's one value throughout the whole game (which would make you not even need a variable).

But as far as what you just asked, you just look at the actor's current max HP, and check if the stored original mhp - current mhp >= your adjustable number of possible wounds.

If you're still not entirely sure you have it, I'd strongly encourage you to try something - if it works just like you want, then awesome. If it doesn't, then you have an event you can show screenshots of and say "this specific thing isn't doing what I want."
If I understand you correctly, this is all in your most basic event commands - Control Variables and Conditional Branch.

You haven't explained whether the max HP is increasing with levels throughout the game, like normal, or if it's one value throughout the whole game (which would make you not even need a variable).

But as far as what you just asked, you just look at the actor's current max HP, and check if the stored original mhp - current mhp >= your adjustable number of possible wounds.

If you're still not entirely sure you have it, I'd strongly encourage you to try something - if it works just like you want, then awesome. If it doesn't, then you have an event you can show screenshots of and say "this specific thing isn't doing what I want."
That's actually pretty helpful advice. I was over here suffering from a sort of mental paralysis thinking 'I don't even know if this is gonna work' I should probably do a bit of throwing things at walls for a while to see what sticks while I get acquainted with the engine.
For instance, in events I saw 'control variables' but I was like 'okay, so I can control variables, but how do I set them'- lo and behold, 'set variable' is one of the functions of control variable.
Additionally, as I'm going through this, I'm realizing it would probably be much easier to have fatigue reduce max health, and damage to what it normally does- I won't have to jump through near as many hoops to change how damage functions, or incorporate it into the ui- also now that I think about it, that's how a lot of survival based games handle fatigue, so it will be more familiar to players.

So now that I know my intended approach, I can ask for more specific help.

So here's where I'm at.

I have created an event to set variable 1 [vigor] to character's max hp.
I have created a common event to increase variable 2 [fatigue] by 1.
The next step of this event will be to set character's parameter max hp to equal \v[1]- \v[2]
The change parameter option won't work here because it only let's me add or subtract, not set it to a specific value.
I tried running a script, but I don't think I called the object correctly.

This was my attempt. Cast your gaze upon my attempt to code, and despair:

$gameActors.actor(1){
mhp= \v[1]-\v[2]}

I'm super rusty when it comes to coding, is this even close to the right direction, or is that a whole lotta nonsense?

edit: also, no, max hp will not increase by levels, but will be increased by gear, so it will need to be a value that can change.
$gameActors.actor(1){
mhp= \v[1]-\v[2]}
oh dear 🤣

The change parameter option won't work here because it only let's me add or subtract, not set it to a specific value.
it does only add/subtract, but you make the variables so that you have anchors you can use, and then use a bit of math to get the correct values

a thought - you dont need to look at the actor's mhp for this, but if you do, itd be easier to use the base max hp instead of the current max hp since buffs, states and gear can cause increases you must account for and changes where they might not be expected.

assuming theres just the one actor, try this
Code:
var v = $gameVariables;
var fatigue = v.value(1)
v.setValue(1, fatigue + 5);    //add 5 fatigue
fatigue = v.value(1)-fatigue;       //gets the fatigue difference you just added

$gameActors.actor(1).addParam(0, -fatigue)  //subtracts the fatigue difference
then for your individual events, you can change the 5 to some other value to add.

if its a common event being ran and you want fatigue gain to be variable, you can substitute the 5 with the call for another variable's value that you set beforehand (lets say variable 2).

and when its time to clear the fatigue, use the script and set variable 1 to 0 instead (or if its a common event that uses a 2nd variable, make variable 2's value variable 1's *-1 and run it)

Edit: a few edits overthinking and poorly explaining things 😀
oh dear 🤣


it does only add/subtract, but you make the variables so that you have anchors you can use, and then use a bit of math to get the correct values

a thought - you dont need to look at the actor's mhp for this, but if you do, itd be easier to use the base max hp instead of the current max hp since buffs, states and gear can cause increases you must account for and changes where they might not be expected.

assuming theres just the one actor, try this
Code:
var v = $gameVariables;
var fatigue = v.value(1)
v.setValue(1, fatigue + 5);    //add 5 fatigue
fatigue = v.value(1)-fatigue;       //gets the fatigue difference you just added

$gameActors.actor(1).addParam(0, -fatigue)  //subtracts the fatigue difference
then for your individual events, you can change the 5 to some other value to add.

if its a common event being ran and you want fatigue gain to be variable, you can substitute the 5 with the call for another variable's value that you set beforehand (lets say variable 2).

and when its time to clear the fatigue, use the script and set variable 1 to 0 instead (or if its a common event that uses a 2nd variable, make variable 2's value variable 1's *-1 and run it)

Edit: a few edits overthinking and poorly explaining things 😀
Thanks for the help!
Alright, let me parse through this to make sure I have a good grasp of what I'm looking at, and try to learn from this a bit...


var v = $gameVariables; a. okay, so here you're creating a variable named v, and defining it to be $gameVariables- is that where all engine variables are stored?
var fatigue = v.value(1) b. so if 'v' now refers to $gameVariables and assumption a. is correct, v.value(1) refers to variable 1? so this is setting enigine variable 1 to 'fatigue'? is this being created directly in the code instead of in the engine to streamline the process, or will it not work otherwise?
v.setValue(1, fatigue + 5); //add 5 fatigue c. This part confuses me a bit, if my above assumption that (1) referred to engine variable 1 why would the value need to be called again. This leads me to believe assumption b. was ,in fact, incorrect. can you provide clarity?
fatigue = v.value(1)-fatigue; //gets the fatigue difference you just added d. it happens again here, so let me reevaluate assumption b. : the variable 'fatigue' has nothing to do with the game engine variables, and is only being used for the code itself?

$gameActors.actor(1).addParam(0, -fatigue) //subtracts the fatigue difference e. so if this is for a single actor, for multiple actors I would change (1) here for each actor?
f. param(0) refers to actor's max hp?
a. okay, so here you're creating a variable named v, and defining it to be $gameVariables- is that where all engine variables are stored?
yes. there is a global $gameVariables object that handles all the data for the game's variables. in this case i made the "v" variable as a shorthand for $gameVariables cause i thought id be typing it enough to be worth shortening

b. so if 'v' now refers to $gameVariables and assumption a. is correct, v.value(1) refers to variable 1?
yes. the $gameVariables object has a value() function that fetches the value of the variable you pass it, but the function has an additional behavior of returning 0 if there is no data at all. if you accessed the data directly from the _data array and you havent initialized that value, it would return null and youd need to manually check for that

so this is setting enigine variable 1 to 'fatigue'? is this being created directly in the code instead of in the engine to streamline the process, or will it not work otherwise?
when youre using a script box, all of its contents are ran directly as JS. you are allowed to use regular JS practices like declare variables for use within that script box.
so i make a local "fatigue" variable and set its value to the game variable to create a copy of what that variable's value was at that time. If the game variable's value changes later, fatigue wont update with it.
you could also use a second game variable if you wanted, but there isnt much need to. all it is for is creating a copy of the value and it would only ever be used here.

c. This part confuses me a bit, if my above assumption that (1) referred to engine variable 1 why would the value need to be called again. This leads me to believe assumption b. was ,in fact, incorrect. can you provide clarity?
the purpose this one serves is to keep track of the total fatigue by incrementing it. If you set it but didnt have it refer to itself at some point in that process, you lose track of previous changes and wouldnt be able to revert the changes later without doing more.

d. it happens again here, so let me reevaluate assumption b. : the variable 'fatigue' has nothing to do with the game engine variables, and is only being used for the code itself?
yep. the variables declared in a script box have no inherent relation to anything and only exist within the scriptbox theyre made in. the only relation fatigue initially had to game variable 1 was that it was a copy of its value at the start of all of this. we've changed the value of variable 1 to add more fatigue the line prior, but we still have fatigue as the game variable's value before the update.

the line then takes the difference between what variable 1's value used to be, and what it is now to determine how much the total fatigue shifted

e. so if this is for a single actor, for multiple actors I would change (1) here for each actor?
yes, the 1 refers to the actor with the Id of 1. you'd change the number of the id and run that line for each actor that should be affected. remember, this all all came with the assumption that either you had one actor, or fatigue is shared. all actors would have their hp reduced by the same amount without further changes

param(0) refers to actor's max hp?
i didnt type that, but yes. param(0) returns the actor's max hp. the numbers 0-7 all refer to the different parameters in the order they appear in the class parameter curve panel.
similarly, addParam(x, y) will add y to the actor's x parameter and allows negative values.
yes. there is a global $gameVariables object that handles all the data for the game's variables. in this case i made the "v" variable as a shorthand for $gameVariables cause i thought id be typing it enough to be worth shortening


yes. the $gameVariables object has a value() function that fetches the value of the variable you pass it, but the function has an additional behavior of returning 0 if there is no data at all. if you accessed the data directly from the _data array and you havent initialized that value, it would return null and youd need to manually check for that


when youre using a script box, all of its contents are ran directly as JS. you are allowed to use regular JS practices like declare variables for use within that script box.
so i make a local "fatigue" variable and set its value to the game variable to create a copy of what that variable's value was at that time. If the game variable's value changes later, fatigue wont update with it.
you could also use a second game variable if you wanted, but there isnt much need to. all it is for is creating a copy of the value and it would only ever be used here.


the purpose this one serves is to keep track of the total fatigue by incrementing it. If you set it but didnt have it refer to itself at some point in that process, you lose track of previous changes and wouldnt be able to revert the changes later without doing more.


yep. the variables declared in a script box have no inherent relation to anything and only exist within the scriptbox theyre made in. the only relation fatigue initially had to game variable 1 was that it was a copy of its value at the start of all of this. we've changed the value of variable 1 to add more fatigue the line prior, but we still have fatigue as the game variable's value before the update.

the line then takes the difference between what variable 1's value used to be, and what it is now to determine how much the total fatigue shifted


yes, the 1 refers to the actor with the Id of 1. you'd change the number of the id and run that line for each actor that should be affected. remember, this all all came with the assumption that either you had one actor, or fatigue is shared. all actors would have their hp reduced by the same amount without further changes


i didnt type that, but yes. param(0) returns the actor's max hp. the numbers 0-7 all refer to the different parameters in the order they appear in the class parameter curve panel.
similarly, addParam(x, y) will add y to the actor's x parameter and allows negative values.
Awesome, Thank you so much, you have been tremendously helpful.
This was my attempt. Cast your gaze upon my attempt to code, and despair:
I dunno why you're trying to do JavaScript here - you don't need to be using code for any of this. I wouldn't.

As I said originally, all of this can be done with the builtin event commands Control Variables, Conditional Branch, and Change Parameter.

The change parameter option won't work here because it only let's me add or subtract, not set it to a specific value.
Of course it will, you just do one math operation (Control Variables) to subtract your specific value from the current max. Then Change Parameter subtracting that amount.
I dunno why you're trying to do JavaScript here - you don't need to be using code for any of this. I wouldn't.

As I said originally, all of this can be done with the builtin event commands Control Variables, Conditional Branch, and Change Parameter.


Of course it will, you just do one math operation (Control Variables) to subtract your specific value from the current max. Then Change Parameter subtracting that amount.
I guess I misunderstood how the change parameter option works then. I expected it to go this way:
(using base max hp 100 for example)
Variable fatigue is created and set to 1. command change parameter is run subtracting fatigue from max hp

Max hp is now 99,
Next, fatigue increases by 1 for a total of 2. Command change parameter is run subtracting fatigue from current max health of 99 for a new value of 97.

Are you saying that it's actually
Variable set to 1. command runs, max hp = 99
variable increases to to. command runs, subtracting fatigue from ORIGINAL max hp, for a new value of 98?
Variable fatigue is created and set to 1.
I don't see the purpose of this variable. If you're just decreasing the max HP by one every time, then do Change Parameter and type 1 into the value.

If you need to check whether they can lose the HP based on a maximum fatigue, then you have your fatigue variable and it has nothing to do with the Change Parameter event command.

Control Variables -> CurrHP = actor's Max HP
Control Variables -> CurrHp = OrigHP - CurrHP (you could call this variable something else to be more meaningful, but I don't see a reason to take up another variable for this)
Conditional Branch -> CurrHp < AllowedFatigue
- Change Parameter -> Max HP - 1
honestly, now that I think about it, I'm not sure, I was probably overthinking the process

Original thread: https://forums.rpgmakerweb.com/threads/granular-temporarily-reduced-max-hp-maximum-max-hp.172832/