Script to make a state stay through an Inn visit?

So, after like an hour of Google giving me basically the same answer I don't want, is there a script that will let me mark certain states to not get removed upon visiting an inn or dying? I know there's a billion scripts that already do this, but those scripts also disable every other way of removing the state other than the "remove state" command. I have a disease state that wouldn't be cured by an Inn visit, but would naturally go away after like 30 turns or walking 1000 steps. I have way too many status effects and characters to try and make a common state for inn visits that manually removes each and every state aside from the disease state for each character.
Here you go

Spoiler: Life & Death So Near So Far
Code:
module PERSISTENT_STATES
################################################################################

          RECOVERY = [2,3,4,5] # Doesn't get removed on Recover All

          DEATH = [6,7,8,9] # Doesn't get removed on Death

################################################################################
end

class Game_BattlerBase
  def clear_some_states
        for state in $data_states
          next if state.nil?
erase_state(state.id) unless  PERSISTENT_STATES::RECOVERY.include?(state.id)
        end
  end
        
  def clear_other_states
        for state in $data_states
          next if state.nil?
erase_state(state.id) unless  PERSISTENT_STATES::DEATH.include?(state.id)
        end
  end
end

class Game_Battler < Game_BattlerBase
  def recover_all
    clear_some_states
    @hp = mhp
    @mp = mmp
  end
end

class Game_Battler < Game_BattlerBase
  def die
     @hp = 0
     clear_other_states
     clear_buffs
  end
end
Here you go

Spoiler: Life & Death So Near So Far
Code:
module PERSISTENT_STATES
################################################################################

          RECOVERY = [2,3,4,5] # Doesn't get removed on Recover All

          DEATH = [6,7,8,9] # Doesn't get removed on Death

################################################################################
end

class Game_BattlerBase
  def clear_some_states
        for state in $data_states
          next if state.nil?
erase_state(state.id) unless  PERSISTENT_STATES::RECOVERY.include?(state.id)
        end
  end
       
  def clear_other_states
        for state in $data_states
          next if state.nil?
erase_state(state.id) unless  PERSISTENT_STATES::DEATH.include?(state.id)
        end
  end
end

class Game_Battler < Game_BattlerBase
  def recover_all
    clear_some_states
    @hp = mhp
    @mp = mmp
  end
end

class Game_Battler < Game_BattlerBase
  def die
     @hp = 0
     clear_other_states
     clear_buffs
  end
end

This script crashes the game after I take a step with the state. It gives an error that says:
Script 'Game_Actor' line 596: NoMethodError occurred.
undefined method`>' for nil:NilClass
This script doesn't touch Game_Actor
Must be something else

Do you have any scripts that affect state removal? Particularly on step?
I have Yanfly's Buff & State Manager v1.07 and Yanfly Engine Ace - Lunatic States v1.02. There's a bunch of other scripts, but those are the only ones that affect states.

Edit: It's probably the Buff and State Manager.
I tested those two scripts together and they work fine. Game Actor default script has line 596 as # * Update Step Count for State
You have modified the default scripts. That's a no, no. Now you will have issues like what you are encountering. You should always make a new script and copy over the sections you need to modify to prevent problems with the default scripts.

What other scripts are you using?
I was going to bring that up
That line is indeed supposed to be a comment

If there's no incompatibility between Yanfly's scripts and my snippet, then probably your edits are to blame

try reverting Game_Actor to how it was and see what happens
I had the Japanese version of Game_Actor because I started this project on a pirated Japanese copy of RPG maker (Yes, I know) before buying the Steam version.
Line 596 on that version is: @state_steps[state.id] -= 1 if @state_steps[state.id] > 0
The same error still persists when I copy and paste the english Game_Actor script from a fresh project, except now it refers to line 600 (which says the same thing as above).

Typing game_actor into the search thingy shows the following scripts:
  1. Ace Save Engine v1.03
  2. New Game+ v1.00
  3. Ace Menu Engine v1.08
  4. Ace Battle Engine v1.22
  5. DoubleX RMVXA Unison Addon to Yanfly Engine Ace
  6. Enemy Target Info v1.02
  7. Victory Aftermath v1.04
  8. Ace Equip Engine v1.06
  9. Barehand Trait v1.00
  10. Dual wield / two-handed fix (the author is Trihan)
  11. Ace Message System v1.05
  12. Ace Item Menu v1.02
  13. Ace Shop Options v1.01
  14. Ace Status Menu v1.02
  15. Battle Command List v1.09b
  16. Lunatic States v1.02
  17. Lunatic Parameters Package - Empower v1.00
  18. Weapon Attack Replace v1.01
  19. Party System v1.08
There's way more scripts than that honestly, but I think, with my nearly nonexistant knowledge of programming, that these are likely the most relevant ones.
I started this project on a pirated Japanese copy of RPG maker
And that's the problem. You need to start a new project for the English version and copy over your scripts and maps.
You can recreate the rest. But don't copy over the scripts file and probably some of the data files as that will cause instabilities with mixing versions.

Then let us know if the problem still exists.
And that's the problem. You need to start a new project for the English version and copy over your scripts and maps.
You can recreate the rest. But don't copy over the scripts file and probably some of the data files as that will cause instabilities with mixing versions.

Then let us know if the problem still exists.
Are you sure I can't just copy over the scripts from a new project? That'd take maybe an hour compared to the 100s of hours spent on this project. Even copying and pasting everything would still take longer.
That'd take maybe an hour compared to the 100s of hours spent on this project
I understand you spent a long time working on your game. I've been working on mine for 4 years.
I was giving a starting point to see if things would work.
I just want you to know that the scripts file is the biggest thing to clean up but the other files may be a problem as well.
Start whichever way you wish. But just know the cleanest way is to start a new project and copy paste everything over.
The exception that I know of is the map files, you can just move them over. Is would be a huge pain to re-create maps, wouldn't it.
The easiest thing I could think off would be to Reapply those states that you want to keep even if your heroes go to sleep. This option would let you use less lines of code to get the desired effect. So aliasing the method, probably recover_all, would be useful here.
Okay, so I copied over all the scripts from a fresh project, and that didn't fix the crash. After that, I decided to copy and paste the file labeled "Scripts" to a new project and test it there. It worked perfectly. So, I think it's (somewhat) confirmed that there's nothing wrong with my billions of scripts, the project itself is just cursed lol

EDIT: Oh, yeah, it's super cursed lol. I removed the script entirely (the newest one, obviously), and the crash still happens as soon as I pick up the test state and take a step.

EDIT PT2: I FIGURED IT OUT! It was Yanfly's Buff & State Manager. The states that were causing crashes were marked with "<reapply total>". Removing that stopped the crashes!

Original thread: https://forums.rpgmakerweb.com/threads/script-to-make-a-state-stay-through-an-inn-visit.125867/