skill that heal status ailment one by one VE_StateReplace

Hello guys,

I need help for a skill that would heal multiple status ailment but not all at once.

To be precise I have 3 states

arm fracture
leg fracture
rib fracture

I would like a skill (let's call it Brace) that would heal one of those 3 states randomly when used.

I use the VE_StateReplace plugin in my project.
My 'Brace' skill inflict a state, that is replaced by this code :

<replace state code>
a.removeState(26) ||
a.removeState(27) ||
a.removeState(28);
</replace state code>

So the skill remove all 3 states at once.

How should I make it so my skill remove only one state randomly ?
It's important also that it doesn't remove a state if the battler isn't affected.

Can you help me ? 🙂
I think the easiest way to do it would be to change your Replace State code to:
if (a.isStateAffected(26)) {
a.removeState(26);
} else if (a.isStateAffected(27)) {
a.removeState(27);
} else {
a.removeState(28);
}

(You may also need to change a to b, since a is generally the user and b is generally the target. I don't know how this specific Plugin works.)

This code should remove exactly one Fracture state from the target, prioritizing the first one (26) if it's applied. If it's really important to have it remove one random Fracture state when there are multiple ones applied, it gets more complicated. I think the following might work:

frac_states = [[26, 27, 28], [26, 28, 27], [27, 26, 28], [27, 28, 26], [28, 26, 27], [28, 27, 26]];
var fractures = Math.floor(Math.random() * 6);
var chosen_array = frac_states[fractures];
if (a.isStateAffected(chosen_array[0])) {
a.removeState(chosen_array[0]);
} else if (a.isStateAffected(chosen_array[1])) {
a.removeState(chosen_array[1]);
} else {
a.removeState(chosen_array[2]);
}

(I think you do need the word "var", but you can try removing it from both early lines if this code doesn't work. Also, again, might want to change a to b.)

What that code does is to represent all possible combinations of random first, second, and third choices between the three states, chooses one of them at random, and then iterates through that randomly chosen order until it finds a state on the battler to remove. It should remove one Fracture state that is on the battler, completely at random.
Thank for your help, it works !

I don't really understand those two first lines though.

I'd like to do the same with states 29, 37, 38, 39, 41, 43
Can you help me some more ?


EDIT : I think I get it, but it gets really long lol
There are definitely ways to shorten the code, another similar approach could look like this for example:

Code:
var fractureStates = [26, 27, 28, 29, 37, 38, 39, 41, 43];
var removableStates = fractureStates.filter(function(stateId) {
    return a.isStateAffected(stateId);
});
if (removableStates.length > 0) {
    var randomIndex = Math.randomInt(removableStates.length);
    a.removeState(removableStates[randomIndex]);
}
What this version does is to first list all possible states, then filter them so you are only left with those the target is actually affected with. This way, if there are more than 0 states left, you can pick a random one and remove it.
Math.randomInt(X) should be equivalent to Math.floor(Math.random() * X) here.

Original thread: https://forums.rpgmakerweb.com/threads/skill-that-heal-status-ailment-one-by-one-ve_statereplace.118851/