How to make a skill apply a status to self only once?

Hey all. I'm having a problem with a particular skill I'm trying to create:
The skill is meant to do three things: deal damage to the enemy, give a stacking buff to the caster, and remove specific other buffs that the caster has.
The Problem: While the effect works fine when it's used with a single target skill, when it's used in a multi-target or multi-hit skill, like an 'All Enemies' skill, the skill applies a stack of the buff for every enemy hit (or, more specifically, whenever the skill hits an enemy) which is not the intention - it should still only give one stack of the status for each usage of the skill.
The formula used is as follows:
a.addState(19); a.removeState(16); a.removeState(17); a.removeState (18); a.removeState (22); a.removeState (23); a.removeState (24); a.removeState (25); a.removeState (26); a.removeState (27); 60 + a.mat * 2.5 - b.mdf * 2
State 19 is an invisible state that works as a background process to make sure the stacking effect works. State 19 has the following code:

<Custom Apply Effect> if (user.isStateAffected(15)) user.setStateTurns(15, 4); else if (user.isStateAffected(14)) { user.removeState(14); user.addState(15); } else if (user.isStateAffected(13)) { user.removeState(13); user.addState(14); } else user.addState(13); target.removeState(19); </Custom Apply Effect>

Any help appreciated.
I think that stuff above might be more complicated than it needs to be, but it doesn't appear to be related to the issue of what you're doing within the skill.

I'd make a dummy state to track whether it's been done this action.
Code:
if (!user.isStateAffected(69))
{
// Do whatever you're already doing here
    user.addState(69);
}

Then give state 69
Code:
<Custom Regenerate Effect>
user.removeState(69);
</Custom Regenerate Effect>
Apologies, I'm not sure if I fully understand what you're asking me to modify.
Are you saying that I should do something like this?
<Custom Apply Effect> if (!user.isStateAffected(69)) { user.addState(69); } if (user.isStateAffected(15)) user.setStateTurns(15, 4); else if (user.isStateAffected(14)) { user.removeState(14); user.addState(15); } else if (user.isStateAffected(13)) { user.removeState(13); user.addState(14); } else user.addState(13); target.removeState(19); </Custom Apply Effect>

Edit: I tried the above, and the dummy status shows up when hitting the enemy rather than the casting of the action, so maybe that is the problem?
Sorry to doublepost, but I think I found a solution that I'll add here for posterity:

It seems the problem was that I placed the addition of the status in the damage formula, which caused the status to be applied every time the damage formula would also apply (such as calculating damage)

The solution is to create a Common Event whose sole purpose is to add the background status to the character, and then make it so that the skill invokes the common event whenever it's used, resulting in the stacking effect only applying once instead for each enemy hit.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-a-skill-apply-a-status-to-self-only-once.165260/