MV Help understanding a state error

Using Yanfly's states and buffs, elements, passives, auras, and action sequences, i seem to have found myself in a little bit of a funny situation in adding a mechanic. it works as follows: the user uses a self targeting skill that gives it a state with an aura effect. The aura effect adds another state to all alive battlers. Nothing fancy there and has no problem. The state that the aura adds makes it so that every time someone with it is struck with a single target lightning element skill, all their allies (not including themself) take a fraction of the damage the skill did (modified by their lightning resistance). this one seems to be the problem.

My first attempt of the state was this:

JavaScript:
<Custom Respond Effect>
if (this.getItemElements().contains(4)){

var shockT = target.friendsUnit().aliveMembers();
shockT.splice(shockT.indexOf(target), 1);
shockT.forEach(member => member.gainHp(-Math.ceil(value/4)));
shockT.forEach(member => member.startDamagePopup());
}
</Custom Respond Effect>

Thought it'd work, but after testing it i noticed that anything hit by a lightning skill with that state on seems to... die? they take the damage of the initial skill, allies take the intended splash damage, the initial target stays on screen, but they cant attack or be targeted by any skill regardless of the damage dealt. when i hit all enemies with a lightning skill, the fight ends as a victory despite no enemy actually dying. thought it was weird, but as far as i could tell, it should have worked. So i decided to just redo the effect with a different approach.

Second attempt was making it a set of states instead. after some trial and error regarding what the origin of a state applied by another state was, the state above eventually became 3 separate ones. the one above (State 413) eventually became this:

JavaScript:
<Custom Respond Effect>
if (this.getItemElements().contains(4) && this.isForOne()){
target.friendsUnit().aliveMembers().forEach(member => member._shockTransfer = -Math.ceil(value/4));
target.addState(414);
}
</Custom Respond Effect>

State 414 looks like this and has a resist for state 415:
JavaScript:
<Custom Apply Effect>
target.friendsUnit().aliveMembers().forEach(member => member.addState(415));
target.removeState(stateId);
</Custom Apply Effect>

<Custom Remove Effect>
user._shockTransfer = undefined;
</Custom Remove Effect>

State 415 is this:

Code:
<Custom Apply Effect>
user.gainHp(user._shockTransfer*user.elementRate(4));
user.startDamagePopup();
user.removeState(stateId);
</Custom Apply Effect>

<Custom Remove Effect>
user._shockTransfer = undefined;
</Custom Remove Effect>

It works, except for one very slight, but very janky kink. The mechanic for one of my classes is that magic cast by it may be modified through states it applies to itself for an increased mp cost. one of these states makes single target magics become AOE through action sequences. all applicable spells has the following in their notetags:
Code:
<target action>
if user.isStateAffected(100);
action animation: all opponents
action effect: all opponents
else
action animation
action effect
end
</target Action>
Reason for doing it this was that this makes all enemies/allies take the damage/heal at the same time instead of slowly and sequentially. However, since the single target lightning spell is single target in the database even if its aoe through action sequences, it makes isForOne() return true.

At this point, im not even bothered by it bypassing the single target check. What i want to know is why it does what it does. State 415 applies the damage of the effect and is resisted if affected by state 414 - the one that applies it. State 414 applies 415 to all allies sequentially, and then removes itself after the application to all its allies, right?. what happens when i use the class to make ST spells AOE is that each battler gets hits by the initial cast, but then all enemies take the splash damage in a way thats less than predictable. in a 3 enemy setup, they all take a direct hit, 2 of them get damaged through the effect once, and the last one takes the damage twice. wouldnt the expected result would have been either that they all take a spell hit, gain immunity from the splash damage of the one that hit them personally, 414 spreads, then it falls off, and they take the effect damage from the other 2 (meaning apply 415 apply happens after 414 removal), OR the first gets hit and gains immunity from the effect, the second takes the effect damage of the first gets hit by the spell, gains immunity, and the third takes the effect twice and the spell hit once and gains immunity with no immunity falling off until everything if over (415 apply happens before 415 removeal), no?. Additionally, since the 2 instances of bonus damage the one enemy that takes 2 takes arent equal to eachother, theyre distinct calculations, so i know its not showDamagePopup() producing some kind of unintended effect.

1684764373279.png


In an 8 target setup, they all take a skill hit, and they *all* take the bonus damage only once or twice instead of something that would have made more sense like 0-1-2-3-4-5-6-7 or 7-7-7-7-7-7-7-7

1684765152175.png


Does anyone have an idea as to why this is? to clarify, im not looking for a solution to the spell triggering the effect because i know can add !user.isStateAffected(100) to the conditional statement on state 413 and shut it down completely, im just curious as to what order these effects should be happening in and why. It doesnt seem to be right, but theres probably something I dont get here

i've also tried:
Code:
<Custom Apply Effect>
user.removeState(stateId);
</Custom Apply Effect>

<Custom Remove Effect>
user.gainHp(user._shockTransfer*user.elementRate(4));
user.startDamagePopup();
user._shockTransfer = undefined;
</Custom Remove Effect>
thinking that the order of operations here would change if the effect was moved to on state removal instead of application but no difference was made.
Thought it'd work, but after testing it i noticed that anything hit by a lightning skill with that state on seems to... die? they take the damage of the initial skill, allies take the intended splash damage, the initial target stays on screen, but they cant attack or be targeted by any skill regardless of the damage dealt.
In my experience, that happens when you have invalid results in a damage formula. Does it function any differently if you replace the equation in gainHp with a static number? Like, just pass in value unmodified? Or 10?

Reason for doing it this was that this makes all enemies/allies take the damage/heal at the same time instead of slowly and sequentially.
Just FYI, if you set the scope to multiple targets and use whole action rather than target action, that is how it should happen (simultaneously).
In my experience, that happens when you have invalid results in a damage formula. Does it function any differently if you replace the equation in gainHp with a static number? Like, just pass in value unmodified? Or 10?
Back when i was able to get the issue to happen a few times, i saved the notetag in visual studio to hold on to it and rewrote it in MV. I had pasted it from there into the post, and now that Ive put it back in MV from VS it seems to be working fine? the very first iteration of the state had an integer hardcoded into the gainHp function just to see if the effect worked and I think i had the issue back then, but i hoestly cant remember and i cant seem to replicate it anymore. Ill chalk it up as reason #48 to not write code past a certain time.

Just FYI, if you set the scope to multiple targets and use whole action rather than target action, that is how it should happen (simultaneously).
I wasnt sure back when i set the spells up if whole action would have been able to help with my spells since they werent aoe, but now that i think about it, having something like
Code:
<Whole action>
if user.isStateAffected(100);
action animation: all opponents
action effect: all opponents
else
end
</whole Action>
and
Code:
<Target action>
if !user.isStateAffected(100);
action animation
action effect
else
end
</Target Action>
in the same skill would have had the intended functionality, but would isForOne() return false? I defaulted to single enemy scope + target action tag with a conditional for aoe because its the first thing i stumbled into that seemed to have worked as i had intended.

setting the skill to multiple targets isnt an option for me (well, not that it cant, but im stubborn on the effect). the spells are single target by default and there are no aoe spell equivalents like there'd normally be. the state that that one caster can use makes it so that the skill in effect becomes an aoe and hits all foes, but its the same skill in the database. I back when i was putting the spells together i came to this solution because some other alternatives i found (i forgot what ones they were) did stuff like execute the effect sequentially on all foes/allies slowly or hit the primary target, then hit everyone, including the primary target again.
now that i think about it, having something like
You wouldn't want to have stuff playing on all opponents in a whole action. Whole action, by definition, executes against every target within scope simultaneously. So you put any commands in there that you want to be evaluated against individual targets, just like inside target action - only it doesn't happen one at a time.
You wouldn't want to have stuff playing on all opponents in a whole action. Whole action, by definition, executes against every target within scope simultaneously. So you put any commands in there that you want to be evaluated against individual targets, just like inside target action - only it doesn't happen one at a time.
I've changed the action sequence tags in the skill from the one target action block to this:
Code:
<whole action>
if user.isStateAffected(100);
action animation
action effect
else
end
</whole Action>

<target action>
if !user.isStateAffected(100);
action animation
action effect
else
end
</target Action>
and it the spell remained single target with the state on. I added the ": all opponents" to the action animation and effect lines in the whole action block and it looks to be working, but the functionality seems to be the exact same as it was in the first post. It still makes isForOne() return true as well. I dont think I have a plugin installed that changes it, but it seems like the both approaches are equivalent? in either case, it creates the the effect i want, where a spell is a single enemy scope by default, but becomes all enemies when a state is active. I can just include isForOne checks with !isStateAffected() since the state only exists to make spells multi target.

Although, all I can use the Whole action block for other skills. I have a few all ally scope skills that still apply the effects one at a time that I just left alone. Ill be able to atleast speed those up. previously, I was going to make them single target and use a target action block to make the effect work on all allies since i already had the working example from the first post it in the project, but it keeping them on all allies scope and using whole action makes more sense now
I've changed the action sequence tags in the skill from the one target action block to this...and it the spell remained single target with the state on.
I think there is confusion here.

You said:
Reason for doing it this was that this makes all enemies/allies take the damage/heal at the same time instead of slowly and sequentially. However, since the single target lightning spell is single target in the database even if its aoe through action sequences, it makes isForOne() return true.
And I said you don't need to do that, you can make it correctly be all enemies or whatever in the database scope.

Then, if you use whole action instead of target action, it will make them take the effect at the same time instead of slowly and sequentially. I did not say this was a way to help you break the functionality of the skill's scope.

I would suggest you use apply/remove effects on the state to remove the single-target skill and teach an AOE skill with the same name, rather than try to go through hard-coding it in action sequences like that.
I think there is confusion here.

And I said you don't need to do that, you can make it correctly be all enemies or whatever in the database scope.

Then, if you use whole action instead of target action, it will make them take the effect at the same time instead of slowly and sequentially. I did not say this was a way to help you break the functionality of the skill's scope.

I see now, yeah. I misunderstood what you were suggesting the whole action for. I had thought you meant it for the single target spell to become aoe for some reason and not just to speed up aoes in general. Thats on me.

I would suggest you use apply/remove effects on the state to remove the single-target skill and teach an AOE skill with the same name, rather than try to go through hard-coding it in action sequences like that.

I never thought of taking that approach. I had did what i did to preemptively cut down on the number of unnecessary skills in the command lists, but I never thought of making the state enable the aoe versions and disable the default ones. Sounds perfectly doable.

since the spells are learned as a class levels up id probably have to put a show and requirement eval on the default ones for not having the state on, make the state teach the aoe skills, and have the skills only show if the battler is at the right level. Id have to use Aloe's skill/item reorganizer plugin to maintain the display order without moving DB entries since theres skills in the mage's list that arent subject to the state and i set enemy ai priorities based on skill id, but It sounds like itll be better in the long run like this. Thank you for the suggestion.
since the spells are learned as a class levels up id probably have to put a show and requirement eval on the default ones...
For that matter, if you have Skill Core with show requirements, you don't actually need to put any notetags on the skill. You can use a show requirement eval on the original skill to just hide it if you have the state, have a Trait on the skill that grants the new one.

Or have the skills take adjacent IDs in the database so you don't need to muck with any reordering. Have the class teach both simultaneously and use show evals to determine which is visible.

Several routes to success!
Or have the skills take adjacent IDs in the database so you don't need to muck with any reordering. Have the class teach both simultaneously and use show evals to determine which is visible.
If I could give a few tips to my past self about the project, spacing the database entries even more than I did initially would be one of the first ones on that list lmao. much of the earlier stuff like the base spells are pretty jumbled as is and i ended up filling the spaces around them with other skills for other classes. Making them adjacent at this point isnt an option without some reorganizing. Later on, i started making proper labeled partitions to group skills, but the first 200 or so are just a hot mess of damaging skills, buffs, passives, fake items for enemies to use, etc.. Ive been avoiding making changes to it for a long time now

I didnt mention it, but i use yanflys battle aftermath plugin alongside ramza's patch for it. Together they show skills learned by actors via level up after battles according to their active class and subclass. It played a part in my avoidance of making and teaching aoe versions of the spells since the aoe skills would also show up there alongside the base ones and i wanted to give the impression that its one skill, just modified.

making the state grant the skills as well as both hide and disable the base skill sounds like a near perfect solution in this case. They wont be "learned", so they dont show up on the level up screen. The show evals on the aoe skills themselves would manage their visibility for the player since the base skills are learned at different levels and the state by itself would make them all visible once its active. the only thing im unsure of is how enemies will react around it, which is why instead of just hiding the original skills, I'd disable them through a requirement too. But since i use AI priorities for most of my enemies anyways I doubt there would be any actual impact since very rarely does any of them resort to making choices with the default engine

Original thread: https://forums.rpgmakerweb.com/threads/help-understanding-a-state-error.157716/