Yanfly's Skill Core: Eval triggering for multiple targets, i only want it to trigger once

Hi there! I'm currently using Yanfly's Skill Core, and am encountering a problem with it's Eval code. I am running a system where I want to increase a variable by a certain amount every time a skill is used. Here's what it looks like currently:

Code:
<Post-Damage Eval>
$gameVariables.setValue(1, $gameVariables.value(1) + 36);
</Post-Damage Eval>

However, for skills that target multiple enemies, the Eval code runs for each target, so if I hit 4 targets with one attack, the variable will increase 4 times.

Is there a way to get it so this only happens once, even if the skill targets multiple enemies?
My first thought is to find a way to check if there are multiple targets and if so, divide the final exp by the number of targets...I'll dig around and see if there's a way to do this. Since you can choose multiple targets directly from the editor, I believe this is possible.

-UPDATE-

I've turned my focus to Yanfly's Target Core plugin, this code specifically:

Code:
  <Custom Target Eval>
  for (var i = 0; i < foes.aliveMembers().length; ++i) {
    var member = foes.aliveMembers()[i];
    if (member.level % 3 === 0) targets.push(member);
  }
  </Custom Target Eval>

The help file reads:

"The 'targets' variable is an array that determines which are the targets
to be used during the selection process. Push the desired targets into
the 'targets' array."

Try this:

Code:
<Post-Damage Eval>
$gameVariables.setValue(1, $gameVariables.value(1) + (36 / BattleManager._targets.length));
</Post-Damage Eval>

-UPDATE- 9:45pm

I just tried the code above with a skill that targets all enemies and while it didn't just crash the game, it didn't have the intended effect either, and the reason is that the post damage eval runs every time the skill does damage...

try the after eval notetag:

<After Eval>
$gameVariables.setValue(1, $gameVariables.value(1) + 36);
</After Eval>

Gonna test this myself and see what I come up with.

-UPDATE- 10:45pm

I believe I have the solution:

Code:
<Custom Target Eval>
for (var i = 0; i < foes.aliveMembers().length; ++i) {
  var member = foes.aliveMembers()[i];
   if (member.name) targets.push(member);
$gameVariables.setValue(98, targets.length);
}
</Custom Target Eval>

<After Eval>
$gameVariables.setValue(99, $gameVariables.value(99) + (36 / $gameVariables.value(98)));
</After Eval>

These two evals should create the desired effect.
First, the custom eval returns the number of enemies targeted by the skill and stores it into variable 98.
Next, the after eval uses var 98 to divide the exp output by the number of targeted enemies.

One thing to note, the math behind this is not completely consistent. When tested against 1 and 4 enemies, both returned 36, since 36 is a multiple of 4. When tested against 5 enemies, it returned 35. I'll work on this for a little bit longer tonight, and see what I can figure out with javascript's Math function by tomorrow evening. Maybe by then someone will have come along and finished the solution for us!
Have you had any more luck with this yet? I'm still working on it and haven't gotten a working solution yet. I do need the math to be consistent, as different encounters have different numbers of enemies.
I did test a simple <After Eval> statement with Skill Core, and it does increment the variable for each battler the skill affects... At first glance, it doesn't seem to be a good solution for this task.

The game's base code has a function that runs each time a skill is used:
Code:
Game_Battler.prototype.useItem = function(item) {
    if (DataManager.isSkill(item)) {
        this.paySkillCost(item);
    } else if (DataManager.isItem(item)) {
        this.consumeItem(item);
    }
};

You can branch off of this to increase a variable whenever an actor uses a specific skill:
Code:
//=============================================================================
// SkillIncrement.js
//=============================================================================

(function() {

var _Damascus7_Game_Battler_useItem = Game_Battler.prototype.useItem;
Game_Battler.prototype.useItem = function(item) {
    _Damascus7_Game_Battler_useItem.call(this, item);
    // The skill ID to check for
    var skill = 89;
    // The variable ID to update
    var variable = 1;
    // The amount to increment
    var increment = 1;
    if (this.isActor() && DataManager.isSkill(item) && item.id == skill) {
        var count = $gameVariables.value(variable);
        $gameVariables.setValue(variable, count + increment);
        // Verify the count
        console.log($gameVariables.value(variable));
    }
};

})();
This will only increment the variable once regardless of the number of targets the skill affects.
Nice! So assuming I would put this in my plugin list, how would I go about implementing this after it's loaded? And also, I will need this to work the same way for every skill that targets multiple enemies, instead of just this one.
The configurable parts of the code are marked by the // symbol... That should be fairly straightforward.

However, if you want every single skill in your game to increment its own variable every time it's used, then that's probably well beyond the scope of perhaps even this thread.

The code I put in my original reply will increment a specific variable each time a specific skill is used. You could easily expand that to work for X number of skills... But you need to think in terms of scope.

If you have 30 skills that each need to increment their own variables each time they're used, that might demand a more comprehensive plugin.

Edit: unless all you're trying to do is increment a single variable each time any actor uses any skill, which is much easier to do.
Essentially what I'm doing is a Talent system, where you gain points in certain Talents depending on how often you use the associated Skills. So I have several different variables tied to different Skills. I'm guessing this won't work if I just copy the code in this plugin several times with different values for each iteration?

I also did just think of a possible workaround with Yanfly's Action Sequences, and I'm a little mad that I didn't realize it earlier since I've been using that plugin for ages. The Action Sequences only run once regardless of the number of targets, and there is an action for changing variables. So if I tack in
Code:
change variable 1 += 36
at the very end of the Action Sequence, it should accomplish what I'm trying to do.

I'll need to test this out at a later date to make sure I'm doing this correctly.
That sounds like it could work. During the action sequence, can you control wether or not the variable changes based on a successful hit or not?

Also, I just finished a variable based weapon mastery system using yanflys weapon unleash and skill core plugins. I have a skill for every weapon type that replaces the basic attack when a character has that weapon equipped. I use this skill to control each variable linked to each character's own weapon mastery levels.

The reason I bring this up is because i use a switch statement to check the actor id of the character using the skill and then change the matching variables. What I am wondering is how are you deciding which characters have access to which talents? is it completely open and any character can level any talent? Do you skills have set talents that they level? If so, using a switch statement to check the actor id could work.
I don't think I can do that with the Action Sequence, but I'm pretty sure Post-Damage Eval only triggers on a hit. There might be a way to combine the two plugins to do this, but I think you'd have to use an 'if' statement, which I don't think you can use in Action Sequences. Regardless, I plan to add the variable even if the Skill misses, so I don't think I need this for my current purposes. Thanks for all your help though!

The Talent system I'm using uses Frogboy's Talent Core along with Talent-Based Traits. This plugin assigns Talents to different actors, so I don't need any script to check actor ID's. Essentially all I do is add "Training Points" to these variables, which go up each time you use a Skill. Then after each battle, a script runs that determines the Training Points for each Talent, and levels up the Talent for each one that's above a certain threshhold.
The best here is to store a boolean in user, and run a test to see if the skill already trigger the portion of code during the turn.

Code:
<Post-Damage Eval> // will run for each target in array
if (!user._alreadyTriggerThisEffect) { // will be true only for first target in array
    user._alreadyTriggerThisEffect = true;
    $gameVariables.setValue(1, $gameVariables.value(1) + 36);
}
</Post-Damage Eval>

<Custom Execution> // custom exe is run before, once, regardles off targets array length
user._alreadyTriggerThisEffect = false;
</Custom Execution>

Original thread: https://forums.rpgmakerweb.com/threads/yanflys-skill-core-eval-triggering-for-multiple-targets-i-only-want-it-to-trigger-once.121536/