MZ Add/Remove State on Actor Skill Use

Good morning beauts!

Another Day, Another hyper specific Plugin request!

For my game I am building a Spellblade class type.

One of the core features of this class will be: when they use certain Basic Magic Type Skills (Fire, Ice, Thunder) in battle they then gain the associated "Force" State.

For Example:
Actor A uses Fire I in battle, Effect: Add State Fire Force to Actor A

The caveats/asks:

1) The plugin/<note tag>/script should be checking what the Class is in use. The Add State can occur to Actors using specific Class(es)
2) I don't want to have to create duplicate versions Skills. This should be an If/Then check


If there is a way anyone can think of to do this utilizing events that would be just amazing as well. Granted Common Event creation/use is probably what I've had the hardest time learning how to do at all.


Skill Focused Plugins in place in case it helps to know:
Skills and States Core VisuStella MZ
Skill Containers VisuStella MZ
Fomar's Equipment Skill
Class Change System Visustella MZ
Summon Core
the problematic part is your wish in combining many features into a single skill, this would have been much easier if you were willing to use duplicate skills.

That said, please check the forum of your maker for a pinned topic on using the damage formula.
Such a topic is available in every maker forum since VXAce, but they require different commands.

In case of MZ, you can add full javascript code into the damage formula, and that includes if constructs that only process part of the code if a condition is met.
This is usually done to make a skill have different effects both on caster and target, but it has some limitations as well - mostly the length and readability of the damage formula.

So you can't use it if you have too many conditions, or if your requirements are too complex. But you can always mix that with other options and it is easy to use damage formulae like
a.add_state(20); 4*a.atk - 2*b.def
adding an if in there is a bit more trickier but has been done before.

There are three more restrictions on the use of the damage formula however:
1) the code is executed for every target, so in a multiple target skill the caster would get the state of the example above multiple times. Not a problem by default (one state only) but a problem with stacking states or some other cases.
2) the skill need to hit to execute the skill, no hit means no added code.
3) the code is executed even if the engine only tests for damage - like if an AI wants to check which skill does more damage, the other coded effects are applied even if the damage is ignored as a test.

It might help and from the way you wrote your request I think you aren't aware of this option.
In case of MZ, you can add full javascript code into the damage formula, and that includes if constructs that only process part of the code if a condition is met.
This is usually done to make a skill have different effects both on caster and target, but it has some limitations as well - mostly the length and readability of the damage formula.
Knowing this is exactly why I steered clear of having the effect be damage formula based and instead opted to ask for a plugin or a patch plugin solution.

The reason I want to avoid duplicate skills is because of the nature of how my Actors learn skills. I can already see the constant back and forth and over abundance of switches I'd need to create if changing classes meant have to check if a skill was already learned to transform that skill into the "Spellblade" version of that skill.

The only other alternative I can think of is to use something like Auto Skill Triggers VisuStella MZ but I've also been trying to avoid being so heavily reliant in VSMZ for moments like this
I can only answer how I would do it in MV, but you may have success with it also in MZ. As far as I know Yanfly's Skill Core is ported to MZ with Project FOSSIL.
I would put the following javascript in either a Custom Execution (if the state should get added before the actual skill execution) or an After Eval (if the state should get added after the rest of the skill has finished executed).
JavaScript:
if(a._classId == spellBladeId) a.addState(forceStateId);
spellBladeId must be replaced with the actual ID of your spellbalde class. forceStateId must be replaced with the ID of the appropriate force state. Since these are notetags for the skill, I presume that you just know what the appropriate force state is and no further checks which kind of skill or which kind of attack element is currently used is necessary.
@eomereolsson you are a gentleman and a scholar.

I'll take a crack at this tonight and report back
No luck so far but I think it's more me than the suggestions that have been made. Shifting more towards this being a common event trigger in the mean time.
Double-post notice: @Puppet Knight

If it's not working, please show a screenshot of what you've done. I can think of some very basic mistakes that could be made simply due to misunderstanding/misinterpreting the line of script, which would be very easy to resolve.
@Puppet Knight If you use VisuStella's Battle Core, try putting the code @eomereolsson provided in the <JS Post-Apply> notetag and tell me if it works.
@Puppet Knight If you use VisuStella's Battle Core, try putting the code @eomereolsson provided in the <JS Post-Apply> notetag and tell me if it works.
This was the fix.

I got fixated on using the JS Post Apply As User variation of this notetag, meanwhile that notetag was built for everything... but skills --_--. Appreciate this catch @Sword_of_Dusk !

@Shaz apologies if my follow up is considered a double post. Was simply providing a separate update hours later. I'll be more mindful

@eomereolsson that's twice now your MV based solutions save my MZ butt haha.


Next step here will simply be to modify the existing States so characters don't end up OP.

This thread can be closed as a resolution was as follows for the Skill Note Tag (ignore the <ap:1>)

1662265170513.png


The result:
1662265302208.png


1662265289562.png


Please let me know if the thread title/subject can be updated to be more search friendly or helpful for anyone encountering tis issue in the future!
@Puppet Knight The last time I was looking through Battle Core for the notetag to help someone else, I got momentarily confused by the tags with User in it myself. Tricky, innit?

Anyway, I'm glad I was able to help in some way.
If you use VisuStella's Battle Core, try putting the code @eomereolsson provided in the <JS Post-Apply> notetag and tell me if it works.
Not entirely sure if this is still a thing in the MZ version, but <JS Post-Apply> likely does not care if the skill used did actually succeed, so I'd recommend to also wrap code you put there into an if-statement to check if it did:
Code:
<JS Post-Apply>
if (b.result().isHit()) {
  // Original Code
}
</JS Post-Apply>
(Unless of course that is intentional)
Not entirely sure if this is still a thing in the MZ version, but <JS Post-Apply> likely does not care if the skill used did actually succeed, so I'd recommend to also wrap code you put there into an if-statement to check if it did:
It actually works in my favor for the state to activate no matter if it hits or not for the Spellblade class since its more about the Casting of the Magic itself.

However

Code:
Code:
<JS Post-Apply>
if (b.result().isHit()) {
  // Original Code
}
</JS Post-Apply>
I can definitely see this being used for chaining some attacks and states.

What I've already incorporated with the Spellblade class is:

Skill: Fire I (the basic magic skill that already exists)
State: Fire Blade (a modified version of Fire Force that Lasts 1 turn and Changes the Attack Skill to "Fire Blade" )



Turn 1: Cast Fire I, Add State Fire Blade
Turn 2: Uses Fire Blade, Add State Fire Force

This sets a nice rotation for the Spellblade.

For the Hit check you added in, I can definitely see me incorporating that into the Muse classes I'm building up.

Original thread: https://forums.rpgmakerweb.com/threads/add-remove-state-on-actor-skill-use.151050/