Lagged healing

I'm designing a state in which the affected battler converts his damage into heal for the lowest HP ally. For example: if he causes 100 HP damage, his lowest ally will heal 10 HP. Something like that.

Overall, my design works, except for one thing: the healing is delayed one action. For example:
1. affected battler causes damage; recovery sound plays and a recover pop up appears on the lowest hp ally
2.a enemy makes an action; lowest hp ally heals

As you can see from above, healing should be happening on action 1, but it's happening on action 2. If action 2 is an attack from the enemy on the lowest hp ally, the healing will work as mitigation.

So, mechanically, my design works. If healing is delayed or not does not matter mechanically because the result is technically working as intended. But aesthetically, it doesn't work. The player may get confused and think it is a bug and that the state isn't working.

This is how I designed the state
Ruby:
class Game_Battler < Game_BattlerBase
  
   def altruist(a,b,item,damage)
    if a.actor? && !b.actor? && !item.damage.recover? \
      && a.state?(93)
      allies = $game_party.battle_members.select { |member| member.hp > 0 \
      && member.hp < member.mhp}
      allies = allies - [$game_actors[6]]
      return if allies.empty?
      lowest = allies.min_by { |ally| ally.hp_rate }
      altruist_conversion_rate = ((a.mat * 1.9) + 10)/100
      altruist_heal = (damage * altruist_conversion_rate).to_i
      lowest.hp += altruist_heal
      lowest.hp = [lowest.hp, lowest.mhp].min
      Sound.play_recovery
      text = sprintf(YEA::BATTLE::POPUP_SETTINGS[:hp_heal], altruist_heal.group)
      lowest.create_popup(text, "HP_HEAL")
    end
  end
  
end

Just for you to know, I use Yanfly's scripts. Namely: Ace Battle Engine and Lunatic Damage. My state method "altruist" is called on Lunatic Damage in the "Finalization" section, among other methods I designed.
Well you shouldn't have to set the lowest.hp twice. The hp will not go above max hp unless you have something that will allow that.
So I think all you need to do is to do a lowest.refresh which should do Game_BattleBase refresh.
Even though it should have done that when you do the lowest.hp = statement
Personally I would not do the second lowest.hp line. I don't see the point.
I would put a printout before and after to see if the value has changed.
If it has then it's just the hp bar not updating, which is what I believe you are saying.
So what do you have that might be controlling the hp bar and not updating?
Well you shouldn't have to set the lowest.hp twice. The hp will not go above max hp unless you have something that will allow that.
So I think all you need to do is to do a lowest.refresh which should do Game_BattleBase refresh.
Even though it should have done that when you do the lowest.hp = statement
Personally I would not do the second lowest.hp line. I don't see the point.
I would put a printout before and after to see if the value has changed.
If it has then it's just the hp bar not updating, which is what I believe you are saying.
So what do you have that might be controlling the hp bar and not updating?
Both the hp bar and the hp number are not updating immediately. They do so in the subsequent action. But yeah, when I print lowest's hp, I can confirm that the healing has been done, although it has not provoked a visual update besides the pop up.

Original thread: https://forums.rpgmakerweb.com/threads/lagged-healing.169564/