YEP_X_AttachAugments -- Forcing Augments onto Weapons/Armors?

Hello! I was wondering if there was a way to force attach augments onto weapons and armors using Yanfly's Attach Augment plugin. I was trying to make cursed augments that would negatively impact weapons and items, as I wasn't satisfied with just simply restricting equipment onto the player.

I believe the process would go as simply as
1) Event starts
2) Event checks to see if actor has a weapon or armor equipped (I do not require looking for specific pieces of equipment, only that it is either a weapon or armor)
3) It adds an augment slot onto that piece of equipment
4) It creates the augment
5) It attaches onto the piece of equipment into the new slot
6) Augment effects activate

I can easily alter the effects of the augment, such as making it add/subtract stats, lock it in place, all that jazz. I would just like to know what coding that needs to be done or an entirely new plugin that needs to be made that would let me do this. Thank you for taking the time to read this.
This is an interesting problem and I'm certainly curious to know what kind of solution you can develop - while I'm not one for cursing gear, I feel like it would open up a lot of creative flexibility if you could impose augments by event.

My research to date has brought up this thread - that at least illustrates how to use js to push an augment onto an item (your Step 3-5, I think). However, they're working on a newly created item; what you'll also need is a way to find your candidate item and make sure you're scoped to it (your step 2). I'm curious myself what the proper way to do that would be.
Here's the function that applies augments to gear.
Spoiler: Code
Code:
ItemManager.applyAugmentEffects(item, effectItem, slotId, gain);

So to apply augment (#52 in my item database) to the first augment slot in Actor 1's weapon we would use this:
Spoiler: Code
Code:
ItemManager.applyAugmentEffects($gameActors.actor(1).equips()[0], $dataItems[52], 0, 1);

To apply augment (#65 in the database) to the second actor's second armor slot we'd use this:
Spoiler: Code
Code:
ItemManager.applyAugmentEffects($gameActors.actor(2).equips()[3], $dataItems[65], 1, 1);

of course the equips() function depends on your 'Equipment Types' that you've set up in your database.

EDIT: MADE IT EASIER TO READ
Wow, that worked, thanks!
If I may ask, does the slotID run down the type of augment slot or all slots (By default, a weapon would have Glyph/Orb/Orb/Rune. So would slotID 1 be looking for a Glyph #2 or Orb #1?)?
And how would one use the same or similar method to remove augments as well?

EDIT: Well, I can at least answer my first question, doesn't seem to care the type of augment slot. Fair enough, isn't too much of an issue.

Figuring out Question #2 is the tough part.
My pleasure. Happy to help. Removing augments is a bit more work, so let's find the function that removes
them:
Spoiler: Code
Code:
ItemManager.removeAllAugments(item);

We just need to pass in the item we want to remove the augments from. Something like:
Spoiler: Code
Code:
ItemManager.removeAllAugments($dataWeapons[$gameActors.actor(1).equips()[0].id] );
for Armor we'd use
Spoiler: Code
Code:
ItemManager.removeAllAugments($dataArmors[$gameActors.actor(1).equips()[3].id] );

This would remove all the effects that augments have from actor 1's weapon or armor. The augments, however, still exist equipped to the weapon, even though their effects aren't working on that weapon. Let's change that.

We'll make a variable to check how many slots our weapon has. I called it augmentSlots.
Spoiler: Code
Code:
var augmentSlots = $gameActors.actor(1).equips()[0].augmentSlotItems.length;

Next, we'll make a for loop that sets all the augments to 'none' for each slot in the weapon.
Spoiler: Code
Code:
for(i=0;i<augmentSlots;i++){
$gameActors.actor(1).equips()[0].augmentSlotItems[i] ='none';
}

And we're done!
So the script call would look something like this:
Spoiler: Code
Code:
ItemManager.removeAllAugments($dataWeapons[$gameActors.actor(1).equips()[0].id] );
var augmentSlots = $gameActors.actor(1).equips()[0].augmentSlotItems.length;
for(i=0;i<augmentSlots;i++){
$gameActors.actor(1).equips()[0].augmentSlotItems[i] ='none';
}

EDIT: FIXED AN ERROR.
That one appears to destroy every augment slot on a weapon, making it so that you can't ever equip an augment on it again. It leaves the string "none" in the slot, instead of actually clearing the slot of an augment.

1590840131215.png


I would think the .removeAugmentFromSlot() function would be more effective in ejecting augments, but I wouldn't know how to use it like that.
Link me a picture of your script call.
Code:
Apparently, [i] is code for using italics in the forum coding, which messed up the code. Here's what the script call should look like:

Spoiler: Code
Code:
ItemManager.removeAllAugments($dataWeapons[$gameActors.actor(1).equips()[0].id]);
var augmentSlots = $gameActors.actor(1).equips()[0].augmentSlotItems.length;
for(i=0;i<augmentSlots;i++){
$gameActors.actor(1).equips()[0].augmentSlotItems[i] ='none';
}
I'll change it in my previous post as well.

Also, I forgot about your step 2, so we have one more step to make before we're done.
We simply need to see if the actor has a weapon/armor equipped before we try to remove the augments from it. We can do this by using a conditional statement with our previous code:
Spoiler: Code
Code:
if($gameActors.actor(1).equips()[0] !== null){
   ItemManager.removeAllAugments($dataWeapons[$gameActors.actor(1).equips()[0].id]);
   var augmentSlots = $gameActors.actor(1).equips()[0].augmentSlotItems.length;
      for(i=0;i<augmentSlots;i++){
      $gameActors.actor(1).equips()[0].augmentSlotItems[i] ='none';
      }
}
Just be sure to swap out $dataWeapons and $dataArmors depending on your 'Equipment Type.'

Alright, one last thing. If you want to be able to give the augment back to the player we need to edit God's...er Yanfly's code a little. If we open his YEP_X_AttachAugments.js file in notepad, we can find the function:
Spoiler: Code
Code:
ItemManager.removeAllAugments = function(item) {
    var augments = [];
    this.checkAugmentSlots(item);
    var length = item.augmentSlotItems.length;
    for (var i = 0; i < length; ++i) {
      var augment = this.removeAugmentFromSlot(item, i);
      augments.push(augment);
    }
    return augments;
};
All we have to do is add one line to it:
$gameParty.gainItem(augment, 1);
So the function would look like this:
Spoiler: Code
Code:
ItemManager.removeAllAugments = function(item) {
    var augments = [];
    this.checkAugmentSlots(item);
    var length = item.augmentSlotItems.length;
    for (var i = 0; i < length; ++i) {
      var augment = this.removeAugmentFromSlot(item, i);
      augments.push(augment);
      $gameParty.gainItem(augment, 1);
    }
    return augments;
};

I know this has been super long winded, but done correctly, it should work. Good luck!
Much better! It works like a charm! Thank you so much!
No problem. Hopefully it'll help others as well. 🤘

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/yep_x_attachaugments-forcing-augments-onto-weapons-armors.122040/