[RMVXAce] Remove 1 random debuff/state

Hello!

Is it possible to have an action of some sort remove only 1 debuff/negative state instead of a full cleanse?

For a random example, Actor 1 has Poison/Blind, then uses the action and RNG says it removes Blind only.

I was thinking of a skill or item that removes one at a time, and thought of using a common event, but realized if it's randomized and if the actor doesn't have the said state, it wouldn't work if RNG landed on another state.

Maybe I'm approaching it wrong, or is there an easier way to do this?

Thank you very much to anybody who can help me with this. 😂
it can be done, as I have done it before.
it doesn't require a plugin, I did it with a bunch of calls through a common event.

let me dig it up.
@gstv87 : Please remember they are using ACE when you do post it. The logic will probably be the same as in MV though, so I doubt anything major will change.
@bgillisp B, .... please.....
*points to self using Ace*

here

new-1.jpg


this was made to remove up to 5 buffs from a buff list (states not-(300 to 376)).
in my list, that range is for debuffs, so I select everything-except-those, and then instead of picking 4 to remove, I sift everything down until I'm left with 4.
and *then*, I grab that set from the battler's set of buffs and remove them.

so:
grab the battler that's casting the spell, from the current scene:
Code:
scn = SceneManager.scene
bat = scn.active_battler

grab the target of the attack, from which we'll grab the list of states.
Code:
@bt = bat.get_targets[0]

grab the states to work with:
Code:
@rmv = @bt.states.select{|s| !(300..376).include?(s)} or []
# { .. } OR []
# because there might be nothing to grab, so make sure we grab at least an empty array.

then, randomly discard things:
Code:
until @rmv.size < 5
  @rmv.pop(@rmv[rand(@rmv.size)])
end

and then, execute the removal according to that list.
Code:
if @bt.states != []
@rmv.each{|s| @bt.remove_state(s.id)}
end

it can be adapted in any way you need it, just remember to grab the scene, the battler, the target for that battler, the list of states, and from there select what you need to remove.
I'm personally not using this event ATM, and I'm already seeing that it needs refining... this is from an old build that I sketched and never updated.
it did work as intended, but I never ran it through debugging.
I had to find the shortest instructions to work with it so they'd fit in the script call box, that's why I used an until loop instead of a for.
"don't count from one to four! just drop everything until you're left with less than five!"
that was the reasoning XD
so:
grab the battler that's casting the spell, from the current scene:
Code:
scn = SceneManager.scene
bat = scn.active_battler
This solution ends here because "active_battler" is not defined in any scene. Except if I'm blind.
Yeah, it seems to crash because of something to do with the active battler ;_;
oops.

that's based on BattleManager and action order.
still.... you still have to grab the battler you're working with, to grab their targets, in order to grab the states they have.

let me find the equivalent code.

EDIT:
BattleManager.actor
that should return the *actor* that's being handled by the battle scene, but I did some modifications to it, because I modified the party and sometimes it'd bring an empty actor.
if that fails, use BattleManager.actor_index, to bring the party index that's being handled, and from there, the actor.

since this should be used as a skill after-effect, BM.actor shouldn't change until that effect is completed, so the event's call to BM.actor should bring BM.action_battlers[0] which is the same thing, and action_battlers[0] should have been defined at the start of the turn, which is not changing until the actor has gone, and *gone* comes after the last instruction of any skill effect.

¯\_(ツ)_/¯
I've learned that sometimes 2+2 doesn't yield 4, so, might as well establish that 4 does indeed come after 3 and before 5, just to be sure.
This is turning out really complicated than I thought. I can't seem to get it to work, but it's most likely from my confusion especially of the BM.Actor part.
I would do it like this:
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

Add this snippet to your scripts and then set up the skill to use the following in its damage formula:
Ruby:
b.remove_random_state; 0

Add the following notetag to any states that you class as 'negative' states:
Ruby:
<neg>
I tend to not do any processing through the damage formula.
that's there to just present the values to be processed, not call for actual processing itself.

and from there, stems the need to replace the "B" in the damage formula with an actual actor.
that actor is the target for the current actor using the skill for which the damage formula would have called up said processing.

if you go into the skill definition in the help files, it calls for item.damage.eval()
and that eval() call requires two arguments: the two battlers in question.
and, since you can grab the target from the user, and the user from the battle itself, you can process the same thing outside the formula.
I tend to not do any processing through the damage formula.
that's there to just present the values to be processed, not call for actual processing itself.

and from there, stems the need to replace the "B" in the damage formula with an actual actor.
that actor is the target for the current actor using the skill for which the damage formula would have called up said processing.

if you go into the skill definition in the help files, it calls for item.damage.eval()
and that eval() call requires two arguments: the two battlers in question.
and, since you can grab the target from the user, and the user from the battle itself, you can process the same thing outside the formula.
All of these honestly are just pedantic. From the standpoint of user-friendliness, damage formula probably the most user-friendly. And if you start to give a solution outside the damage formula, it would start to look complicated.

However, using it in the damage formula is not without its own quirk.
The process to remove the negative status effect is done BEFORE the damage calculation. Unlike the default add state from the skill effect which is done AFTER the damage. So take that with a consideration.
And if you start to give a solution outside the damage formula, it would start to look complicated.
of course it will look complicated.
the more you go into the code to find out what's doing what thing, the more the instructions will do one thing and one thing only, and you'll need a lot of 1's to get to 100 by going 1+1 every time.
but once you know *why* repeating 1+1 yields 100, then you can make it go 2+2 or 10*10.
if I tell you that 100 is so without telling you why, the next time you get 99 you won't know where the missing 1 is.

The process to remove the negative status effect is done BEFORE the damage calculation.
IF you call for it through the damage formula.
if you use it as an after effect, it will go after the damage.

normally, you'd want all state-changing effects to be applied after the damage, so that if the skill causing the damage needs to be countered by a state on the defender's side, it will be considered by the calculation.
if you remove it before passing the result to the next calculation, any resistances that the defender might have to the item you want to send towards that defense, won't do anything.
and, usually in RPG manuals, all skills are explained as "This skills does X, AND, modifies Y", usually it being "it damages first, and then alters the state of the target", except where the skill is a state-altering skill already (like a buff or a debuff) which usually does no damage.
of course it will look complicated.
the more you go into the code to find out what's doing what thing, the more the instructions will do one thing and one thing only, and you'll need a lot of 1's to get to 100 by going 1+1 every time.
but once you know *why* repeating 1+1 yields 100, then you can make it go 2+2 or 10*10.
if I tell you that 100 is so without telling you why, the next time you get 99 you won't know where the missing 1 is.
There're people who desire solution, easy solution.
And there're people who desire to learn.

Depends on which this thread is posted, if it's posted in Learning RGSSx, I'd drop the item apply method as well as possible solutions to get this done in various ways. But it's posted RGSS3 request. A simple and few steps to get this done is preferable, in my opinion.

normally, you'd want all state-changing effects to be applied after the damage, so that if the skill causing the damage needs to be countered by a state on the defender's side, it will be considered by the calculation.
This is really a case by case basis.
If you heal and add state to increase the heal, it is favorable to put the state first
If you damage and add state to decrease the defense, don't you want the state to apply first?
I'd put aside "normally" because that's entirely the dev to judge how things work.
I would do it like this:
Spoiler
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

Add this snippet to your scripts and then set up the skill to use the following in its damage formula:
Ruby:
b.remove_random_state; 0

Add the following notetag to any states that you class as 'negative' states:
Ruby:
<neg>

Thanks so much for all the help A-Moonless-Night! This works exactly how I want it to be. 😂

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/rmvxace-remove-1-random-debuff-state.120535/