Adjust HP when increasing MaxHP

Almost Simon

Villager
Member
Joined
Aug 8, 2013
Messages
21
Reaction score
17
Primarily Uses
Why hello there!


Let me explain my situation first:


- I use Yanfly's Base Parameter Control to let my MaxHP and MaxMP be influenced by my other attributes (actors defense stat for example).


- I also use Yanfly's BattleStatus and Equip Core (among others that should not be relevant)


So my problem now is this:


- When I equip a different - let's say - armor that increases my defense (-> and therefor my MaxHP) the character's current HP does not update (which is normal, but not how I want it).


What I want is:


- That my HP increases by the same amount that my MaxHP increases when I equip something.


- - If my actor is at 30/60 HP and equips an item that increases his Defense (and therefore his MaxHP) by 10, I want him to be at 40/70 HP.


- Same for HP and MP o.c.


I am able to adjust some basic JavaScript, I just didn't manage to fix this. (Since I don't directly add or decrease MaxHP, I thought of maybe requesting for a change in MaxHP while equipping and add the same value to HP, I couldn't get the code to work though :/ )


If someone could write me some code so that I can fix this problem, that would be fantastic!


Thanks


Simon
 

kovak

Silverguard
Veteran
Joined
Apr 3, 2016
Messages
1,263
Reaction score
1,565
First Language
PT - EN
Primarily Uses
RMMV
That's a issue that has nothing to do with the plugins you've listed, so there's nothing wrong with them.
 

Almost Simon

Villager
Member
Joined
Aug 8, 2013
Messages
21
Reaction score
17
Primarily Uses
Ehm, yea thanks for the quick answer. 


I know it's not a problem with the plugins, I just listed them for simplification, because they do influence how and where certain formulas are executed.


Also, I know that everything works as intended (from the game's & plugin's perspective), it's just not what I want.


Anyhow, I think I managed to get some kind of a work around that seem to do just fine for now. If I'm sure that it works, I'll post it here.



SImon
 

Uzuki

Kawaii on the streets, Senpai in the sheets
Veteran
Joined
Aug 18, 2012
Messages
1,933
Reaction score
1,326
First Language
English
Primarily Uses
RMMV
Read through this and see if this helps: 
 

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
219
First Language
English
Primarily Uses
RMVXA
Mathematically, it's pretty simple.


Store hp rate within a variable.


Modify maximum hp though equipment, states, stats changes, etc...


Then multiply the new maximum hp by the stored hp rate value.


So if your actor had 72 out of 120 HP. You would first store the hp rate.


72 / 120 = 0.6


Let's say maximum health increases to 190. We then just multiply by the old hp rate.


190 * 0.6 = 114


Simply recovering HP equal to the difference between the old and new maximum HP values wouldn't be very accurate.
190 - 120 = 70
72 + 70 = 142



142 / 190 = 0.747


This would take the actor from 60% hp to about 75%. If hp is decreased in the same way, you may end up killing the actor in some cases.


Unfortunately, I can't write a code for this in MV, but there's the math.
 

Almost Simon

Villager
Member
Joined
Aug 8, 2013
Messages
21
Reaction score
17
Primarily Uses
Ok, I think what I did is solid enough to post it as a solution here. If someone could check it, that would be great ;)


So within YEP_EquipCore.js

  • I changed the "onItemOk" function so that it would store the ratio hp/maxHp before equipping the new item.
  • After equipping the item, it sets the hp proportially to my new maxHp.

So here's what it looks like (line 1009)


Yanfly.Equip.Scene_Equip_onItemOk = Scene_Equip.prototype.onItemOk;
Scene_Equip.prototype.onItemOk = function() {
var hpRate = this.actor().hp / Math.max(1, this.actor().mhp);
var mpRate = this.actor().mp / Math.max(1, this.actor().mmp);
var tpRate = this.actor().tp / Math.max(1, this.actor().maxTp());
Yanfly.Equip.Scene_Equip_onItemOk.call(this);
var max = this.actor().isDead() ? 0 : 1;
//var hpAmount = Math.max(max, parseInt(this.actor().mhp * hpRate));
var newMaxHP = this.actor().mhp;
var newMaxMP = this.actor().mmp;
var newMaxTP = this.actor().maxTp();
//var maxHpGained = newMaxHP - currentMaxHP;
var hpAmount = Math.max(max, Math.round(newMaxHP * hpRate));
var mpAmount = Math.max(max, Math.round(newMaxMP * mpRate));
var tpAmount = Math.max(max, Math.round(newMaxTP * tpRate));
this.actor().setHp(hpAmount);
this.actor().setMp(mpAmount);//parseInt(this.actor().mmp * mpRate));
this.actor().setTp(tpAmount);
this._itemWindow.hide();
this._statusWindow.refresh();
};


Is this solid? I mean, it works but will it cause problems for some reason or another?


Thanks


Simon
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,049
Members
137,569
Latest member
Shtelsky
Top