How do I make a common event that triggers when an Actor takes damage? (MV)

I've been trying to do this for 2 days now, and I'm losing my mind over it. I want to make a common event where an Actor takes damage, and it triggers something, so let's say I want it to trigger an animation when the Actor takes damage. Im not sure how to do this, so if someone knows how, can you help?
it depends on how the actor is supposed to take damage and where.

if it is on the battlescreen, you're better off using a troop event - and anywhere else it depends how the damage is done.
it depends on how the actor is supposed to take damage and where.

if it is on the battlescreen, you're better off using a troop event - and anywhere else it depends how the damage is done.
Hm, yes it's on the battle screen, the character is supposed to take damage from the enemy attacks. and I've been trying to use the troop event. thing is, I don't really know how to set the event up.
Hello, my friend. I will help you with this, please follow the steps I will describe, okay?

1) Place the Eventdmg.js file in your plugin folder and activate it through your plugin manager. (I will attach it to this message)
Spoiler: Print 1
print1.png

2) Now configure the enemies in your battle database. In the "Battle Events" tab, set the condition to "end of turn" and the span to "turn", then add the following script call:
Code:
var actorId = 1;
var actor = $gameActors.actor(actorId);

if (actor && actor.isBattleMember()) {
    var damage = actor._lastDamageTaken || 0;

    if (damage > 0) {
        $gameTemp.reserveCommonEvent(10);
        actor._lastDamageTaken = 0;
    }
}
In my example, I make the event trigger only for actor 1 and the common event activated is number 10. All of this can be edited by you.
Spoiler: Print 2
print2.png

3) Now just start a new game in a test map and experiment with the effects you want. I opened it in a blank file and it works perfectly for me; I hope it’s useful to you.

Good luck with your projects!
Using a plugin as already suggested works fine; yet I want to propose a way that uses pure eventing:

On game start, initialize a Variable "Last Actor HP" with Game Data: Actor HP.

Make a Common Event with Parallel Process that always runs. It will look like this:

Code:
Variable OP: "Current Actor HP" = Game Data: Actor HP
Branch: If "Current Actor HP" < "Last Actor HP"
  Variable OP: "Last Actor HP" = "Current Actor HP"
  ... your stuff here
End Branch

Mind: Your stuff runs as soon as your Actor's HP is lowered by any means, regardless of whether it was caused by damage or any other event. When that doesn't suit you, you are probably better by using a plugin as already suggested.


EDIT:
Will not work in battles.
If I recall correctly paralell common events only run in map scenes?
If I recall correctly paralell common events only run in map scenes?
Yes, if you did it Aerosys' way you'd have to use a plugin like NRP Parallel Common Event in Battle
What @Aerosys suggested won't work without plugins. I also don't think you need to go making brand new plugins with complex script calls, because from your description the common event is not actually necessary.

I would suggest using something simple like Yanfly's Buffs & States and Auto Passive States.

Give the actor a passive state with the notetag:
Code:
<Custom Respond Effect>
if (value > 0)
    target.startAnimation(50);
</Custom Respond Effect>

That will play animation 50 on the target each time they're hit.
Yes, if you did it Aerosys' way you'd have to use a plugin like NRP Parallel Common Event in Battle
Ah sorry, I wasn't aware of that.
@ATT_Turan, could you please explain a little better what you mean? I got the Auto Passive State just now, and I'm not sure how to use that.
Please be more clear about what you don't understand.

The plugin instructions tell you how to make a passive state on an actor. I gave you the code you would copy and paste into the state's notebox (which requires Buffs & States to function).

I'm happy to help, but I don't know which part of the process you can't do.
Well. I downloaded Buffs And States, so do I just copy and paste what you coded in my actors notes, and it would work?
Sorry if im being a hassle, Im sort of new to this.
No, the passive state has the notetag.

Give the actor a passive state with the notetag:

Then make sure you notice:
That will play animation 50 on the target each time they're hit.
so, logically, if you want a different animation to play, you change which number is inside the parentheses in the code.
No, the passive state has the notetag.



Then make sure you notice:

so, logically, if you want a different animation to play, you change which number is inside the parentheses in the code.
So your saying to make a new state, and put that in the notes of the states? (Im also confused about the "Value > 0")
It would be great if you have the time to do a step by step explanation, and how to trigger the passive state when the actor takes damage.
It would be great if you have the time to do a step by step explanation
1 - download and install the two plugins I said you need.
2 - make a state in your database and follow the plugin instructions to make it be a passive state on the actor in question.
3 - paste the code I gave you into the notebox of that state.

If you're looking to understand what each line and statement of the code means, it's better to start doing JavaScript tutorials for that. Just isolated bits of knowledge are not super useful, in my opinion.
Im also confused about the "Value > 0"
thats provided by the buffs & states plugin. value is the incoming damage or healing an action is about to do (value, not Value)

and how to trigger the passive state when the actor takes damage.
also covered by buffs & states plugin. thats what <custom react effect> does. it runs the code in the tag as a response to the battler with the state being hit by an action. if you made the state a passive and gave it to the actor, then theyll already have
Hello, my friend. I will help you with this, please follow the steps I will describe, okay?

1) Place the Eventdmg.js file in your plugin folder and activate it through your plugin manager. (I will attach it to this message)
Spoiler: Print 1

2) Now configure the enemies in your battle database. In the "Battle Events" tab, set the condition to "end of turn" and the span to "turn", then add the following script call:
Code:
var actorId = 1;
var actor = $gameActors.actor(actorId);

if (actor && actor.isBattleMember()) {
    var damage = actor._lastDamageTaken || 0;

    if (damage > 0) {
        $gameTemp.reserveCommonEvent(10);
        actor._lastDamageTaken = 0;
    }
}
In my example, I make the event trigger only for actor 1 and the common event activated is number 10. All of this can be edited by you.
Spoiler: Print 2

3) Now just start a new game in a test map and experiment with the effects you want. I opened it in a blank file and it works perfectly for me; I hope it’s useful to you.

If this has been helpful and you want to give back, consider checking out my project Apu's Journey here on the forum. It would be great if others could take a look. Good luck with your projects!
If I wanted to make this happen to the group leader, would it be like this?
If I wanted to make this happen to the group leader, would it be like this?
Did you give up on the buffs and states core solution?
Did you give up on the buffs and states core solution?
Nope, Im watching a tutorial on it, but I wrote that just in case.
I watched many tutorials, on Auto Passive states, Buffs and States Core, and even some about Java Scripting for RPG Maker. I understood somethings, but I am still so confused.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-make-a-common-event-that-triggers-when-an-actor-takes-damage-mv.170914/