Heal depending on states removed

Trying to think of a way that I can make a debuff-cleansing ability heal for any debuffs removed - like 5% HP for each debuff removed or something like that. So, if it doesn't remove any debuffs, it doesn't do anything, then if it removes 1 debuff, it heals 5% HP, if it removes 2 debuffs, it heals 10% HP, etc.

EDIT: ShadowLurk provided a solution below.
Hey Zevia

Unfortunately you will likely need a script to get the target's info. I had a similar issue here.

Basically I had a need to get that info for one of my common events to force an action, and I used Hime's Common Event Variables script, which loads user and target data into variables that you assign into the script.

To solve the problem. I would suggest this.

1. Set up Hime's script to give you a Target Info Varible

2. Set up a State Count Variable

3. Set up a State Count Common Event.

          This event will have to check each status on your list and add 1 to the variable State Count.

4. Set up State Heal Actual skill

          This skill will remove the states and have the calculation in the damage bar. The calculation should be something like. b.mhp * 0.05 * State Count Variable

5. Set up State Heal skill

          This is the skill that the player selects. It will call up the Common Event State Count, set the actors last target using Hime's script, and then Force Action State Heal Actual Skill on the Last target.

You will have to work with Hime's script to get the target info you need.

Hope that helps!

~ Dinhbat
EDIT: ShadowLurk's post below has the best solution.
This is more easily accomplished with scripts. Though if you want to use common event, as you have Hime's common event variable script:

First, in damage formula:

v[123]=b.states.size;0Though you'll want to use some kind of anti-fail for this, for the skill to not display Failed on cast.

Then, in the common event, that is called by using the skill, call script:

$game_temp.common_event_target.hp += v[123] - $game_temp.common_event_target.states.sizeBy the way, if it is too long for a script call, the acceptable break is after opening parentheses or operators. In this case, you can do:

$game_temp.common_event_target.hp +=v[123] -$game_temp.common_event_target.states.sizeI think it is mentioned somewhere that adding underscore (_) before line break means the script is continuing to the next line, but I am not sure.
EDIT: ShadowLurk's post below has the best solution.
I think that would heal for every state on the target, including the positive ones, right? I'm looking to only heal for each negative state removed.
Um, there is no distinction in-game for positive and negative state. My formula would heal the target based of the difference of the number of state before and after. You can make the skill effect remove states as normal.

If your game has something that labels a state as positive/negative, I can work out the formula.

I also forgot to multiply the value with the target's mhp. The event's script call probably would work like this.

Code:
t = $game_temp.common_event_targett.hp+=($game_variables[123]-t.states.size)*t.mhp*0.05
I see - I was thinking it would simply heal based on the number of states, so I thought it would heal for all states, not just the ones removed. I didn't quite follow all the way through on what you were saying because the scripting was a little complex to me.

If I have this right, since common events are called after the damage formula is run and any other effects are calculated, then the formula bar is simply setting variable 17 (123 in your case, but 17 in my project) equal to the number of states the target currently has. It then removes all the various states that cleanse gets rid of, at which point the common event is called.

The common event sets the actor ID stored in $game_temp.common_event_target (generated through Hime's script) to a new variable, t, then says t's HP should be increased by variable 17 (which was the total number of states when the skill was called) minus the number of states currently applied (effectively seeing how many were removed [which was the part I missed earlier]), multiplied by 5% of the actor's maximum HP.

It seems to work just fine, with only the minor setback of the health not appearing as a damage popup - but I'm OK with that, it's very negligible.

Thanks much ShadowLurk, that solves my problem. Thanks to Dinhbat, too, for the recommendation of Hime's script.
For the damage popups, it depends on what battle script you use. If you use Yanfly Battle Engine, you can do this:

Code:
t = $game_temp.common_event_targett.result.hp_damage = -($game_variables[123]-t.states.size)*t.mhp*0.05SceneManager.scene.execute_damage(t)t.result.clear
I'm using Yanfly Battle Engine, Victor Damage Popup, and Jet's Side Battle System. Unfortunately, that suggestion just gives me errors.

EDIT: Still having trouble, actually, and this is not fully solved yet.

The heal provided by calling the common event does not actually apply until the turn is updated, which can potentially take up to 2-3 actions. My guess would be it has something to do with the draw_hp function in Yanfly's script only being called at the end of a turn, whereas the CTB system I'm using counts "turns" as a random number of actions between about 1 and 3. When I use text display to tell me the value of the actor's HP, it appears to be updating immediately, but the health is not actually displaying as properly updated until a bit of a delay.
If even the working version errors, that's just weird.

Anyway, made a mistake in that popup example.

Code:
t = $game_temp.common_event_targetn=(($game_variables[123]-t.states.size)*t.mhp*0.05).to_it.result.hp_damage=-nt.execute_damage(t)t.result.clear
That does get the damage popup to appear, though the actor's health bar still doesn't update until the turn is processed - although my guess is that's an issue with Yami's PCTB system. It might have to do with Yanfly's Battle Engine, though, since it's the script that actually draws the health bar. I don't really know.

It's a relatively minor bug that I don't think players are going to notice, especially since the health IS being restored, it's just not being properly displayed as such for a couple actions. I'd be very pleasantly surprised if you were able to work up a fix for that, but I think if it's basically just a display update issue that fixes within a couple actions, it's pretty much acceptable.

Thanks for the help!
That is caused by Yanfly making the battle scene only refreshes the current actor. I think it was done to reduce lag.

You can use this snippet. It will restore the normal refresh behavior.

Code:
class Scene_Battle < Scene_Base    #--------------------------------------------------------------------------  # new method: redraw_current_status  #--------------------------------------------------------------------------  def redraw_current_status    @status_window.refresh  end  end
Where should I put that in my scripts? I pasted it below all my other scripts, but unfortunately it still doesn't update until the turn is over.
Add this script call in the healing common event, after the healing is done:

Code:
SceneManager.scene.redraw_current_status if SceneManager.scene_is?(Scene_Battle)
That's fantastic. I thought it would be a lot more complicated to fix that issue - I actually had a series of abilities in the game at one point that would use script calls to reduce TP by 15, but I ended up reworking the abilities to just flat out cost TP because the script events wouldn't update immediately. Will that script call now work for all instances where I might want to update the actor status/health/etc. immediately?

I also put in this additional line at the beginning of my common event to fully simulate the regular damage popup sound effect:

Conditional branch: Script: $game_variables[17]-$game_actors[$game_variables[42]].states.size==0

>

  else

  >Play SE: 'Recovery', 80, 100

end

I think that solves everything I wanted in this ability, and if that script call works for all instances that I want to change health or status effects via common events, then that's awesome. I really appreciate the time and effort you put into working on this with me.
Those script calls should work anywhere.
If your effect executes after debuffs are removed, you have access to the debuffs that were removed for the given action as an array.


It includes both buffs and debuffs, but you can easily check that.
The common event is called after the debuffs are removed - and while ShadowLurk's solution means I don't really need to access them for any reason, I'm curious how I would get the information to check specifically what was removed in the common event like you say.
Well, yes.

You can check in the battler's result.

In the spirit of the previous examples:

r = $game_temp.common_event_target.resultn = r.removed_states.sizem = r.removed_buffs.sizewhere result is an instance of Game_Action. I simply compare the target's states before and after in case something resets the action results.

One thing is that removed_buffs does not discriminate against buffs and debuffs.
So, if I were to make a skill called, say, StateTransfer, and instead I wanted the caster to take on the debuffs removed from the target (or a skill that stole buffs from the enemy), would r store the actual states removed, such that I could then do something like $game_actors[$game_variables[41]].add_state[r], where 41 is the actor ID stored with Hime's Common Event variables?

Original thread: https://forums.rpgmakerweb.com/threads/heal-depending-on-states-removed.25386/