Check which actor targeted by the skill

Hello everyone, I want to make a skill that shows different animation depending whose actor is being targeted.
I know the simplest one is storing actor's ID in a variable but I have no idea what script call to use and google doesn't find me the solution I wanted.

The general gist of it is:
  • Skill is cast
  • If Actor 1 is the target, plays animation 1
  • If Actor 2 is the target, plays animation 2
  • etc
Thank you!
This seemed like it might not be too difficult to do, so I poked around a little. I think something like this may work:

Sorry if I got your hopes up. I was just about to post a solution when I realized it wasn't what you asked for (it varied the animation based on the caster, not the target). Further poking reveals that it's a little tricky to do what you asked. The best quick solution I can think of right now involves editing rpg_windows.js to modify how the following functions work:

Code:
Window_BattleLog.prototype.showAnimation
Window_BattleLog.prototype.showAttackAnimation
Window_BattleLog.prototype.showActorAttackAnimation
Window_BattleLog.prototype.showNormalAnimation

But that didn't seem quick and useful enough to be worth doing it and posting the code, as it would be code that very easily conflicts with other plugins.

Given that, it may be useful to know what other plugin you use. If you have something like Yanfly's battle plugin, it might even rewrite that part of the code to be easier to customize (though if it's Yanfly, I won't be able to help with modding it).

Spoiler: Bit more detail on why it's tricky
With the above four functions, showAnimation is the initial entry point, while showNormalAnimation is what looks up the actual animation to show from the database.

When the code steps into showAnimation, it still knows who is using the skill, but it hasn't yet broken down the separate targets – it has a list of targets still. Then it immediately throws away the information about who's using the skill and steps through the other functions until it gets to showNormalAnimation. At this point, all it has is a list of targets and an animation ID. It doesn't know who used the skill. It doesn't even know what skill is being used anymore. It just loops through the targets and applies that specific animation to each one.

The quick-and-dirty probably-conflicts-with-stuff solution I had in mind is literally just pass the skill user on down until it gets to showNormalAnimation. Then that function knows what skill was used and can look at its note tags to check how to substitute the animation.
Given that, it may be useful to know what other plugin you use. If you have something like Yanfly's battle plugin, it might even rewrite that part of the code to be easier to customize (though if it's Yanfly, I won't be able to help with modding it).
I do use mostly Yanfly plugins, but I will try to not rely on custom plugins if i can do it with default/script call.

Spoiler parts
Hmm how about just checking which actor as the target? the animation part, I can just use common event to do the rest. The solution I found after googling is to get "actor position" as variable, not the actors themself.
Yeah, that kind of approach can probably work. If you want to set the skill to have no animation by default and it calls a common event which places the animation, then you can use this code:

Code:
(function() {
	Game_Action.prototype.storeInfo = function(target) {
		var item = this.item();
		var v = Number(item.meta.storeInfo);
		if(v) {
			this.target = target.actorId();
		}
	};
	var old_actionApply = Game_Action.prototype.apply;
	Game_Action.prototype.apply = function(target) {
		this.storeInfo(target);
		old_actionApply.call(this, target);
	};
})();

This is a simplification of something I use for a similar purpose. All that does is store the ID of the actor being targeted into a variable. It is extremely specific to a single use case – it probably won't work properly for multi-target skills, and it probably won't work for skills that target enemies. (If you need it to work on enemies but don't need it for actors, you can replace actorId with enemyId.)

To use it, first put it in a plugin file. (My version was pasted into Community_Basic, just to have a place to put it.) Make sure the plugin is enabled. Add <storeInfo:12> to the skill's note box, but replace 12 with the number of the variable you want to use. Make the skill call a common event. When that common event runs, variable 12 will contain the ID of the actor that was targeted.

EDIT: Fixed missing line.
I do use mostly Yanfly plugins, but I will try to not rely on custom plugins if i can do it with default/script call.
if yanfly's action sequences is one of the plugins youre using, you can make the skill play an animation based on what the target is within the sequence
Yeah, that kind of approach can probably work. If you want to set the skill to have no animation by default and it calls a common event which places the animation, then you can use this code:

Code:
(function() {
    Game_Action.prototype.storeInfo = function(target) {
        var v = Number(item.meta.storeInfo);
        if(v) {
            this.target = target.actorId();
        }
    };
    var old_actionApply = Game_Action.prototype.apply;
    Game_Action.prototype.apply = function(target) {
        this.storeInfo(target);
        old_actionApply.call(this, target);
    };
})();

This is a simplification of something I use for a similar purpose. All that does is store the ID of the actor being targeted into a variable. It is extremely specific to a single use case – it probably won't work properly for multi-target skills, and it probably won't work for skills that target enemies. (If you need it to work on enemies but don't need it for actors, you can replace actorId with enemyId.)

To use it, first put it in a plugin file. (My version was pasted into Community_Basic, just to have a place to put it.) Make sure the plugin is enabled. Add <storeInfo:12> to the skill's note box, but replace 12 with the number of the variable you want to use. Make the skill call a common event. When that common event runs, variable 12 will contain the ID of the actor that was targeted.

Spoiler: error
Screenshot 2025-05-28 133201.png
I make a new plugin and called it "Atarget.js", is it because of that? Or because the conflict with other plugins?

@Robro33: What is the name of the target typing? the "character x" one?
What is the name of the target typing? the "character x" one?
its just the IF command mentioned inside the plugin and the script call to identify an actor. it can be shortened based on how you have your stuff organized, but a basic form would just be
Code:
<target action>
if target == $gameActors.actor(1)
  animation 1: target
else if target == $gameActors.actor(2)
  animation 50: target
else if target == $gameActors.actor(3)
  animation 123: target
else if target == $gameActors.actor(4)
  animation 1291: target
else
  action animation
end

wait for animation
action effect
</target action>
and itll play different animations for actors 1-4, and default to the skill's default animation if the target is anything else
its just the IF command mentioned inside the plugin and the script call to identify an actor. it can be shortened based on how you have your stuff organized, but a basic form would just be
Code:
<target action>
if target == $gameActors.actor(1)
  animation 1: target
else if target == $gameActors.actor(2)
  animation 50: target
else if target == $gameActors.actor(3)
  animation 123: target
else if target == $gameActors.actor(4)
  animation 1291: target
else
  action animation
end

wait for animation
action effect
</target action>
and itll play different animations for actors 1-4, and default to the skill's default animation if the target is anything else
yeah, this one is working. Thank you very much! ^^
Sorry, I accidentally deleted one line too many before posting that. I see you've found another solution, but I edited the fix into the previous post anyway, just in case.

Original thread: https://forums.rpgmakerweb.com/threads/check-which-actor-targeted-by-the-skill.177970/