State Duration reduction

Hey there, anyone happen to know the JS code to reduce the duration of a specific state?

For example, I have a code that runs to see if an ally is affected by X state. If the ally IS affected by X state, the the ally is healed for triple the amount. At this point, I want the duration of the state to be reduced by 1 turn.

Thank you for your time.

Here's the current code I'm working with so you have a better idea:
Code:
<Post-Damage Eval>
// Check if the current effect dealt HP damage and is magical.
if (this.isHpEffect() && value > 0) {
  // Set the ID of the atonement state.
  var atonement = 176;
  // Get current alive members.
  var group = user.friendsUnit().aliveMembers();
  // Calculate the amount of HP healed.
  var hpHealed = Math.floor(value * 0.25);
  // Go through all of the party members.
  for (var i = 0; i < group.length; ++i) {
    // Get the currently looped ally.
    var ally = group[i];
    // Check if the ally exists, is affected by atonement, and the original caster of the state is the current user.
    if (ally && ally.isStateAffected(atonement) && ally.stateOrigin(atonement) === user) {
I WANT THE CODE HERE TO REDUCE THE DURATION OF STATE 176 BY 1 EXTRA TURN
ally.startAnimation(41);
BattleManager.actionWaitForAnimation();     
   // If it matches, heal the ally.
      ally.gainHp(Math.ceil((hpHealed*3)*(1+(ally.def/375))));
   // Start the damage popup.
      ally.startDamagePopup();
   // Clear the results.
      ally.clearResult();
}
else
{
  //Add echo of life to allies
     ally.addState(176);
ally.startAnimation(41);
BattleManager.actionWaitForAnimation();     
// If it matches, heal the ally.
      ally.gainHp(Math.ceil((hpHealed)*(1+(ally.def/375))));
      // Start the damage popup.
      ally.startDamagePopup();
      // Clear the results.
      ally.clearResult();
  }
}
}
</Post-Damage Eval>
Hey there,

By default there is no routine to advance a single state timer as opposed to all at once.
You can freely access all attributes of your game objects by default though.
In general, I'd recommend against doing this too often as it might make your system more difficult to debug. Whenever you can, use the classes accessor functions instead.

In theory you could use this to reduce the duration of a state using this code:

if (battler.isStateAffected(stateId)) {
if (battler._stateTurns[stateId] > 0) {
battler._stateTurns[stateId] -= 1;
}
if (battler.isStateExpired(stateId) && $dataStates[stateId].autoRemovalTiming === 2) {
battler.removeState(stateId);
}
}


The teal part will also remove the state on the spot if the state is expired and has an "end of turn" removal timing (removal for "end of action" states might be a bit more complicated in praxis since its duration would also depend on whether the battler alreay acted this turn).

In general, since this already is a bunch of code and also directly accesses the battlers attributes, I'd highly recommend putting that code in a plugin anyways:
Spoiler
Code:
Game_Battler.prototype.reduceStateDuration(stateId) {
   if (this.isStateAffected(stateId) {
       var state = $dataStates[stateId];
       if (this._stateTurns[stateId] > 0) {
           this._stateTurns[stateId] -= 1;
       }
       if (this.isStateExpired(stateId) && state.autoRemovalTiming === 2){
           this.removeState(stateId);
       }
   }
};
battler.reduceStateDuration(stateId);
should then do the same as the code above. 🙂

Edit: Typo in plugin corrected.

Original thread: https://forums.rpgmakerweb.com/threads/state-duration-reduction.92121/