Use one common event for multiple skills?

I have some skills that call a common event. Each of them does the same thing but with different parameters, so if possible I'd like to use a single common event for all the skills.

Is there any way to figure out what skill was actually used from inside the common event? I think I found a possible way to do it in battle, but I need it to also work at the menu screen. I also found actor.lastMenuSkill() which is almost what I need, but to use that I need a way to determine which actor used the skill.
I belive it could be done better than my solution, but you could store in some game variable skill name
of skill that was used
Of all the times I've seen this question on the forum, it usually results in an answer that says you need to create a separate skill and common event for each actor.
Yea...unfortunately, when using an item from the menu the actor who used it is stored on the respective scene, but the scene is unloaded (with all its properties) before the common event runs. The scene change is because such events use the map interpreter: there's no special event interpreter for the menu scenes. In short: I don't think there's a way to establish a direct reference in that situation, without a plugin. 😴

If all your skills use the formula box, you can try formulae like this:
JavaScript:
v[1] = this.item().id; a.atk * 4 - b.def * 2
I.e. set a game variable equal to the skill's ID, then process the rest of the formula, whatever it might be, as usual. Skill effects run after the damage formula is processed, so the variable will be set before the event runs. 😮‍💨

(Just a quick note: the damage formula is evaluated to determine an expected value when determining action preferences, i.e. autobattle actors or enemy AI. I don't think the caveat applies in this particular case, but thought it was worth mentioning. 😅)

If (some of) your skills do not use the formula box and you'd like to avoid "0" damage popups, maybe check out Yanfly's Skill Core plugin:
Amongst other things, it offers skill notetags that let you run some JS at various points in a skill's execution, e.g.
Code:
<Pre-Damage Eval>
$gameVariables.setValue(1, item.id);
</Pre-Damage Eval>
😤
Thanks for the detailed replied, Caethyril! I had a feeling it wouldn't be simple and was totally prepared to override some game function to store that info in an accessible place, but I might be able to work with what you've given me.

If all your skills use the formula box, you can try formulae like this:
JavaScript:
v[1] = this.item().id; a.atk * 4 - b.def * 2
I.e. set a game variable equal to the skill's ID, then process the rest of the formula, whatever it might be, as usual. Skill effects run after the damage formula is processed, so the variable will be set before the event runs. 😮‍💨
I've been very much avoiding placing extra statements in the formula box, preferring to create plugins with note tags for fancy effects. However, maybe I can make an exception in this case... at the very least, it's worth a try. The only minor problem is that the skill in question is not a damage skill... so I wonder if using the formula box just to run a command would create some minor issues?

(Just a quick note: the damage formula is evaluated to determine an expected value when determining action preferences, i.e. autobattle actors or enemy AI. I don't think the caveat applies in this particular case, but thought it was worth mentioning. 😅)
Yes, I recall reading about this in the giant damage formula thread that's pinned in the main forum. I don't think it matters in my specific case - although I do have a setting to let you set your party to auto-battle, the content of the variable would only matter if the skill is actually executed, so even if it's redundantly updated when the AI picks a skill, it shouldn't affect anything.

If (some of) your skills do not use the formula box and you'd like to avoid "0" damage popups, maybe check out Yanfly's Skill Core plugin:
Amongst other things, it offers skill notetags that let you run some JS at various points in a skill's execution, e.g.
Code:
<Pre-Damage Eval>[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]$gameVariables.setValue(1, item.id);[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT]</Pre-Damage Eval>
😤
Thanks for the suggestion. I've been steadfastly avoiding most of Yanfly's plugins though (for several reasons, I won't go into them here), so I'd prefer to keep that streak going. That said, I guess it would be really easy to get the same effect by overriding something like makeDamageValue or one of the functions in its vicinity in the call stack, so this is still helpful information.

EDIT: The formula box method didn't work for me, since ultimately what I needed was the skill's target rather than its user which isn't stored in a Game_Action (at least on the menu screen), but I got it working by overriding Game_Action.prototype.apply to store some stuff in the variable. I suppose it might've been "cleaner" to implement a custom skill effect and do away with the common event entirely, but whatever, this works.
The only minor problem is that the skill in question is not a damage skill... so I wonder if using the formula box just to run a command would create some minor issues?
Yea, that's why I separated it into two cases: "skills with formula" vs "skills without formula". By default the formula is run through an eval and rounded down; any error or non-numerical result is parsed as a zero. You could do this sort of thing to be safe (skill Damage Type doesn't much matter because result is 0):
JavaScript:
v[1] = whatever; 0
...but then, as indicated, you'd get "0" popups on hit, which I feel is generally undesirable. Alternatively you could give all relevant skills a damage/healing value and stick that in the formula.

...what I needed was the skill's target rather than its user which isn't stored in a Game_Action (at least on the menu screen)
Wait, you wanted the skill's target? In your opening post you ask for the skill ID, hence my example. 😅

All actions have a subject and a target, it doesn't matter how they're invoked. You can access the target via the damage formula via the local b variable, e.g.
JavaScript:
v[1] = b.isActor() ? b.actorId() : -b.enemyId()
^ This'll set game variable 1 to the target's actor ID if they're an actor, or the enemy ID, times -1, if they're an enemy. It's positive/negative in case you can target both and want to distinguish the targets (also to illustrate that different methods are needed for actors vs enemies).

The oddity in using skills items from the menu is that the user will be a party member with highest PHA. This is because a battler's PHA (pharmacology) param multiplies the healing output of any item they use. I'm quite sure targets are still handled as usual...can check with skill formula console.info(a,b);10, seems OK to me.

I got it working by overriding Game_Action.prototype.apply to store some stuff in the variable.
An alias, right? I think this is the cleanest solution, since you just copy a value to a global position for future reference. 🙏

Anyway, sorry for the wall of text, haha. Good you found a solution, happy RPG Making! 😂

[Edit: correction skills -> items, see following post.]
Wait, you wanted the skill's target? In your opening post you ask for the skill ID, hence my example. 😅
Sorry for the confusion... I wanted the skill ID and the target.

The oddity in using skills from the menu is that the user will be a party member with highest PHA. This is because a battler's PHA (pharmacology) param multiplies the healing output of any item they use. I'm quite sure targets are still handled as usual...can check with skill formula console.info(a,b);10, seems OK to me.
This applies to items rather than skills, right? Skills still have a specific user.
Sorry for the confusion... I wanted the skill ID and the target.

This applies to items rather than skills, right? Skills still have a specific user.
Oh, I see. All good! 🙏

And yes, you're correct. I'll edit my post. 😅

Original thread: https://forums.rpgmakerweb.com/threads/use-one-common-event-for-multiple-skills.122904/