MZ Random Loot stats on Items

I know this has been posted before, but does anyone have any idea on how one could make random stats on independent items in MZ. Yanfly item core did this and I know Visustella doesn’t have it yet for some reason but could you somehow use this to roll random values on items and combine it with Dungeon minds independent items ?

<JS Parameters>
MaxHP = code;
MaxMP = code;
ATK = code;
DEF = code;
MAT = code;
MDF = code;
AGI = code;
LUK = code;
</JS Parameters>

- Used for: Weapon, Armor Notetags
- Uses JavaScript to determine the values for the basic parameters based on
the code used to calculate its value.
- The variables 'MaxHP', 'MaxMP', 'ATK', 'DEF', 'MAT', 'MDF', 'AGI', and
'LUK' are used to determine the finalized value of the parameter. This
variable is case sensitive.
- If a parameter is not present, its value will be treated as +0.

'''WARNING!''' If you are trying to calculate a value based off a full
parameter value, such as "ATK = user.atk * 0.10", it's going to break and
will cause an infinite loop. Use base parameter values instead.
You can generate a random integer from a to b inclusive like this:
JavaScript:
a + Math.randomInt(b - a + 1)
E.g. a random integer in the range [5, 20]:
JavaScript:
5 + Math.randomInt(16)

I suspect you would need an "on create" hook for this, otherwise the stats would probably get rerolled whenever VisuStella refreshes the cached values. I haven't checked Dungeonmind's Independent Items to see what it offers.
Hmmm I’ll try it see what happens, you probably know way better than I do. Thought I might have found a way to do it just don’t have the JavaScript knowledge to execute it. How hard is it to put an “on create hook” on that ?
Hmmm I’ll try it see what happens, you probably know way better than I do. Thought I might have found a way to do it just don’t have the JavaScript knowledge to execute it. How hard is it to put an “on create hook” on that ?
None of what you posted is any js. You can't "put an on create hook" into a made up help file. You'd need an actual plugin.
None of what you posted is any js. You can't "put an on create hook" into a made up help file. You'd need an actual plugin.
Sorry that’s from Visustella Items and equip core. Not really a “ made up help file” .
How hard is it to put an “on create hook” on that ?
It's not a beginner-level thing. Looks like Dungeonmind had plans to make follow-up plugins, but I don't see anything like that on their site. Perhaps VisuStella have a tag that'll work for that, e.g. run code when gaining an item?

I haven't tested at all, but something like this might work:
Spoiler: plugin code
JavaScript:
/*:
 * @target MZ
 * @plugindesc Simple <on create: code> tag for Dungeonmind's Independent Items.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/threads/174751/
 * @base DM_IndependentItems
 * @orderAfter DM_IndependentItems
 * @help Free to use and/or modify for any project, no credit required.
 */
;void (() => {
"use strict";
  /** User-facing notetag identifier. */
  const TAG_NAME = "on create";

  /**
   * @param {object} item Database record from which to retrieve tag value.
   * @returns {string|boolean|undefined} Tag value.
   */
  const getTag = function(item) { return item?.meta?.[TAG_NAME]; };

  /**
   * Evaluates notetag.
   * @param {object} item Database record from which to retrieve tag value.
   */
  const applyTag = function(item) {
    const t = getTag(item);
    return t && typeof t === "string" ? eval(t) : null;
  };

  /**
   * @param {object} item Reference database record.
   * @returns {object[]} Reference independent item array.
   */
  const getObj = function(item) {  // like this to match root implementation
    const o = $gameIndependents;
    switch (item.etypeId) {
      case void 0:
        return o._independentItems;
      case 1:
        return o._independentWeapons;
      default:
        return o._independentArmors;
    }
  };

  /**
   * @param {object} item Reference database record.
   * @param {number} [count=1] Quantity of recently-created items to fetch.
   * @returns {object[]} Specified number of recently-created items.
   */
  const getRecent = function(item, count = 1) {
    const o = getObj(item); return o.slice(o.length - count);
  };

  // Patch - process notetag when gaining new independent item(s).
  const alias = Game_Independents.prototype.gainIndependentItem;
  Game_Independents.prototype.gainIndependentItem = function(oldItem, value) {
    alias.apply(this, arguments);
    // NB: root plugin does not instance each copy when value > 1
    applyTag(getRecent(oldItem)[0]);  // so we only need to eval on one item
  };

})();
Then try a notetag like, e.g.

<on create: item.atk = 5 + Math.randomInt(16); item.def = 10 + Math.randomInt(11); >

[Edit: corrected applyTag(getRecent(oldItem)) to applyTag(getRecent(oldItem)[0]).]
It's not a beginner-level thing. Looks like Dungeonmind had plans to make follow-up plugins, but I don't see anything like that on their site. Perhaps VisuStella have a tag that'll work for that, e.g. run code when gaining an item?

I haven't tested at all, but something like this might work:
Spoiler: plugin code
JavaScript:
/*:
 * @target MZ
 * @plugindesc Simple <on create: code> tag for Dungeonmind's Independent Items.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/threads/174751/
 * @base DM_IndependentItems
 * @orderAfter DM_IndependentItems
 * @help Free to use and/or modify for any project, no credit required.
 */
;void (() => {
"use strict";
  /** User-facing notetag identifier. */
  const TAG_NAME = "on create";
  /**
   * @param {object} item Database record from which to retrieve tag value.
   * @returns {string|boolean|undefined} Tag value.
   */
  const getTag = function(item) { return item?.meta?.[TAG_NAME]; };

  /**
   * Evaluates notetag.
   * @param {object} item Database record from which to retrieve tag value.
   */
  const applyTag = function(item) {
    const t = getTag(item);
    return t && typeof t === "string" ? eval(t) : null;
  };

  /**
   * @param {object} item Reference database record.
   * @returns {object[]} Reference independent item array.
   */
  const getObj = function(item) {  // like this to match root implementation
    const o = $gameIndependents;
    switch (item.etypeId) {
      case void 0:
        return o._independentItems;
      case 1:
        return o._independentWeapons;
      default:
        return o._independentArmors;
    }
  };

  /**
   * @param {object} item Reference database record.
   * @param {number} [count=1] Quantity of recently-created items to fetch.
   * @returns {object[]} Specified number of recently-created items.
   */
  const getRecent = function(item, count = 1) {
    const o = getObj(item); return o.slice(o.length - count);
  };

  // Patch - process notetag when gaining new independent item(s).
  const alias = Game_Independents.prototype.gainIndependentItem;
  Game_Independents.prototype.gainIndependentItem = function(oldItem, value) {
    alias.apply(this, arguments);
    // NB: root plugin does not instance each copy when value > 1
    applyTag(getRecent(oldItem));  // so we only need to eval on one item
  };

})();
Then try a notetag like, e.g.

<on create:
item.atk = 5 + Math.randomInt(16);
item.def = 10 + Math.randomInt(11);
>

Gah, I just tried it but I think DungeonMind's Plugin is outdated says 1.6.0 MZ and I can't get it to make any independent items at all 🙁

1737057190004.png
1737057282846.png


The fact that you wrote out an entire plug in is insane to me lol thank you so much for trying! I’ll keep trying to get this functional. It seems like a feature a lot of people want from my googling. If I can’t get it to work I’ll just have to make tons of weapons with all different stats then just have weapons drop from a loot pool. Wouldn’t be as good though as random stat generated ones.
Gah, I just tried it but I think DungeonMind's Plugin is outdated says 1.6.0 MZ and I can't get it to make any independent items at all 🙁

View attachment 329110View attachment 329111


I'm sorry it's not working for you. I regularly update my plugins to ensure compatibility and functionality. After conducting a test, I confirmed that this plugin works as intended, even in conjunction with VisuStella's ItemsEquipCore and Visual Items plugins.

If you're experiencing issues, it's possible that an incompatible plugin is causing the problem. Please note that only plugins listed on the website have been tested for compatibility. If you're using a plugin not listed, it may not be supported.


ScreenShotIndepednet-Items.png
Okay perfect! That’s actually great news there’s hope yet!

Its working, I have no idea why it wasn't before refreshing the plug ins seems to have fixed it!
The <on create: item.atk = 5 + Math.randomInt(16);> does not change the swords atk value
was a very valiant effort!
Oh, derp. Database items don't have properties like atk; instead it would be params[2], e.g.

<on create: item.params[2] = 5 + Math.randomInt(16); // atk item.params[3] = 10 + Math.randomInt(11); // def >
Basic param IDs are 0~7: mhp, mmp, atk, def, mat, mdf, agi, luk. 👋
Still no stat changes on the independent items, appreciate the effort!
1737123206655.png
Humor me a bit and try this?
item.params[2] += Math.randomInt(16);

I feel like the way you were using it with the equals sign it would set the value the same for all items at creation, esp if gained in bulk... but it could just be the way my mind was reading this.

Just a thought on it 😀



(I have a working self-ported version of YEP ItemCore, so I kinda had some of these issues way back when I did this for myself... ahh the memories!)
Humor me a bit and try this?
item.params[2] += Math.randomInt(16);

I feel like the way you were using it with the equals sign it would set the value the same for all items at creation, esp if gained in bulk... but it could just be the way my mind was reading this.

Just a thought on it 😀



(I have a working self-ported version of YEP ItemCore, so I kinda had some of these issues way back when I did this for myself... ahh the memories!)
Lol yes ohhh the joys! I did try that with Cae's plugin but still nothing I think we are close. I found this on another website that said it works with DM_IndependentItems but I haven't had any luck.

1737141436606.png
Ok, just looking at that event code... I can see issues:

letrandomBonus should be
let randomBonus

The space was missing.

and then in the actual formula part the Math.random(), does that actually return a value since you didnt set a roll value in the ()?

I feel like it should be Math.randomInt(x) * 6if anything.


Also, 2nd line of params has a 0 instead of a ] 😉
Well I have fixed the code .... but now whenever I get a "sword" (in data slot 1) it adds randomint + 8 to all swords in the game lol

1737153398658.png


I may have to just give up, make 30 of each sword with different stats and use a random loot box that pulls from those 30 weapons. Just makes a ton more work but... it'll do.
I'm not super familiar with this plugin at all, but I'd guess the issue above is the use of dataWeapons[1].
Maybe try:

JavaScript:
let newItem = $dataWeapons[newItemId];

See if that helps.
In case you get it working with a script call, I also noticed a typo in my plugin. This line:
JavaScript:
applyTag(getRecent(oldItem));
...should actually be:
JavaScript:
applyTag(getRecent(oldItem)[0]);
That's because getRecent returns an array (I changed the design part-way through). 😴
Thanks all for trying, no luck 🙁
@jimmyshmo
I see that I am not the only one looking for the exact same thing : random stats on independant items...

I read all the post and I am glad to see that the community is great here trying to find a solution altogether :LZYgrin:, love this.
Unfortunatly, my level in JS and advanced RPGMZ is so bad, I cannot help... Its clearly above my reach...

This only thing I can say is that I tried to ask directly Visustella if their roadmap has a pluging like this incoming but unfortunatly I had no answer.
I think I read somewhere that it is not on the roadmap...

Trying to have a diablolike system seems complicated this way for the moment...

I ended up doing just like you : create manually a bunch of items to simulate this...
I am just at the very beginning of my new game with this system so I cannot give you feedback on the faisability of this but ... it should work.

Did you already make your "Loot pool" ? I am using "Extra Enemy Drops VisuStella MZ" and I don't know if it is an easy thing to do yet.
This only thing I can say is that I tried to ask directly Visustella if their roadmap has a pluging like this incoming but unfortunatly I had no answer.
I think I read somewhere that it is not on the roadmap...
its not just not on the roadmap. its explicitly not on the roadmap
my team and I have decided that it's best if we don't work on Independent Items in order to be able to focus and create better gameplay plugins outside of its scope. That and we believe these features would be better off made by another plugin developer or plugin team who could dedicate their time and focus on them instead. Unfortunately, it wouldn't be from VisuStella MZ.

Original thread: https://forums.rpgmakerweb.com/threads/random-loot-stats-on-items.174751/