How does one use Common Events to add a state to a player that an enemy has landed a specific skill on?

I'm trying to make an enemy skill trigger a Common Event that triggers a state change in the targeted (and hit) actor. I have YEP_BuffsStatesCore

This seems like a very simple thing to do but searching the forums and the rest of the internet merely shows that it can be done, just not how. In the character, I have the Common Event working (I can get text from the CE to show) and the best I can figure is to use a Script, but my JS knowledge is beginner. I know variables, variable types, operators, and to be aware that everything is case-sensitive but not a whole lot more than that.

my attempt at a script for this in CE (without conditionals for hit or miss) is:
target.addState(12)
I don't even know what to use from the RMMV library as some links that might have been informative no longer work.
Have you tried adding the state through the damage formula? If the skill hits, the damage formula runs and the state is applied. If it misses, then no state.
I haven't yet but the thing is I want it to run through a Common Event because I need to apply a state to the attacking enemy as well.

All info I read on this says that Skill Effects will only be able to run one Common Event in a character's Skill Effect window
I haven't yet but the thing is I want it to run through a Common Event because I need to apply a state to the attacking enemy as well.

All info I read on this says that Skill Effects will only be able to run one Common Event in a character's Skill Effect window

I think you can apply a state to both the user and the target through formula only. It's still better than with a Common event since you can easily target the user and enemy in the formula field, since you just need the denominators "a" and "b".
Making it through a common event would be a bit more complicated.

Try this:
a.addState(x); b.addState(x)
Where X is the state you're using.

Here's where you can get these formulas from:

You can also try Yanfly's Skill Core where you're able to determine exactly when you want to use these effects:
Thank you so much both for these responses, trying them right away.
So it doesn't appear to be working - Here's some screens of the Skill and States.

Is there anything in here that doesn't line up? I'm treating this as a physical attack

Here's the code in the Skill Note that allows the character to move up to melee range and change animation/pose
<setup action>

display action

immortal: targets, true

</setup action>

<target action>

if user.attackMotion() !== 'missle'

move user: targets, front, 20

else

perform start

end

zoom: 125%, 30

camera screen: target, front center, 30

camera focus: target, front center, 30

wait for movement

motion skill: user

wait: 10

skill animation: target

wait for animation

</target action>

<finishing action>

immortal:targets, false

clear battle log

perform finish

</finishing action>

You may notice the <DragonBone Settings> tags too, those are just to see if the States can also change Battler settings, just ignore that. There was no difference when they aren't there either.
Actually, ignore my above reply because I found I was missing an action effect command and the finishing action was interfering with the skill. I still have problems with making things work but I do have at least one skill working so I have a place to start from. I replaced the code above with:
JavaScript:
<setup action>
display action
immortal: targets, true
</setup action>
<target action>
if user.attackMotion() !== 'missle'
 move user: targets, front, 20
else
perform start
end
zoom: 125%, 30
camera screen: target, front center, 30
camera focus: target, front center, 30
wait for movement
motion attack: user
wait: 10
attack animation: target
wait for animation
action effect
</target action>

I will be updating this thread as I go until everything is solved. I imagine I'll have a lot more troubles with this. Thanks again for your time
So it doesn't appear to be working - Here's some screens of the Skill and States.

Is there anything in here that doesn't line up? I'm treating this as a physical attack

Here's the code in the Skill Note that allows the character to move up to melee range and change animation/pose


You may notice the <DragonBone Settings> tags too, those are just to see if the States can also change Battler settings, just ignore that. There was no difference when they aren't there either.

Try putting a "; 0" in the end of the formula. Since you says it deals "HP Damage" but don't give a value it may be confused and does nothing.
Double-post notice: @cheef

The amount of damage always has to go at the end of the damage formula.
Try putting a "; 0" in the end of the formula. Since you says it deals "HP Damage" but don't give a value it may be confused and does nothing.
The issue was with my sequence note code it seems. I'm slowly making progress. Thanks for responding and suggesting the ; 0 - good to know for future bugs.

My new problem is making the player battler invisible and skipping their turn until either an enemy skill cancels this or until an upper limit of turns passes. I'll post a new thread if that part becomes particularly painful but I'll do my due diligence first before looking for answers here.

please avoid double posting

The amount of damage always has to go at the end of the damage formula.

Sorry about the doublepost! Won't do it again and thanks for clarifying the damage formula.
I'm confused as to why you're using common events at all. This whole thread seems super convoluted to me 😛

To add a state to the target of a skill, you put Add State in the Effects list of the skill in the database.

To add a state to the battler using a skill, you should avoid doing it in the damage formula but you are using Yanfly plugins so you can use the Skill Core notetag:
Code:
<After Eval>
user.addState(12);
</After Eval>

You're also using action sequences, and there are action sequence commands listed in those instructions for adding states to any battler involved (user or target).
I'm confused as to why you're using common events at all. This whole thread seems super convoluted to me 😛

To add a state to the target of a skill, you put Add State in the Effects list of the skill in the database.

To add a state to the battler using a skill, you should avoid doing it in the damage formula but you are using Yanfly plugins so you can use the Skill Core notetag:
Code:
<After Eval>
user.addState(12);
</After Eval>

You're also using action sequences, and there are action sequence commands listed in those instructions for adding states to any battler involved (user or target).
Thank you for replying, I can use all the help I can get. I'll be putting this into practice today. I literally don't even know enough to know the right questions to ask: which is why I asked about Common Events.

This breaks timing or perhaps I'm using it wrong depending on if I place it before or after the Skill Core tag, I'm unsure.
That question has nothing to do with this thread. Please limit your threads to a single question, and post a new thread for the new question. If ATT_Turan's suggestion works, report this thread as solved and it can be closed.
Currently this isn't solved. I was informed by ATT_Turan that my initial question wasn't even something RMMV could do and that the first suggestion - placing state changes in the damage script - is something I shouldn't do.

So now I'm asking about a different solution because if I shouldn't use the first suggestion and instead use the second solution which seems to break the timing of animation changes (the animation changes are now happening after the attack rather than during) with my current solution because I don't know how to make the change happen at the same time as the attack. Or, maybe it doesn't break and I'm just using tags improperly.

I'm asking this so that I can get Dragonbones to alter animations based on events as well as state changes (if that's possible) and my latest question is relevant to such changes affecting actors. If anything, the thread title should probably be changed because what I initially asked can't even be done.

Also, I've edited my previous post and started new threads for anything that is tangential to that subject. Thank you for your patience.
I was informed by ATT_Turan that my initial question wasn't even something RMMV could do and that the first suggestion - placing state changes in the damage script - is something I shouldn't do.

I don't understand either of these. You can absolutely add a state to the target via the skill itself, as well as via the damage formula. Can you (or @ATT_Turan) explain why you can't use either of these options? The only reason I can think of is that there are other requirements that you didn't explain.
To add a state to the battler using a skill, you should avoid doing it in the damage formula..
This is the quote I'm referring to. The suggestion to do it through damage formula does work but Turan suggested I should avoid it - I'm not sure why but I know how finnicky old software can get so I'm just trying to follow the suggestion.

But you know, let's just call this solved. I'll hover around the forums and try more testing. For the time being, I'll just use the damage formula since it seems to work.

Thank you both for the help and sorry for any bumps in the rules of the forum. I'll do my best to stay on precise topics with future posts.
but Turan suggested I should avoid it - I'm not sure why
The main problem is that the damage formula is processed more than once, which means the added code is run more than once as well.

If the engine tries to find the optimum skill for autobattle, the damage formula is processed - this doesn't matter for the damage number that is ignored, but added script commands will take effect even if the engine choses another skill.

If the skill targets multiple enemies, the effect on the skill user is activated once per target instead of one time total.

And a few similar cases where the engine is programmed to ignore the number resulting from a test but cannot handle overriding code.

In this specific case it should not matter because states do not stack and it doesn't really matter how often in the same action the state is applied to the skill user - as long as you don't put the skill user on autobattle.

But for other javascript effects that is not true, which is why people suggest to new users to not rely on the damage formula to create added effects.
I don't understand either of these. You can absolutely add a state to the target via the skill itself, as well as via the damage formula. Can you (or @ATT_Turan) explain why you can't use either of these options? The only reason I can think of is that there are other requirements that you didn't explain.
I didn't say you can't add a state to the target via the skill - in fact, in post #11 I explicitly said all the complicated stuff on this thread seemed unnecessary because the OP should just use the Add State effect 🙂

What I did say is that it's desirable to avoid adding states in the damage formula (not that it can't be done) because it can cause it to happen at undesirable times.

MV uses the evaluate() function when actors are on auto-battle or when skills are given to enemies. Any JavaScript in the damage formula will be executed then, so things that directly modify battlers (like manipulating states) will happen even if the skill isn't actually used.
Thank you very much! This is tremendously enlightening.
If the engine tries to find the optimum skill for autobattle, the damage formula is processed - this doesn't matter for the damage number that is ignored, but added script commands will take effect even if the engine choses another skill.
MV uses the evaluate() function when actors are on auto-battle or when skills are given to enemies. Any JavaScript in the damage formula will be executed then, so things that directly modify battlers (like manipulating states) will happen even if the skill isn't actually used.

So this is ultimately an AI issue where it runs the script in the damage formula in order to determine what skill to use - if it's a number then it wont apply during evaluate but when it's a string, it does when it shouldn't really be doing anything.

Ok, I'll skip the damage formula for now and read into how to notate via Yanfly State changes specifically. I really appreciate everyone's help!
Right. If you know that the skill is only given to players and you will never use the Auto Battle trait, then it doesn't harm anything to put this in your damage formula.

But it's better practice to avoid it so you don't need to evaluate on a per-skill basis, and it's usually easy to do with plugin notetags.

Original thread: https://forums.rpgmakerweb.com/threads/how-does-one-use-common-events-to-add-a-state-to-a-player-that-an-enemy-has-landed-a-specific-skill-on.155565/