Retaliate Skill?

I want to have a skill where an actor spends one turn guarding, then on the next turn deals damage based on the damage taken during the turn they were guarding. I've looked through Yanfly's stuff and seen some of the Lunatic stuff, but aside from damage based on total HP lost over the course of the battle, I don't know if there's any method via those scripts to ONLY take into account the damage taken on that specific turn.

Is there any way to do this with the Yanfly scripts or some other scripts? Is there any way to do this with RTP?
I'd say you can do it using Troop Events but how to do that depends a lot on how you want that skill to deal damage. Is it a skill that should damage everyone in the enemy team? Is it a skill that targets only a single enemy? Does it have to target only the last enemy who dealt damage?

Depending on those factors you should set up your skill and event differently.
I'd say you can do it using Troop Events but how to do that depends a lot on how you want that skill to deal damage. Is it a skill that should damage everyone in the enemy team? Is it a skill that targets only a single enemy? Does it have to target only the last enemy who dealt damage?

Depending on those factors you should set up your skill and event differently.

Hmm... I honestly don't see any way to have a character attack via event at all, much less with Troop Events. And even if you could, there would be no real way (as far as I can tell) to ONLY trigger that when the character uses the skill in question.
I honestly don't see any way to have a character attack via event at all
You can force actors to perform attacks with events so yes, you can. HOW you do it depends on the answer to my questions, that's why I took my time asking them.

When asking for help you should understand that if you do not share the necessary informations people can hardly help you. Even assuming you cannot do it using events and you need a script for that, without knowing how you want it to retaliate we cannot tell you if a certain script works for you or not.

Let's say - for the sake of speaking - that you want to retaliate storing up damage and inflicting that amount to every enemy. If I knew of a script that divides that value by the number of enemies that's not what you are looking for, is it? So those informations ARE necessary if you want some help. Please provide more informations and I'll be glad to help you.

Anyway forcing actions is a nice way of using something like a retaliation attack against random targets or the whole enemy team. You might be amazed to see how many things you can actually do with just battle events.
Troop Events -> Force action. I use it all the time to set up my 2 and 3 turn bosses so they have different patterns on each turn of the round. And, you can use it to simulate someone not in the battle party sniping at the enemy too if you wish, just use force action on an actor that is in the database and initialized, and it will work just fine*.

*: Unless a script interferes with it.
You can force actors to perform attacks with events so yes, you can. HOW you do it depends on the answer to my questions, that's why I took my time asking them.

When asking for help you should understand that if you do not share the necessary informations people can hardly help you. Even assuming you cannot do it using events and you need a script for that, without knowing how you want it to retaliate we cannot tell you if a certain script works for you or not.

Let's say - for the sake of speaking - that you want to retaliate storing up damage and inflicting that amount to every enemy. If I knew of a script that divides that value by the number of enemies that's not what you are looking for, is it? So those informations ARE necessary if you want some help. Please provide more informations and I'll be glad to help you.

I thought I was pretty clear on what I wanted:

I want to have a skill where an actor spends one turn guarding, then on the next turn deals damage based on the damage taken during the turn they were guarding.

That seems fairly self-explanatory to me. You use the skill, the actor guards for one turn, the enemy deals damage to that actor, then the next turn the actor attacks a random enemy (or perhaps all enemies, I haven't decided that just yet) and deals damage based on the damage taken ONLY during the turn on which the actor was guarding, and ONLY based on the damage done to the actor who used the skill. What critical information did I leave out here that the post didn't make clear that would prevent you from helping me?

Troop Events -> Force action. I use it all the time to set up my 2 and 3 turn bosses so they have different patterns on each turn of the round. And, you can use it to simulate someone not in the battle party sniping at the enemy too if you wish, just use force action on an actor that is in the database and initialized, and it will work just fine*.

*: Unless a script interferes with it.

Ah, now I see that. I feel like a moron now. That said, I still need to figure out a way to calculate the attack based on the damage done by the enemy, and ONLY the damage done THAT actor on the guarding turn and NO OTHER previous turn. Any ideas on that?
I thought I was pretty clear on what I wanted
It was not, you left away the most important part of all of it: how you want to target your enemy. Different targets have to be handled differently and you cannot pretend someone writes you a whole new guide just because you left apart an important detail.

Anyway now that I know you want to use random targets (or all enemies) it is much easier to explain. Since both options work in the same way we can solve this with a single explanation. I am starting from the assumption you have only a single character who is able to use this skill. If you have more than one then you have to use a damage formula instead of using a common event when casting your skill.

Spoiler: One way of doing it
1. Mark your actor
This is pretty much self explanatory but when using your skill you have to mark your actor so that you can calculate how much damage he took later on. You can do it in many ways but since you want to apply something like a guard state to that actor I think using the state itself would be fine. Keep in mind that if you want to use the state itself to mark your actor you have to create a new state for this purpose, otherwise you will track down the first actor who guarded.

2. Store your actor's current health
One way of storing damage would be that of calculating the difference between you actor's health when the skill is supposed to retaliate and the health she had when the skill was first cast. First of all let your skill call a common event (or use its damage formula for the same purpose) and store your actor hp (not mhp, just hp) into a variable. If you want to use your damage formula you can just use
Code:
$game_variables[id] = a.hp
If you want to use a common event then you have to point the character who's able to cast this skill and store her hp.

3. Start a timer
You also need a variable to act as a timer to see how many turns you spent charging so that when you are ready you can retaliate. That variable must be set to 0 whenever you cast your skill and should then be increased every turn (using troop events). This means you probably want to use a switch to tell the engine when to increase that variable and when not.

4. When it's time retaliate
When your timer variable reaches the value you want it to you can finally force an action on your actor and retaliate. Your damage will just be calculated as follows
Code:
r = $game_variables[id] - a.hp
The variable you use here is the same one you used when storing your actor's hp.
You can force that action against a single random target or against all enemies, that's up to you depending on how you want the skill to affect your gameplay.

5. Reset counters
After casting your skill do not forget to remove the marking state from your actor and to reset bot your switch, your timer variable and the variable you used to store actor's current hp.

This is not the only way of doing and it has good and bad points.

GOOD POINTS:
  • Very easy to set up
  • No script needed
BAD POINTS:
  • If you heal your actor that will reduce the amount of damage stored
  • You can only have a single actor using this skill

Of course if those bad points are too bad for you it means you have to do it in a different way but, as I said, you gave us a bit too few informations, regardless of what you think being self-explanatory or not. So this is everything I could do to help you lacking so many details.
I just used that solution (as it seemed to handle every concern I had), but I think I must have done something wrong, because the moment the skill (I called it "Fury Counter") is used, the game freezes.

Here are some screen grabs to give some context that will hopefully help solve the problem:
Spoiler
I split the skill into two; one is the "guard" version, i.e., the one that the player actually activates and causes the special state I created to occur, and the other is the actual attack meant to be triggered by common event. Here's the "guard" skill:
Fury Counter 01.JPG

And here is the "Attack" skill:
Fury Counter 03.JPG

Here's the special state I added:
Fury Counter 04.JPG

Here's the common event:
Fury Counter 02.JPG

and finally, the battle event, set as a base troop event via Yanfly's script:
Fury Counter 05.JPG

I hope that's enough info.
Now, that's what I call "giving necessary info"! Thank you, this way it is much easier to identify your mistake. It freezes because your common events contains an infinite loop.

If you want to use a common event then you have to point the character who's able to cast this skill and store her hp.

3. Start a timer
You also need a variable to act as a timer to see how many turns you spent charging so that when you are ready you can retaliate. That variable must be set to 0 whenever you cast your skill and should then be increased every turn (using troop events).

As I said your common event has to store your character current HP and has to set your turn timer to 0. Everything else should be handled by troop events. Basically what's inside your loop should be moved in your troop event with a conditional branch to check Fury Counter Turn (variable 74) value. It can be 1 if you put your check ABOVE the part where you increase it or it can be 2 if you put your check BELOW it. It makes absolutely no difference from the player's point of view. From your point of view it simply is a graphical preference since if you remove the Fury state then you won't be increasing variable 74 in the next branch so having the check before that increment is perfectly fine.

Spoiler: A little advice
One more thing: Labels are ABSOLUTE EVIL!!!!! Try to avoid them as much as possible. Every thing you can do using them can be done using breaks or branches making your events much easier to read. It is not a big problem if you only have one, even Linux source code contains around 3 - if I am not mistaken - "goto" but anyway the more you can avoid those, the better.

If you are interested you can look for Spaghetti Code on google (or wikipedia). It should give you a clear understanding of what I mean. As I said it still works and it is not a problem if you only use a single one but when you start using a lot of them correcting your code becomes a real pain.

NOTE: you have to take these things into account especially if you plan on asking for help. It is very unlikely that someone wants to spend a whole day looking into many goto (label and jump to label) just because you wrote a spaghetti code. It is much more likely that they will just leave it at that without helping you. So using proper structured programming is not good only for others but also for you because you can get help faster.

It is more or less the same thing about giving all the necessary details when asking for something. Nobody is gonna write a whole tutorial that explains the whole world of possibilities just because your post was lacking important details. The lesser the time people have to spend to help you, the more likely you are to get help from them and the faster you solve your problem.

I hope this helps you.
YESSSSS IT WOOOOOORKS!!!!

Also, I'll keep that advice in mind from now on. Thank you for helping!

Original thread: https://forums.rpgmakerweb.com/threads/retaliate-skill.96412/