(SOLVED) On-the-fly item generation using Yanfly's ItemCore

Hi!
This new game-thing I'm working on is going to be quite retro dungeoncrawling with a heavy emphasis on the weird and wonderful items you can stumble into (both random or pre-defined). I've already downloaded and installed the excellent Yanfly's ItemCore and AttachAugments plugins. However...

Ok, let me first explain how I'd like my item system to work. You've got your couple of augments attached to a base item - the first prefix would be item quality (cheap, /none/, fine etc), second prefix and suffix are optional and bestow some kind of special quality (Fiery, of Slaying, etc). Such items cannot be further modified by players (though I might add that later for special occasions). I should be able to do this easily with augments system by simply hiding augments from players and making them non-detachable.

However, there is a big problem with the way AttachAugments works... It only allows the players to attach augments to items while I, as the "dungeon master" do not have this capability. Players are given items with empty augment slots and then augments themselves to combine. What I'd like to do is the reverse - to define a new item instance, add augments to it on the fly and then give it to players via an event or something.

For example, a classical RPG trope - there is a chest which you open and it gives you a sword with random augments on it. Or a sword with augments I've already pre-defined. Is there a way to do this using the AttachAugments and ItemCore plugins? Of course I could try defining each augment combination in the database as separate item entries but that would be impossible due to the number of combinations (and sheer insanity of such a task). Are there perhaps scriptcalls I could use and if so could you please help me out a bit with some code samples since I'm quite new at RMMV and JavaScript though I do have some experience with programming in general.

Thank you!

/edit
Added links to Yanfly's plugins. Thanks for the suggestion Kes!
Also, I've been trying to use DreamX's Random Affixes and Prefixes add-on plugin for ItemCore and here at least I can combine items myself... but only in database which is still not what I'm looking for (and it seems that it doesn't work with augments 🙁 )
@GumboSoup Please edit your post to include a link to the web pages where you got the plugins you mention. That way if people need info in order to help you, they don't have to hunt for it.
Thanks
/bump

Help, anyone?
/bump
Come on people, I know some of you gurus have this in your little finger.
Pretty please? My whole game concept depends on it 🙂 If I can't do it through RMMV I'd have to code the whole game from scratch with some lower level tool I'm familiar with... and that would be unfortunate and probably impossible given my time commitments 🙁

tl:dr of my original question: How to apply augments to items at creation using Yanfly's above-mentioned plugin?
Looking through the augments plugin, here's the code that runs when the player clicks 'ok' from the augment window to add an augment.

Code:
Scene_Item.prototype.onAugmentListOk = function() {
    var effectItem = this._augmentListWindow.item();
var slotId = this._itemActionWindow.currentExt();
 
  ItemManager.applyAugmentEffects(this.item(), effectItem, slotId, 1);
    this._augmentListWindow.refresh();
    this._augmentListWindow.activate();
    this._statusWindow.refresh();
    this._infoWindow.refresh();
    this._itemWindow.refresh();
    this._itemActionWindow.refresh();
    var index = this._augmentListWindow.index();
    this.onAugmentListCancel();
};

The important function there seems to be "applyAugmentEffects", the other actions look to be for managing the windows. Here is that function:

Code:
ItemManager.applyAugmentEffects = function(item, effectItem, slotId, gain) {
    if (!item) return;
    gain = gain || 0;
    this.checkAugmentSlots(item);
    if (item.augmentSlotItems[slotId] !== 'none') {
      var augment = this.removeAugmentFromSlot(item, slotId);
      if (augment) $gameParty.gainItem(augment, gain);
    }
    this.installAugmentToSlot(item, effectItem, slotId);
    $gameParty.loseItem(effectItem, gain);
    this.augmentRefreshParty(item);
};

So you should be able to use a script event command to call that function.
Excellent, that's a perfectly usable starting point, thank you!

Now I just have to figger out how to wrap what I want to do into something RM understands... Oh well, I guess learning some JavaScript was inevitable. I'll post my finished code here, if I manage to muddle through it, as a thank you to the community. Thanks again!
Hmm.. it seems we're not there yet 🙁
My knowledge of JS and how RMMV works is still sketchy.. I've written this as event script and it doesn't seem to do anything except give me a new sword... What am I doing wrong?


Code:
var it = $gameParty.gainItem($dataWeapons[1],1);
ItemManager.applyAugmentEffects(it, $dataItems[6], 0, false);

(found this tidbit from a way back which explains applyAugmentEffects but I still can't get it to work... I feel I keep making some really embarrassing newb mistake)
Yippee!
Finally managed to muddle through, mostly using brute force.

Here's event script code which will give the party a weapon with an augment already applied. Thank you Aloe Guvner for your help!

Code:
$gameParty.gainItem($dataWeapons[1],1);
ItemManager.applyAugmentEffects($gameParty.weapons()[0], $dataItems[6], 0, false);

If you want to augment armor just change "Weapons" in the code for "Armors" (and watch the cases). I'm not sure yet whether the third argument in applyAugmentEffects function refers to the id of augment slot on the particular item or some kind of global id for slots but I guess we can't have it all in the first go. Cheers!

/edit and oh btw you can simply delete the first line and instead place a "Change Weapons" action before the script

Original thread: https://forums.rpgmakerweb.com/threads/solved-on-the-fly-item-generation-using-yanflys-itemcore.102891/