So I'm in the game I'm working on I'm trying to see if there is any way to increase my actor(s) current HP when they level up in tandem with their max HP. For example: say an actor(s) have a max HP of 100 and after the end of combat the current HP is 20 and the actor(s) level up and the max HP increases to 301. How would I make the current HP of 20 become 60 HP to keep the ratio somewhat the same? I am trying to avoid plugins if possible and I'm not good at JavaScript.
Current HP to Max HP level up ratio
RPG Maker MV SupportYou don't need JavaScript, but you...well, you don't need plugins, but doing it without them would be so inefficient and unnecessarily complicated that it's absurdly silly. So to not be ridiculous, you'd use two plugins:
1 - Make a troop event that stores the current and max HP of each actor into a variable at the end of each turn. You'll need HimeWorks' End Phase Triggers to make this work properly at the end of combat. (you can be more efficient by using Yanfly's Common Troop Events instead of pasting this into every troop in your game)
2 - use HimeWorks' Level Up Common Events to check the new max HP against the stored max HP and set the current HP to the appropriate percentage.
1 - Make a troop event that stores the current and max HP of each actor into a variable at the end of each turn. You'll need HimeWorks' End Phase Triggers to make this work properly at the end of combat. (you can be more efficient by using Yanfly's Common Troop Events instead of pasting this into every troop in your game)
2 - use HimeWorks' Level Up Common Events to check the new max HP against the stored max HP and set the current HP to the appropriate percentage.
I see. Well the reason I was asking is because I have MV on both my PC and on the Nintendo Switch and wanted to make the same game on Switch for a friend to play because he likes playing such games on his Nintendo Switch. And since the Nintendo Switch doesn't allow plugins that's why I was asking. But thanks for the advice. I am really new to RPG Maker so I am grateful for the help.
the engines for handheld are different than the engines for computers, which is one reason why they don't have plugins. But there is an evented solution for the computers and you can try to use it on the handheld as well.
first thing is you need a troop event running on turn 0 to setup everything.
depending on what exactly you want, this troop event should store the required values like MaxHP before battle.
additionally it should turn on a switch "after battle event".
second part is a parallel process event conditioned to exactly that switch.
on computers, parallel processes are stopped during battle. If that is the same the parallel process will not run until the battle ends and the player returns to the map.
in the parallel process event, you compare current maxHP with the maxHP before the battle - if it increased, you can calculate the difference and then add the required HP to the player to keep the scale.
or anything else you want to happen after each battle.
and the last command of the parallel process should be to switch it off, preventing the commands to be repeated.
first thing is you need a troop event running on turn 0 to setup everything.
depending on what exactly you want, this troop event should store the required values like MaxHP before battle.
additionally it should turn on a switch "after battle event".
second part is a parallel process event conditioned to exactly that switch.
on computers, parallel processes are stopped during battle. If that is the same the parallel process will not run until the battle ends and the player returns to the map.
in the parallel process event, you compare current maxHP with the maxHP before the battle - if it increased, you can calculate the difference and then add the required HP to the player to keep the scale.
or anything else you want to happen after each battle.
and the last command of the parallel process should be to switch it off, preventing the commands to be repeated.
That's the part I'm not sure about. Do you run a script in the common event to run the calculation?
Depends on what exactly you want to calculate. Of course you can calculate anything in a script. But you should be able to do most calculations using the 'Control Variables' event command, if you are not comfortable using scripts.
If you tell us the exact calculation you want to perform, we can also help you put that into a script or event commands.
If you tell us the exact calculation you want to perform, we can also help you put that into a script or event commands.
no, the control variable command should contain and enable every basic mathematical function, even the rarely used modulo operation.
you might need to use a temporare variable to store partial operations and complex formulaw can use a dozen control variable commands, but they are possible without scripts.
I would say it would be Max HP (during combat)/ Max HP (after level up) = HP%
then HP% * Current HP= Added HP
then change HP command to add Added HP to current HP
this way your Current HP is ratioed to the new Max HP. But I'm not sure how to do that through the variable commands.
MaxHP cannot change during battle (not unless you have an item that permanently increases MaxHP, and those should be limited to outside battle use)
so
Troop event on turn 0:
control variable beforeHP= MaxHP of actor
Common event after battle:
control variable afterHP = MaxHP of actor
control variable afterHP /= beforeHP
if afterHP > 1 (which means HP increased)
>> control variable afterHP *= currentHP of actor
>> control variable afterHP -= currentHP of actor
>> change HP actor plus variable afterHP
please take note of which variable and which mathematical operation is used where, you can mess this up (but I can't guarantee it'll work because I haven't tested it, but it should work)
so
Troop event on turn 0:
control variable beforeHP= MaxHP of actor
Common event after battle:
control variable afterHP = MaxHP of actor
control variable afterHP /= beforeHP
if afterHP > 1 (which means HP increased)
>> control variable afterHP *= currentHP of actor
>> control variable afterHP -= currentHP of actor
>> change HP actor plus variable afterHP
please take note of which variable and which mathematical operation is used where, you can mess this up (but I can't guarantee it'll work because I haven't tested it, but it should work)
wouldn't that make afterHP drop down to 0 after the first level up?
right - sorry, you'll need to multiply afterHP with 100 before dividing by beforeHP
I forgot that the variables truncate to integer....
EDIT: and of course divide by 100 again before changing HP with the result.
so anything less than half will not work?
no, that is why I multiplied by 100.
if you multiply the first number by 100 and then divide the last result by 100 again, the error is 1% or less.
otherwise even 0.99 would count as 0 for eventing.
Okay so here's what I came up with
Troop Event: Condition Turn 0
>>Control Variable: (actor)OldMaxHP = Max Hp of (actor)
>>Control Variable: (actor)OldLvl = Level of (actor)
>>Control Switch: LvlupHP = On
Common Event:
>> Control Variable: (actor)NewMaxHP = Max HP of (actor)
>> Control Variable: (actor)NewLvl = Level of (actor)
>> Control Variable: (actor)currentHP = HP of (actor)
If : (actor)NewLvl > (actor)OldLvl
>> control variable (actor)OldMaxHP*=100
>> control variable (actor)OldMaxHP/=(actor)NewMaxHP
>> control variable (actor)OldMaxHP*= (actor)currentHP
>> control variable (actor)OldMaxHP/=100
>> Change HP: (actor), {(actor)OldMaxHP}
>> control switch: LvlupHP = Off
and it seems to work.
Thanks so much for the help.
Troop Event: Condition Turn 0
>>Control Variable: (actor)OldMaxHP = Max Hp of (actor)
>>Control Variable: (actor)OldLvl = Level of (actor)
>>Control Switch: LvlupHP = On
Common Event:
>> Control Variable: (actor)NewMaxHP = Max HP of (actor)
>> Control Variable: (actor)NewLvl = Level of (actor)
>> Control Variable: (actor)currentHP = HP of (actor)
If : (actor)NewLvl > (actor)OldLvl
>> control variable (actor)OldMaxHP*=100
>> control variable (actor)OldMaxHP/=(actor)NewMaxHP
>> control variable (actor)OldMaxHP*= (actor)currentHP
>> control variable (actor)OldMaxHP/=100
>> Change HP: (actor), {(actor)OldMaxHP}
>> control switch: LvlupHP = Off
and it seems to work.
Thanks so much for the help.
Original thread: https://forums.rpgmakerweb.com/threads/current-hp-to-max-hp-level-up-ratio.143133/