$gameTemp.lastActionData(4) doesn't seem to be able to return self target heal skill

When using $gameTemp.lastActionData(4) to gather the actorTarget, it always returns the other actor (there are only 2) no matter who is targeted. If actor 2 targets actor 2 (self) it returns 1.

How do I determine if a heal skill is targeting self, the actor that's casting it?

I need this data before the action is performed and after input is finished.
Can you show where/how you're using it? That should be the correct usage.

Is it a skill for any ally and you're choosing the same actor, or is it a scope of User?
It's a skill for any ally, I need to determine if the caster self targets.

I've moved it dozens of times trying to find the best place to query. This is what my latest attempt looks like:

Game_Action.prototype.updateLastTarget = function(target) { if (target.isActor()) { $gameTemp.setLastTargetActorId(target.actorId()); if($gameTemp.lastActionData(4) === 2) {$gameVariables.setValue(24, 1)}; console.log("last selected", $gameTemp.lastActionData(4)); } else { $gameTemp.setLastTargetEnemyIndex(target.index() + 1); } };

I might want to mention that it's a TP skill.
Ok, your problem is this:

I need this data before the action is performed and after input is finished.

updateLastTarget() is the last thing called inside Game_Action.apply(), so that gets set after the skill has resolved.

Can you just use this inside the damage formula of the skill? Or is that still too late?
Code:
if (a==b) $gameVariables.setValue(24, 1); formula here

Otherwise you'd have to either use notetags from a plugin (like VisuStella Battle Core) or add code to an earlier stage of the battle flow, ignoring the whole last data thing. With the Battle Core, JS Pre-Start Action would do the trick.
Hmm trying to set it in the battle formula isn't something I thought of. I'm not sure if I did it wrong or if it's just not working, this is what I added. (please note the actual heal formula is placeholder and copy/pasted from the basic attack)

if($gameTemp.lastActionData(4) === 2){$gameVariables.setValue(24, 1)} a.atk * (400/(100+b.def))

Does that look right to you? I'm a damage formula infant :LZSlol:
It's a skill for any ally, I need to determine if the caster self targets.

Do you only need to determine if the caster self targets and do you only want to affect something within the scope of the damage formula?

You could do something like this:

JavaScript:
if (b === BattleManager._subject) { 999 } else { 9 }

One problem I can think of with that approach is that if you have any plugins that run eval() on the damage formula outside of the scope where the b or BattleManager._subject variables exist, you could potentially get a crash.

I haven't looked at lastActionData, but I guess it might be safer to check in that regard, in which case you can just swap out 'b === BattleManager._subject' with the relevant lastActionData check.
Yes and no.

I do only want to determine if actor 2 is self targeting. (there's only actor 1 and 2 and they will always be the same actor id), but I'm not limiting the effects to the damage formula.

I need the data to determine how the action battle sequence will play out using VS Battle core.
Something like this should work:

JavaScript:
const actor = $gameActors.actor(2);
const subject = BattleManager._subject; 
const target = BattleManager._targets[0]; // assuming skill is single-target
if (subject === actor && target === actor) {
    // do whatever
}

Potentially in a "JS Post-Start Action" tag. I'm not familiar with VisuStella plugins, but their documentation states that JS Post-Start Action fires at the end of BattleManager.StartAction(), and the above data should be available at that point.
Hmm trying to set it in the battle formula isn't something I thought of. I'm not sure if I did it wrong or if it's just not working, this is what I added.
No - again, lastActionData will get set after the skill has resolved.

Ignore that.

Just check it directly the way I showed in my last post - see if the target is the same as the current actor. a==b

I need the data to determine how the action battle sequence will play out using VS Battle core.
Then any time in the action sequence you should be able to do a conditional to see if user==target
Something like this should work:

JavaScript:
const actor = $gameActors.actor(2);
const subject = BattleManager._subject;
const target = BattleManager._targets[0]; // assuming skill is single-target
if (subject === actor && target === actor) {
    // do whatever
}

Potentially in a "JS Post-Start Action" tag. I'm not familiar with VisuStella plugins, but their documentation states that JS Post-Start Action fires at the end of BattleManager.StartAction(), and the above data should be available at that point.
IT'S WORKING!!! OMG THANK YOU!!!

@ATT_Turan Thank you for your help! I finally have a working function, I really appreciate you looking into it. 🙂
Closed by OP request

Original thread: https://forums.rpgmakerweb.com/threads/gametemp-lastactiondata-4-doesnt-seem-to-be-able-to-return-self-target-heal-skill.161185/