Checking Both the User and Target of an Item or Skill?

Hello! I'm unsure if this is something that would require an MV-Specific Plugin/Solution or not, so I'm hoping this is the right section.

What I am trying to do is increase "bond points" (currently stored in a Variable, but please let me know if there is a better method than variables) between characters through their actions in battle (There are six playable characters, but only three can be in battle at once, if that affects anything).

All six characters can increase their own "Bond Points" variable with each other by either giving each other healing items in battle, or by using skills on each other (for example, if Character A uses [Heal] on Character B, the "Character A + B Bond Points" variable will increase).

Currently, each combination of two characters has their own specific variable. For example, "Character A + B Bond Points" is Variable 1, and "Character A + D Bond Points" is Variable 3.

The issue I am having is how to check who the User and the Target is for a skill or an item, and how to make this lead to increasing a variable. I am especially having trouble trying to figure this out with items, since items can be used by anyone, and can target anyone. I'm also unsure of how to get this to work with target-all skills or items, since there are multiple targets and variable that would need to be checked.

So to try and summarize:
  • I would like to be able to check both the User and the Target(s) of a skill or an item after it is used, so that I can increase a specific variable depending on the User and Target(s).
  • There are 6 characters, and every combination of 2 has their own unique "Bond" Variable.
    • Example "Character A + B Bond Points" is Variable 1, "Character A + C Bond Points" is Variable 2, etc.
  • While I would like for this to also work on skills and items that also target the user (such as a Healing item that targets everyone), it is fine if that is unable to work! At the least, I just need the single target skills and items to work!

Thank you for reading! If anything is unclear, please let me know, and I will try to clarify!

Also, I am using the Chrono Engine Battle System, if that makes any difference in how this could work.
Both items and skills are handled in the code as the same type of object, and both the target and user ARE referenced.

The usual "solution" for something like this is to have the items/skills set a state and check for that state at the next opportunity, removing said state when done.... but I'm not sure that would work for you.

If you're using Yanfly's SkillCore (probably have the name wrong, it's off the top of my head) you can use JS code for different stages of a skill use, and use a for user and b for target, just like the formula bar. But you'd have to do that for EVERY skill or item that can trigger those effects.
This would be a lot easier, though, if you have access to Yanfly's Buffs and States Core and Auto Passive States.
Thank you both for offering to help!
Trihan, I do have access to both of those Yanfly plugins, so that's no issue! 🙂

Drakkonis, I do have Yanfly's SkillCore, though I think I'm still lost on how to check who exactly the user and target is inside Formula/JS code.

So for skill core, I'd use <Post-Damage Eval>. Would the code inside <Post-Damage Eval> be something like:
"if a.isActor(1) & if b.isActor(2)), v[1] +5, else if a.isActor(1) & if b.isActor(3)), v[2] +5, else if...", continued for every combination of actors? Sorry the formula I wrote is probably wrong, I've only gotten very little formula writing experience.
Give me a bit and I'll let you know what notetag you need.
It might be even easier to just hook into Game_Action with a very simple plugin. I’d need to take a look later, but Game_Action would know both the target and the subject (user) of a skill/item.

Edit: Okay, @Mimironi, here is my take on the problem.

By hooking into the .apply function of Game_Action, you shouldn't need to worry about single versus multi target skills/items. By this point in Game_Action, the targets have already been made and the game is iterating through each of them.

I should add that I am wholly unfamiliar with the battle system plugin that you are using, so if it completely overwrites this function, then my approach probably wouldn't be compatible.

JavaScript:
_Game_Action_apply = Game_Action.prototype.apply;
Game_Action.prototype.apply = function(target) {
    _Game_Action_apply.call(this, target);
    let subject = this.subject();
    // The actor ID of the user
    if (subject.isActor()) subjectId = subject.actorId();
    // The actor ID of the target
    if (target.isActor()) targetId = target.actorId();
    // If both user and target are actors, call a new function
    if (subject.isActor() && target.isActor()) this.updateBond(subjectId, targetId);
}
// New function to handle/update bond mechanics
Game_Action.prototype.updateBond = function(subjectId, targetId) {
    // Print a test message with the user and target's actor IDs
    console.log('Updating bond between actor ID ' + subjectId + ' and actor ID ' + targetId)
    // Do bond-related things here
    var currentBond = 0;
    var bondGain = 0;
    // Example: increase game variable 1 by 5 if actor id 1 used a skill/item on actor id 2
    if (subjectId === 1 && targetId === 2) {
        currentBond = $gameVariables.value(1);
        bondGain = 5;
        $gameVariables.setValue(1, currentBond + bondGain);
        // Print a test message
        console.log('Bond has increased to ' + $gameVariables.value(1));
    }
}

Edited the original code with an example of how to increment a game variable based on the user and target actor IDs.

Last edit: I'm not sure if you envision certain items generating greater bond, but if so, check the spoiler below.

Spoiler
JavaScript:
_Game_Action_apply = Game_Action.prototype.apply;
Game_Action.prototype.apply = function(target) {
    _Game_Action_apply.call(this, target);
    let subject = this.subject();
    // The actor ID of the user
    if (subject.isActor()) subjectId = subject.actorId();
    // The actor ID of the target
    if (target.isActor()) targetId = target.actorId();
    // If both user and target are actors, call a new function
    if (subject.isActor() && target.isActor()) this.updateBond(subjectId, targetId, this.item());
}
// New function to handle/update bond mechanics
Game_Action.prototype.updateBond = function(subjectId, targetId, item) {
    // Print a test message with the user and target's actor IDs
    console.log('Updating bond between actor ID ' + subjectId + ' and actor ID ' + targetId)
    // Do bond-related things here
    var currentBond = 0;
    // Use the skill/item's bond gain, otherwise use a static gain of 5
    // Add <Bond:x> to the skill/item's notetag for a custom amount
    var bondGain = 5;
    if (item.meta.Bond) bondGain = parseInt(item.meta.Bond);
    // Example: increase game variable 1 if actor id 1 used a skill/item on actor id 2
    if (subjectId === 1 && targetId === 2) {
        currentBond = $gameVariables.value(1);
        $gameVariables.setValue(1, currentBond + bondGain);
        // Print a test message
        console.log('Bond has increased to ' + $gameVariables.value(1));
    }
}
@Kenen
Thank you! I seriously can't thank you enough! I even tested the <Bond:x>, as well as the skills/items that targeted multiple people just to make sure, and it all works. Currently in the process of adding lines for the rest of the character combinations ^^

Oh, and while this didn't initially work with the battle system I'm using, I ended up changing line 2 to:

Game_Action.prototype.applyCN = function(target,coopUsers) {

since that's what Chrono Engine uses to call that line, and it worked! Also putting that here for anyone else who stumbles across this thread & also uses this battle system.

Thank you again, I'll definitely make sure to credit you!
You’re welcome!

Original thread: https://forums.rpgmakerweb.com/threads/checking-both-the-user-and-target-of-an-item-or-skill.137907/