Quick Question

Trying to work on my first plugin. What I am creating is an auto state that happens at 25% or less hps. If hps go below 25% the state fatigue will be applied and if hps are above 25% the state will be removed. I believe i am not using the correct variables in this.fhp = HP / MHP, I have tried searching what to put here to make this work but none of my ideas have been correct. Due to this being my first attempt I may have this all wrong. Any advise would be amazing thanks in advance =)


/*:
*
*@plugindesc adds fatigue to characters below set amount of health.
*
*@author Skeezixs
*
*@param 
*
*@help
*
*/
(function() {
Game_BattlerBase.prototype.fatigueStateId = function() {
    return 12;


 var  Game_Battler_Fatigue = Game_Battler.prototype.refresh;
        Game_Battler.prototype.refresh = function() {
            Game_BattlerBase.prototype.refresh.call(this);
                this.fhp = HP / MHP
                if (this.fhp <= 0.25) {
                    this.addState(this.fatigueStateId());
                } else {
                    this.removeState(this.fatigueStateId());



}();  
try this.fhp = this.hp / this.mhp


actually, back in Ace there is the hp_rate method


maybe you can try if it exists in MV? like using this.hp_rate directly as your check or setting it as this.fhp = this.hp_rate


Also, I believe that this line


Game_BattlerBase.prototype.refresh.call(this);


should be 


Game_Battler_Fatigue();


So that it will run everything that Game_Battler's refresh method runs (which afaik includes a call to the method run by Game_BattlerBase too). Your current setup only runs the refresh of Game_BattlerBase + your edits, any update done by Game_Battler is lost.
opps yah i needed to change the prototype but still does not work with either this.hp_rate or this.hp / this.mhp . I tried both. Thats the one thing I cannot seem to find what they used for the parameters I want to find the percentage of. Even tried changing the 0.25 to 25 when using this.hp_rate to see if it was using a whole number for the percent versus a decimal. Neither seemed to work. 


/*:
*
*@plugindesc adds fatigue to characters below set amount of health.
*
*
*@author Skeezixs
*
*@param 
*
*
*@help
*
*
*
*
*
*/
(function() {
Game_BattlerBase.prototype.fatigueStateId = function() {
    return 12;


 var  Game_Battler_Fatigue = Game_Battler.prototype.refresh;
        Game_Battler.prototype.refresh = function() {
            Game_Battler_Fatigue();
                this.fhp = this.hp_rate 
                if (this.fhp <= 0.25) {
                    this.addState(this.fatigueStateId());
                } else {
                    this.removeState(this.fatigueStateId());



}();  
Been playing around with this and think I found what the variables should be but it still is not working. Below is what I have currently changed it too but it still does not work. I was also trying to put in Game_BattlerBase.prototype.hpRate and it did not seem to work either. 
 


function() {
Game_BattlerBase.prototype.fatigueStateId = function() {
    return 12;


 var  Game_Battler_Fatigue = Game_Battler.prototype.refresh;
        Game_Battler.prototype.refresh = function() {
            Game_Battler_Fatigue();
                this.fhp = this._hp / this.mhp
                if (this.fhp <= .25) {
                    this.addState(this.fatigueStateId());
                } else {
                    this.removeState(this.fatigueStateId());



}();  
It appears that you are missing a few closing brackets }.


When using return it will not run any code after the return.


So all of this:


var  Game_Battler_Fatigue = Game_Battler.prototype.refresh;
Game_Battler.prototype.refresh = function() {
Game_Battler_Fatigue();
    this.fhp = this._hp / this.mhp
    if (this.fhp <= .25) {
        this.addState(this.fatigueStateId());
    } else {
        this.removeState(this.fatigueStateId());
}
};


Will never be called.


Note that this is assuming that there isn't a } after the return statement.


So I believe your code might look something more like this:

Code:
function() {
Game_BattlerBase.prototype.fatigueStateId = function() {
    return 12;
};
  
 var  Game_Battler_Fatigue = Game_Battler.prototype.refresh;
        Game_Battler.prototype.refresh = function() {
            Game_Battler_Fatigue.call(this); //changed this to call vs Game_Battler_Fatigue()
                this.fhp = this._hp / this.mhp
                if (this.fhp <= .25) {
                    this.addState(this.fatigueStateId());
                } else {
                    this.removeState(this.fatigueStateId());
                }
        };

}();
I tried this as well and it still did not apply state 12 when the character goes below 25% life. But I feel we are on the right track. 

Original thread: https://forums.rpgmakerweb.com/threads/quick-question.73401/