Store ActorID in Variable after using a skill

I've been messing around for a couple of hours now, but I can not get this done.

I want to store the ID of an actor to a variable(502) after they used a skill.

Extra information
I want actors to be able to add effects to their attacks based on their gear/passives etc etc. I want to do this by running a common event with each skill that determines what extra attacks/effects go off with each skill. The common event runs a conditional branch to check which user is using the skill, then uses a bunch of Forced actions to trigger all the effects.

I don't think this should be complicated, but everything I tried until now failed miserably..

Thanks in advance!
Any screenshots you could share so we can understand it better?
In regards to damage skills you can add
Code:
$gameVariables.setValue(1, a.actorId());
to the damage formula.
Non-damaging skills are going to be a bit of a problem. If the a and b are still defined at that point, you could run the same chunk of code inside of the common events, but I'm not certain about that.
The damage formula box also happens to feature a shorthand for getting/setting variables:
Code:
v[1] = a.actorId(); a.atk * 4 - b.def * 2
^ This'll set game variable 1 equal to the skill user's actor ID, then return a damage/healing value equal to 4 times the user's ATK minus 2 times the target's DEF. Note that if an enemy uses this skill, the game will crash, because enemies don't have an actorId method! So this is a safer option:
Code:
if (a.isActor()) v[1] = a.actorId(); a.atk * 4 - b.def * 2
This should only set the variable value if the skill user is an actor. 🙂

Like Poryg says, though, that doesn't help if the skill has no damage formula. I believe this'll get the last battler who used a skill:
Code:
BattleManager._subject
Note that this is not a number, it's an object. You can use the actorId (or enemyId) methods to get the appropriate number, e.g.
Code:
var a = BattleManager._subject; a.isActor() ? a.actorId() : a.enemyId()
^ This should return the skill user's actor ID if they're an actor, or their enemy ID if they're an enemy. It can be used in Control Variables > Script if you like.

If you want the battler's index instead, i.e. their position in their unit (0 = leader, 1 = first follower, etc), try this instead:
Code:
BattleManager._subject.index()
I want to store the ID of an actor to a variable(502) after they used a skill.

Spoiler: The following will set variable ID 502 to the Actor Id but only if the target was hit:
Code:
var _gaa = Game_Action.prototype.apply;Game_Action.prototype.apply = function(target) {var vId = 502;_gaa.call(this, target);if (target.result().isHit() && this._subjectActorId) $gameVariables.setValue(vId, this._subjectActorId);};
Spoiler: The following will set variable ID 502 to the Actor Id no matter if the hit succeeds or not:
Code:
var _gaa = Game_Action.prototype.apply;Game_Action.prototype.apply = function(target) {var vId = 502;_gaa.call(this, target);if (this._subjectActorId) $gameVariables.setValue(vId, this._subjectActorId);};

Created a very small plugin for you 🙂
Spoiler: Simply add it to the plugin manager
ddlkwy0-1c556632-b593-48d2-b360-82e2b2124c4e.png
Let me know if that's how you need it.

VariableToActorIdAfterTurn [Only When Target is Hit] (Plugin): Click to Download
Thank you all for all your help! This community really is the best haha

Poryg & Caetheril: Those work great! I figured out that if you didn't add a damage formula afterwards, the game would deal the amount of damage similar to the actorID. So by adding - a.actorId, that damage is always 0. Like below.

Code:
if (a.isActor()) v[502] = a.actorId(); a.actorId() - a.actorId()

I believe I saw a Yanfly Action Sequence plugin that disables damage popups somewhere. So you could combine those two to have it even work on nondamaging skills without it having to look weird.

Ct_Bolt: This is perfect! Exactly what I was looking for, thank you so much 🙂 !!!
I'm definitely going to use your script, it makes everything so much easier for me. And of course, if I ever get to release it, credited <3

Thank you all so much!
Ct_Bolt: This is perfect! Exactly what I was looking for, thank you so much 🙂 !!!
I'm definitely going to use your script, it makes everything so much easier for me. And of course, if I ever get to release it, credited <3
No prob. Happy to help 🙂 Very glad to hear it works as needed 🙂

Spoiler: Extra info
(If you want to change the variable to be able to be changed in game you could change "var vId = 502" to something like "var vId = eval($gameVariables.value(505))" no quotes.

This would set the variables to the value stored in GameVariable ID 505. So in the game you could change that variable to 502 or whatever needed. (Hope that makes sense)

Happy Game Making!

Original thread: https://forums.rpgmakerweb.com/threads/store-actorid-in-variable-after-using-a-skill.115894/