Help with skill cost through Yanfly Skill Core

So I have a system where you can use a skill to apply a state to yourself we’ll call it light 4. Then there are certain attacks that use this as a cost to activate. For example let’s say a skill costs 1 light it would remove light 4 and add light 3 in its place. The problem is sometimes the skills are removing the state entirely and not adding the new ones. Below is the code I’m using for these skills any help would be appreciated. Also the problem seems to mostly pop up on skills that hit more than one enemy.

State 15 is light 4
State 16 is light 3
State 17 is light 2
State 18 is light 1

<Custom Requirement>
if (user.isStateAffected(15) || user.isStateAffected(16) || user.isStateAffected(17) || user.isStateAffected(18)) {
value = true;
} else {
value = false;
}
</Custom Requirement>

<Before Eval>
if (user.isStateAffected(15)) {
user.addState(16);
user.removeState(15);
} else if (user.isStateAffected(16)) {
user.addState(17);
user.removeState(16);
} else if (user.isStateAffected(17)) {
user.addState(18);
user.removeState(17);
} else if (user.isStateAffected(18)) {
user.removeState(18);
}
</Before Eval>
the skills that hits multiple targets will do the eval as many times as the number of targets. You need to put another condition like a blank state on the user so that it only do it once and then use <Custom Action End Effect> to remove that state when the action is over.
the skills that hits multiple targets will do the eval as many times as the number of targets. You need to put another condition like a blank state on the user so that it only do it once and then use <Custom Action End Effect> to remove that state when the action is over.
So when the skill starts I have it apply the blank state and then remove it at the end? What do I need to change in the middle to make it not evaluate multiple times?
end of eval

user.addState(x)

start of eval

if (user.isStateAffected(x))

in blank state custom action end

target.removeState(x)


also if those skills target allies only there is an easier solution, just condition the eval with

(target == user)
There's an easier way to do this. If you're using Yanfly's Buffs and States Core, states can have counters attached to them. By using a counter, you don't need 4 different states; you can just use the counter on 1 state to tally how many 'points' you have left. And when the state counter needs to change, simply change the counter through scripting. The necessary scripts are included in the plugin's help file.
end of eval

user.addState(x)

start of eval

if (user.isStateAffected(x))

in blank state custom action end

target.removeState(x)


also if those skills target allies only there is an easier solution, just condition the eval with

(target == user)
So I tried something like this:

<Before Eval>
if (user.isStateAffected(x))
if (user.isStateAffected(15)) {
user.addState(16);
user.removeState(15);
} else if (user.isStateAffected(16)) {
user.addState(17);
user.removeState(16);
} else if (user.isStateAffected(17)) {
user.addState(18);
user.removeState(17);
} else if (user.isStateAffected(18)) {
user.removeState(18);
}
</Before Eval>

<After Eval>
user.addState(x);
</After Eval>

with state x having the code

<Custom Action End Effect>
target.removeState(x);
</Custom Action End Effect>

It works a bit better but instead of moving from light 4 to light 3 as is should it moves from light 4 to light 2 this was tested on a group of 3 enemies.
No errors? youre supposed to have a bracket after if (user.isStateAffected(x)) and another one at the end of user.removeState(18);

If you did that l dont know what to say, thats the technique l use for upgrading in multi targets skills
There's an easier way to do this. If you're using Yanfly's Buffs and States Core, states can have counters attached to them. By using a counter, you don't need 4 different states; you can just use the counter on 1 state to tally how many 'points' you have left. And when the state counter needs to change, simply change the counter through scripting. The necessary scripts are included in the plugin's help file.
Well that does work exactly the same way and is a bit easier than what I currently have it doesn't solve the multi hit skills evaluating multiple times problem. Do you have an idea of how I can fix it?
This is the new code:

<After Eval>
if (user.getStateCounter(47)===4) {
user. setStateCounter(47, 3);
} else if (user.getStateCounter(47)===3) {
user. setStateCounter(47, 2);
} else if (user.getStateCounter(47)===2) {
user. setStateCounter(47, 1);
} else if (user.getStateCounter(47)===1) {
user.removeState(47);
}
</After Eval>
No errors? youre supposed to have a bracket after if (user.isStateAffected(x)) and another one at the end of user.removeState(18);

If you did that l dont know what to say, thats the technique l use for upgrading in multi targets skills
I added the brackets and it seems like it's still doing the same thing where it is evaluating one less time than there are targets so with 3 targets it evaluates twice.
You're still making this harder than it needs to be. You don't need 4 different statements to do this. Just use user.addStateCounter(47, -1) to subtract 1 from whatever the counter is. And rather than doing <Before Eval> in the skill to reduce the points, use <Custom Execution> so that the code only runs once when the skill is used. That should solve the multi-hit problem.
You're still making this harder than it needs to be. You don't need 4 different statements to do this. Just use user.addStateCounter(47, -1) to subtract 1 from whatever the counter is. And rather than doing <Before Eval> in the skill to reduce the points, use <Custom Execution> so that the code only runs once when the skill is used. That should solve the multi-hit problem.
That worked perfectly. You're a life saver thanks 🙂

Original thread: https://forums.rpgmakerweb.com/threads/help-with-skill-cost-through-yanfly-skill-core.77852/