Remove the state which has the most turns remaining?

Soryuju

Combat Balance Enthusiast
Veteran
Joined
Apr 19, 2018
Messages
179
Reaction score
213
First Language
English
Primarily Uses
RMMV
I was wondering if someone could help me implement a system in which status ailment-cleansing skills remove a set number of ailments, and they normally prioritize removing the ailment(s) which currently have the most turns remaining in their duration. I’m using Yanfly’s State Categories to identify “Ailment” states, so buffs and other non-ailment states shouldn’t cause any issues.

So for example, let’s say I Poison a target for 3 turns, and then Silence the same target for 2 turns. A skill which removes 1 status ailment would remove the Poison ailment. If I had used the Poison skill 2 turns before using the Silence skill (so the durations were 1 turn for Poison and 2 turns for Silence), then the cleansing skill would remove Silence instead.

If two or more ailments had the same number of turns remaining, it would be fine for the system to default to removing them in order of their State ID.

How could I go about something like this? Thanks!
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,252
First Language
Spanish
Primarily Uses
RMVXA
you could add a couple of script calls to a common event and use it as the effect of a skill, and it should work just fine.
-you can round up all the states.
-you can sort the lot by remaining time (which is a property of each state)
-you can establish a number of states to remove.
-you can hand-pick remove them, or remove the whole set at once, already through default methods.

that's all that needs to be taken into account when considering the solution, and it all can be done.

I don't know if it would conflict with plugins, tho.... plugins that alter/add/watch states and their timers.
 

Soryuju

Combat Balance Enthusiast
Veteran
Joined
Apr 19, 2018
Messages
179
Reaction score
213
First Language
English
Primarily Uses
RMMV
you could add a couple of script calls to a common event and use it as the effect of a skill, and it should work just fine.
-you can round up all the states.
-you can sort the lot by remaining time (which is a property of each state)
-you can establish a number of states to remove.
-you can hand-pick remove them, or remove the whole set at once, already through default methods.

that's all that needs to be taken into account when considering the solution, and it all can be done.

I don't know if it would conflict with plugins, tho.... plugins that alter/add/watch states and their timers.
I hadn’t tried using a common event yet, though I have to admit, I’m not sure what the the actual JavaScript that corresponds to what you’ve described looks like. I know there’s an a.stateTurns() command I can use, but I’m not sure how to translate that into the JS for comparing the durations of the states on a target and removing the one with the highest number of remaining turns.
 

Soryuju

Combat Balance Enthusiast
Veteran
Joined
Apr 19, 2018
Messages
179
Reaction score
213
First Language
English
Primarily Uses
RMMV
Bumping this because I’m still hitting a wall here.

Right now I’ve got code which can remove all states which last longer or shorter than a specified number of turns, but I still haven’t figured out how to write a condition which will remove a single state with the longest current duration. In other words, I still need code which will compare the state durations to each other, rather than to an arbitrary value. And as I said above, if two ailments have the same number of turns remaining, it’s fine to remove them in ID order.

Here’s what I’ve figured out right now (i.e. what I’ve ripped from Yanfly’s Tips and Tricks), written in the cleanse skill’s notes:

Code:
<After Eval>
var states = target.states();
var category = ‘ailment’;
category = category.toUpperCase();
for (var i = 0; i < states.length; ++i) {
  var state = states[i];
  var turns = target.stateTurns(state.id);
if (state && state.category.contains(category) && turns < 4) {
target.removeState(state.id);
}
}
</After Eval>
Var category is utilizing Yanfly’s State Categories plugin to restrict the removal to status ailments, and the 4 in the “if” conditional is just a placeholder value for testing.

I’m not sure if I can write a basic condition to check for the state with the most turns remaining, or if I’ll need to construct another array, or something else. I’d appreciate any guidance/sample code anyone can offer.
 

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

Latest Threads

Latest Profile Posts

I should realize that error was produced by a outdated version of MZ so that's why it pop up like that
Ami
i can't wait to drink some ice after struggling with my illness in 9 days. 9 days is really bad for me,i can't focus with my shop and even can't do something with my project
How many hours have you got in mz so far?

A bit of a "sparkle" update to the lower portion of the world map. :LZSexcite:
attack on titan final season is airing tomorrow, I'm excited and scared at the same time!

Forum statistics

Threads
105,881
Messages
1,017,227
Members
137,607
Latest member
Maddo
Top