Heal on level up but keep unique state.

Hello everyone,


I am using VX ACE and I have a script (see below) that heals the player when they level up. Works great! However it removes status effects. Don't get me wrong I want to remove the bad status effects but I have one status effect "well rested" that I would like to keep if it is active when the player levels up.


The status is given when the player sleeps at an INN and last for 1200 steps (gets removed afterwards.)


What I want to know is how to I stop the script from removing that particular status effect or can I just remove recover_all and have heal_poison, heal_paralysis, ect...

Code:
class Game_Actor < Game_Battler
  alias heal_on_level_up level_up
  #--------------------------------------------------------------------------
  # * Level Up
  #--------------------------------------------------------------------------
  def level_up
	heal_on_level_up
	recover_all
  end
end
From what I understand, recover_all literally removes all states. The only other way is to call remove_state(state_id) which would require you to manually remove every single state at level up if you did that.


Though, I do think something like this should work for what you want, as long as you don't ever intend to add another state you want kept on level up:


def level_up
heal_on_level_up
if(state?( insert id of your state here)
recover_all
add_state( id of your state)
else
recover_all
end
end



This is untested, but the idea is to check if the state you want to keep is on the player, and if it is call recover_all and add back that state. If that state is not on the player, call the standard recover_all. However, if you ever decide you wish to keep more states on level up you'll probably have to manually parse the states on the player and remove all those that you wish to remove manually.
Yes, recover_all removes all states.


The above snippet would work if you got only one state to keep (not counting the syntax error in it, a bracket is lost between the if and state? words 😛).


Here is a snippet if you want to keep multiple states on level up:

Spoiler
# Made by: Sixth

module KeepStates

# Enter the ID of the states you want to keep on level ups here.
# All states entered here will be kept upon leveling up.
# If a state ID is not here, than that will be removed!
States = [23,24,25]

end

class Game_Actor < Game_Battler

alias add_rec_spec7763 level_up
def level_up
add_rec_spec7763
recover_special
end

def recover_special
remove_spec_states
@hp = mhp
@mp = mmp
end

def remove_spec_states
states.each do |st_id|
next unless state?(st_id)
next if KeepStates::States.include?(st_id)
revive if st_id == death_state_id
erase_state(st_id)
end
refresh
end

end

I haven't tested this, but it should work if you replace the snippet you use now with this one.
Thanks,


I shall give them a try and let you know.

Original thread: https://forums.rpgmakerweb.com/threads/heal-on-level-up-but-keep-unique-state.56765/