MZ Please help scripting dice-roll of "traits" for actors

Yay, it works now! Many thanks!
Great, you're welcome! 👋

The funny thing is that it doesn't seem to pick up the traits with the below
My plugin does not add the traits to any database record, that's why. Instead, you can find its data under the plugin namespace, ExtraTraits. E.g. to see the random param rate traits for actor 1 via the console:
JavaScript:
ExtraTraits.data.randomParamRates[1];
traitObjects fetches all trait sources for a battler: all database objects giving them traits, e.g. actor, class, states, equipment. My plugin patches that method to add a (potential) new trait source for each Game_Actor. It checks for data pertaining to that actor, and if found, offers it as a new, anonymous set/source of traits.
ExtraTraits.data.randomParamRates[1];
Okay, I can see that there's six objects in there((6) [{…}, {…}, {…}, {…}, {…}, {…}]), but still experimenting how to lookup the entries of the objects.

Got it,

ExtraTraits.data.randomParamRates[1][1]

{code: 21, dataId: 3, value: 1.6}

Was trying to retrieve array values using normal parentheses because visual basic habits... urgh
Yep, it's just an array of traits, e.g. ExtraTraits.data.randomParamRates[1][0] for the first "extra" trait of actor ID 1~
Wonderful! Now I can make items (pills?) that do rerolls for any of the party members, too!

Thanks for your kind and patient lecturing... it helps so much with the steep learning curve.

JavaScript:
let CharParam = ["STR","CON","INT","WIS","DEX","CHA"];
let textMessage = "";
for (let k = 0; k < 6; k++) {
textMessage += CharParam[k] + ":" + ExtraTraits.data.randomParamRates[1][k].value * 10 + " ";
(k == 2) ? (textMessage += "\n"):(textMessage += "");
}
$gameMessage.add(textMessage);
this.setWaitMode('message');
Now I can make items (pills?) that do rerolls for any of the party members, too!
I mean, you technically could do that already with Conditional Branch and Plugin Command. Could get tedious if you have many actors, though. Or maybe you meant randomising only specific params or something.

As we've seen, VisuStella has a cache system, so if you do change any traits then you should refresh the trait bearer afterwards, e.g. $gameActors.actor(1).refresh().

For variable inputs you can just call the named function bound to the plugin command, e.g.
JavaScript:
ExtraTraits.command.get("Randomise Param Rates")({
  Actor: $gameVariables.value(123)
});
I.e. "randomise param rates for the actor with ID equal to the value of game variable 123." This has the advantage of replicating the plugin command, including the battler refresh.

(It's "get etc" here just because I used a Map for storing the commands, instead of a normal object.)

In case you're interested: it'd be relatively simple to rewrite the plugin command (or add a new one) to accept a variable ID and use the value of that variable as the actor ID instead. You could change:
  • The arg in the header from @type actor to @type variable;
  • How the actor ID is obtained from the input arguments.
In that case you'd probably also want to change the arg name in both places, too.

Original thread: https://forums.rpgmakerweb.com/threads/please-help-scripting-dice-roll-of-traits-for-actors.158453/