MZ How to apply only once a buff when using a multi-target skill?

Basically I want a spell that gives a buff to the spellcaster whenever they use it.
But since the spell is on all enemies, the buff is given as many times as there are enemies, which is not the desired effect.
I thought using this Visustella notetag would do the trick, but it seems not.

<JS Pre-Damage>
a.addBuff(5,2);
</JS Pre-Damage>

So is there a way that the buff is applied only once even if there are several targets?
Hi there!

I guess you can make it in a way that only adds the buff if the target does not have:

JavaScript:
if(!a.isBuffAffected(paramId)){
    a.addBuff(5,2)
}

Just replace the paramId with the id of the parameter that the buff is targeting.
You could also use: isMaxBuffAffected to check not only if the target has the buff, but also if the buff is on the max "level".
<JS Pre-Damage> is "aimed at the function: Game_Action.prototype.apply". An action gets applied to each of its targets, thus this notetag runs once per target.

Looks like there are other notetags, though, e.g. <JS Pre-Start Action> hooks into BattleManager.startAction, which only runs once per action. I'm guessing <JS Pre-End Action> can also be used on Skills/Items.
Thank you both 👍

Original thread: https://forums.rpgmakerweb.com/threads/how-to-apply-only-once-a-buff-when-using-a-multi-target-skill.151550/