MV Yanfly Action Sequence add/remove State not working consecutively

I'm working on a combat system with timed inputs for blocking. Due to various complications and whatnot, I'm now in a position where I apply 2 states when the timed input was hit correctly.
1683194525159.png

1683194542675.png

This makes it so that both my characters can block, but one character only blocks 25% of damage, while the other blocks all damage. Both states are applied in the action sequence code to the target of the enemy attack, but each actor is state resistant to the other actor's block state.
1683194624437.png

1683194633223.png


This has worked fine for single hit attacks. Today I wanted to make a 2 hit attack, and suddenly it's not working correctly anymore. The state is properly applied on the first block, but not on the second. Curiously if you don't block the first hit, the second block applies the state as intended and I don't know why it does that.
Spoiler: AS Code
<Max Mastery Level: 0>
<custom target eval>
var targetActor = $gameParty.members().reduce(function(prevActor, currActor) {
return prevActor.tp > currActor.tp ? prevActor : currActor;
});
targets.push(targetActor);
</custom target eval>
<setup action>
camera focus: user, center, 0
zoom: 120%, 20
wait: 20
immortal: targets, true
</setup action>

<target action>
se: Jump2
PROJECTILE ANIMATION 78: START user, GOAL user, START OFFSET -0 +0, GOAL OFFSET -0 +0
move user: target, front, 40, offset x +60
jump user: 200%, 40
motion evade: user
wait: 10
CHANGE VARIABLE 100 = 0
start sequence input: ok, 100
wait: 10
animation 56: target
animation 13: target
wait: 25
end sequence input
motion swing: user
wait: 13
if $gameVariables.value(100) > 10
add state 28, 29: target
eval: target.battler().setFrame("missile", 1);
se: Block Hit
animation 29: target
action effect
shake screen: 5, 5, 8
eval: target.battler().setFrame("missile", 1);
wait: 10
remove state 28, 29: target
eval: target.battler().removeMaxFrame()
else
animation 160: target
action effect
immortal: targets, false
flash screen: 255, 0, 0, 80, 10
color break: intensity 40, duration 10
shake screen: 5, 5, 8
if (target.name() === 'Dunstan')
common event: 12
else
common event: 13
end

CHANGE VARIABLE 100 = 0
start sequence input: ok, 100
animation 56: target
animation 13: target
wait: 15
motion thrust: user
wait: 13
end sequence input

if $gameVariables.value(100) > 0
add state 28, 29: target
eval: target.battler().setFrame("missile", 1);
se: Block Hit
animation 29: target
action effect
shake screen: 5, 5, 8
eval: target.battler().setFrame("missile", 1);
wait: 10
remove state 28, 29: target
eval: target.battler().removeMaxFrame()
else
animation 160: target
action effect
immortal: targets, false
flash screen: 255, 0, 0, 80, 10
color break: intensity 40, duration 10
shake screen: 5, 5, 8
if (target.name() === 'Dunstan')
common event: 12
else
common event: 13
end

wait: 20
move user: return, 20
motion walk: user
face user: backward
wait: 20
face user: forward
</target action>

<finish action>
perform finish
wait for movement
wait for effect
wait for camera
</finish action>

As you can see in the code above, the block condition is the same code for both instances of the hit. The sequence itself works (The block motion, animations and screen shake all play out as intended), but the damage gets applied on the second hit regardless and the state is not applied.


Block(1).gif


In the gif you can see on the scuffed hud how the state gets applied and removed as it should on the first block, and nothing on the second...

I hope someone has any smart ideas to solve this.
This is actually intentional in RPG Maker. When a state is removed, it goes into a temporary removed states list to prevent accidentally adding it back on within the same action.

Try this: after you remove the two states in the first swing, add this:
Code:
eval [28, 29].forEach(stateId => target.removedStates.splice(target.removedStates.indexof(stateId)))

See if that does the trick.
This is actually intentional in RPG Maker. When a state is removed, it goes into a temporary removed states list to prevent accidentally adding it back on within the same action.

Try this: after you remove the two states in the first swing, add this:
Code:
eval [28, 29].forEach(stateId => target.removedStates.splice(target.removedStates.indexof(stateId)))

See if that does the trick.
Tried:
Code:
if $gameVariables.value(100) > 10
    add state 28, 29: target
    eval: target.battler().setFrame("missile", 1);
    se: Block Hit
    animation 29: target
    action effect
    shake screen: 5, 5, 8
    eval: target.battler().setFrame("missile", 1);
    wait: 10
    remove state 28, 29: target
    eval: target.battler().removeMaxFrame()
    eval: [28, 29].forEach(stateId => target.removedStates.splice(target.removedStates.indexof(stateId)))
else

No change in behaviour. No errors or anything in the console either.
Oops, that's not on the battler, it's on the action result. Change it to:
Code:
[28, 29].forEach(stateId => target.result().removedStates.splice(target.result().removedStates.indexof(stateId)))
Code:
eval: [28, 29].forEach(stateId => target.result().removedStates.splice(target.result().removedStates.indexof(stateId)))
Again no change. 🙁
But at least the console now has this:
1683206039426.png
...because it's indexOf, capital "O". I'm gonna go back to sleep.
...because it's indexOf, capital "O". I'm gonna go back to sleep.
Alrighty, that seems to have done the trick. Awesome. You can now go back to sleep, you've earned it😀

Oh, and the thread can be closed I suppose.

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-action-sequence-add-remove-state-not-working-consecutively.157209/