Removing only 1 stack of the state?

So, I found an awesome mini script in an old post that allow you to use a script call in damage formulas to remove 1 random state that has a special tag on the state box.

The mini script works perfectly!
Spoiler: Remove Random State
Ruby:
class RPG::State < RPG::BaseItem
  def neg_state?
    self.note =~ /<neg>/i
  end
end

class Game_Battler < Game_BattlerBase
 
  def remove_random_state
    return if neg_states_and_debuffs.empty?
    state_id = neg_states_and_debuffs.sample
    state_id.is_a?(Array) ? remove_buff(state_id[0]) : remove_state(state_id)
  end
 
  def neg_states_and_debuffs
    debuffs = Hash[@buffs.map.with_index { |x,i| [i,x] }]
    debuffs = (debuffs.select { |k,v| v < 0 }).to_a
    return @states.select { |s| $data_states[s].neg_state? } + debuffs
  end
 
end

But there's a little problem, I'm also using a script that make that the same stats can be stacked. The problem with the mini script, is that it erase all stacks of a same state. Is there some way to fix the script to make it only erase 1 stack of a same state?
Didn't I recommend you or a similar forumer that it was better just to stack extra turns instead of copies of a given state?

I strongly believe your problem has a lot to do with a flawed design. Try removing state turns instead.
Didn't I recommend you or a similar forumer that it was better just to stack extra turns instead of copies of a given state?

I strongly believe your problem has a lot to do with a flawed design. Try removing state turns instead.

I can't quite remember such comment. It could be but I don't remember.
Do you mean adding turns to the duration of states?
My game has a lot of unique mechanics that depends on the number of times a state is applied. Some of them are not even related to turns.

I'm making a card game based on yugioh, and I tried to recreate some cards the best I can. For example this card:
1660751015509.png

In yugioh you can have a maximum of 3 copies of a card. If you use 3 times the skill related to this card, you will have the same state 3 times, allowing you to gain 200 ATK * 3.
If I didn't have the stacks, it will only do it once. Also, this card (state) is permanently as long as the battle continue or if the state is removed in this case with the script talked above that remove states, so adding "turns" would do nothing.
Perhaps you should call them buffs and debuffs instead. 😉

Can you give us an example of how exactly you are adding the so called states?

I will see if I can get some spare time to invest it on analysing the original script.
Perhaps you should call them buffs and debuffs instead. 😉

Can you give us an example of how exactly you are adding the so called states?

I will see if I can get some spare time to incest it on analysing the original script.

"incest"? :ewat:
hahaha.

ammm, I just add them normally with the traits box in the skills database. Like a regular poison skill would add the poison state to an enemy, nothing too overcomplicated.

EDIT: I'm sorry, after a lot of testing, I discovered that it wasn't the mini script the one that removed all stacks of a same state, it was another script called "quasi passive" that made states tagged with a passive note to not show. For some reason, this script made that removing a state removed all stacks of said state. So this post can be closed.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/removing-only-1-stack-of-the-state.150508/