Last Target Hit Help

I'm fairly new to RPGMaker VX Ace, and I'm trying to set up a skill that does a follow-up skill dependent on the state that the specific target enemy is in.

I've tried a lot of different solutions, all of them close but not exactly what I need.

Right now I seem to be the closest I've ever been, but I need help with code in a Conditional Branch. I currently have "Actor uses skill, which runs a Common Event. That Common Event has a Conditional Branch that is "if last target hit has State X, force action Skill A on last target hit. elsif last target hit has State Y, force action Skill B on last target hit. else last target hit has State Z, force action Skill C on last target hit." etc etc.

My problem: I can get it working for if the actor has a State using "$game_actors[X].states.include?($data_states[Y])" but I need the State Conditional to be based on the target enemy, not the actor using the skill. I see that force action uses the code "action.target_index = last_target_index" for last target, but using that whole string or just "last_target_index" inside the Conditional Branch both result in errors. What is the code for last target hit where I can replace "$game_actors[X]"?

Things I've tried:

  • Yanfly's Follow-Up Skills Script : It's very helpful, but limited to a single skill choice. I've even been able to get a follow up skill dependent on the last target's state using the code below, but the script only allows a single line of code for it's eval. If I try to squeeze in a condition branch inside or several eval sections, the code fails. (This code goes in the Skill's Database note box, which is why it's so limited)
Code:
<follow up eval>
opponents_unit.members[current_action.target_index].state?(state_ID)
</follow up eval>
<follow up skill_ID>
  • Assigning troops to variables based on their position and flipping switches, but it always results in the follow up skill happening on any enemy as long as a single enemy has the state.

  • A Conditional Branch that checks if Enemy 1 has X state, then forcing the action to happen to Enemy 1, but this also happens regardless of who the actor attacked. This could work if the Conditional Branch allowed me to choose "Last Targeted Enemy" instead of choosing an enemy slot.

  • I've also thought about any time an actor attacks an enemy, all the enemy states get mirrored onto the actor, which at that point I could make a condition branch and have it be based on the actor's states. Then I'd have to clear out those new states after their action as well. However, I don't know how to do this and it seems like a huge janky work around for an otherwise easy solution.

Thank you ahead of time for reading and helping!

Let me know if there's any more information I can give to help.

tl;dr : Ruby/RGSS3 code for last target hit?
If you make Scene_Battle.subject an attr_accessor, you can do

Code:
SceneManager.scene.subject.last_target_index
For this kind of thing I usually add a dummy state (that is invisible and does nothing) to the battler that it hits (to make sure the battler won't resist the skill, you can add b.add_state(x); to the beginning of your battle formula, where x is the State ID of the dummy state), and then I have the skill run a Common Event which checks every single enemy (or every single actor if that's who it's targeting) for the dummy state using Conditional Branches. If they have that dummy state, I do whatever other processing is necessary - in your case a follow-up skill on that battler, by the user, using a Force Action command, I guess. At the end of the Common Event, I remove the Dummy State from all enemies (actors).
If you make Scene_Battle.subject an attr_accessor, you can do

Code:
SceneManager.scene.subject.last_target_index

Thanks for the response! I'm not sure where exactly to put that. I looked up what it is and how it can work, but where do I go to even make Scene_Battle.subject an attr_accessor?


For this...

Thank you so much! After hearing some other feedback and using $game_troop.members[x].states.include?($data_states[y]), I was already heading in the direction of dummy states. Using one dummy state that stays on the enemy, and another dummy state that applies and is removed per action allowed dummy state #2 to act as a trigger or catalyst if it detected dummy state #1.

Now my new question is how to make it efficient. Currently, I'm using a lot of built-in scripts that manually runs through each actor, each enemy, and each state. And this is only like 20%. So I'd like to get loops and variables running throughout. Here's what I have to far:

Current:
jEpE8gd.png


Planned/Goal:
Code:
$game_variables[1] = 0
$game_variables[3] = 21
loop
    loop
        begin
            if $game_troop.members[$game_variables[1]].states.include?($data_states[$game_variables[3]])
                  if $game_troop.members[$game_variables[1]].states.include?($data_states[35])
                    $game_message.add("Package detonates")
                    Game_Battler.force_action(117, 0) [FORCE ACTION INCLUDE VAR]
        rescue
            nil
        end
        $game_variables[3] += 1
        if $game_variables[3] = 24
            exit loop
    end
    $game_variables[1] += 1
    if $game_variables[1] = 8
        exit loop
end

I believe I have it all lined up to work by using pure RGSS3, but I don't know the code for force action. I believe the last target is "$game_actors[1].last_target_index" but it could be wrong. I tried "Game_Battler.force_action(skill_ID, enemy_index)" and a few other permutations, but with no success. If you also have other tips or advice for a different way, I'm open to it.

Regardless, thanks for everyone's help so far!
1595464682177.png


Just add that line to line 8, inside the class definition but outside the methods. You could even just make it an attr_reader since you're not assigning a value to it.

Also you can use a .each loop to avoid having to do a conditional branch for every enemy.
Awesome! Thank you, I'll look into that right away!

Original thread: https://forums.rpgmakerweb.com/threads/last-target-hit-help.124330/