Set a variable based on the attack used to kill an enemy - Resolved

Need some help, basically I want to set up an effect where if you kill an enemy with a fireball after combat the body has a fire effect, but if you kill them with a sword slash, it has a blood effect.
What I have done so far:
  1. On each skill there is a call to a common event to update the same variable with a unique ID for the skill.
    1. This tracks the most recent attack that was used
  2. On the Battle Event for the troop, on Enemy[1] Hp < 0% trigger event (battle)
    1. Update "killed by" variable to match the most recent attack ID
  3. On Victory right now I have it say "Attack x was used"

Problem I'm not getting the most recent attack I'm getting the second most recent (Sword, followed by Fireball is calling sword not fireball)
Best I can figure is my attack is landing but instead of the attack common event updating BEFORE the enemy dies, its trying to happen after.
Help?


Edit: Thanks ATT_Turan including v[x]=y; in the front of the damage for my attack script fixed this.
I think it was the case that if your attack kills (edit: the last) enemy, the common event doesn't run, or if it runs, only after returning to the map. They made some changes to that at some point, but don't know if it was MV or MZ.

If you're using STEAM, there's a plugin in the RPG Maker DLC folder called 'LastUsedItem', where you can have it store last skill or item ID in different variables.
if it is a lunatic code, update the attack with the variable before it ends
or completed.

or try it with the above plugin that rpgLord69 suggest (which I have no
clue how it works).

but there are methods you could use, but the best way depends on
your skill and common events, and how you control the variable.
They made some changes to that at some point, but don't know if it was MV or MZ.
Not that I know of. That's worked the exact same way since forever, as far as I know. But that's also not the problem that the OP is describing.

Best I can figure is...instead of the attack common event updating BEFORE the enemy dies, its trying to happen after.
Exactly. Common events attached to skills are executed after the skill completely resolves.

All you need to do is set your variable in the damage formula. Annoyingly, that's not in the pop-up text when you mouse over the damage formula field, but it is in the instructions.

Code:
v[69]=15; your regular damage formula
That will set variable 69 to 15. Change the variable number to whatever you're using, and replace 15 with each skill's ID as you copy and paste it.

You could use Yanfly's Passive States and Buffs & States to do this in notetags, but I think that's overkill for what you're doing.

If you do want to make sure the common event runs against the last enemy in the troop, you'll need Himeworks' End Phase Triggers.
Not that I know of. That's worked the exact same way since forever, as far as I know. But that's also not the problem that the OP is describing.


Exactly. Common events attached to skills are executed after the skill completely resolves.

All you need to do is set your variable in the damage formula. Annoyingly, that's not in the pop-up text when you mouse over the damage formula field, but it is in the instructions.

Code:
v[69]=15; your regular damage formula
That will set variable 69 to 15. Change the variable number to whatever you're using, and replace 15 with each skill's ID as you copy and paste it.

You could use Yanfly's Passive States and Buffs & States to do this in notetags, but I think that's overkill for what you're doing.

If you do want to make sure the common event runs against the last enemy in the troop, you'll need Himeworks' End Phase Triggers.
Thank you, I didn't even consider that you can embed scripts in the attack function.

This perfectly did what I was hoping, as now the variable is being set pre-attack, it's being saved as the killing blow on death (even on the last enemy in the troop, I have Yanfly's Combat plugin for other reasons that might of made sure of that.)
Thanks after posting I played with this for a while and made it work, but it was really complicated coding, now I don't even need the common events on the skills.

Original thread: https://forums.rpgmakerweb.com/threads/set-a-variable-based-on-the-attack-used-to-kill-an-enemy-resolved.162656/