skill that heal status ailment one by one VE_StateReplace

thierrywtrmz

Villager
Member
Joined
Jan 30, 2020
Messages
12
Reaction score
2
First Language
French
Primarily Uses
RMMV
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 ? :)
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,624
Reaction score
5,104
First Language
English
Primarily Uses
RMVXA
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.
 

thierrywtrmz

Villager
Member
Joined
Jan 30, 2020
Messages
12
Reaction score
2
First Language
French
Primarily Uses
RMMV
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
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
275
First Language
German
Primarily Uses
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.
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,097
Members
137,588
Latest member
_Coby_
Top