[MZ] Dynamic Traits

Nat_DynamicTraits v1.2
Nat
​

Introduction
By default, RPG Maker MZ doesn't allow for dynamic changes to traits during gameplay, with the exception of the typical parameters. However, with this plugin, that is now a possibility for all traits!

This is a very simple plugin, with one feature - the ability to dynamically enable/disable/modify traits during gameplay.
Spoiler: Screenshots
PluginScreenshot02.png

PluginScreenshot01.png

PluginScreenshot03.png

Plugin Commands / Script Calls
Modify Trait
  • Class - The class whose trait you want to modify.
  • Trait - The trait that you want to modify, from the class's list of already assigned traits. This starts from 0, so Trait ID 0 would be the first trait in the list, Trait ID 1 would be the second, and so on. (The plugin cannot modify a trait which is not already on that list. If you wish to modify a 'new' trait, enter it initially with a value of e.g. zero or 100% depending on what the neutral figure is. An example of a new trait might be 5% Magic Reflect which the actor did not have before.)
  • Code - This is the number that determines what type of trait is being modified. Unless you're very familiar with the source code of RMMZ, I recommend that you just use the dropdown.
  • Data ID - Some of the traits prompt you to select from a dropdown menu. If this is one such trait, the Data ID is the index for that dropdown. This starts from 0, so Data ID 0 would be the first item in the dropdown, Data ID 1 would be the second, and so on. For example, Evasion Rate would be Data ID 1, Magic Reflect ID 5, and so on.
  • Modifier Type - Overwrite, Add, or Subtract. Overwrite will replace the existing value of the trait, Add will add to its existing value, and subtract will subtract from it. Add and Subtract will only work for traits which involve number inputs.
  • Value - Some of the traits prompt you to input a numerical value. If this is one such trait, the Value is the number you enter in that box (i.e. the number will be the new value, not the difference between the old value and the new). For percentages, this is a decimal value, but for everything else this is a whole number.
Download
The plugin and the demo are both available on the itch.io page:
https://sleepy-kitten-games.itch.io/dynamic-traits-rmmz

Terms and Credits
This plugin is free to use, for both commercial and non-commercial projects. If you use this plugin in your game, credit me (Nat)
This plugin may be edited/modified, but don't claim it as your own work. If you edit/modify this plugin and distribute that edit, you must still credit me as the plugin's original creator.
I am interested in this, as I was a great devotee of Shaz's Dynamic Traits when I was using Ace. But I have to admit that I am a little confused by your instructions.

You say
Trait - The trait that you want to modify. This starts from 0, so Trait ID 0 would be the first trait in the list, Trait ID 1 would be the second, and so on.
So, supposing I want to change the Evasion rate, which is on the second tab of the Traits list. Does this mean that I have to count up all the traits on tab one, and then add the traits on tab two until I get to EVA? That is what is implied, but the screenshot of your example shows sealing equipment as Trait 10, which I can't tie into anything.

When I dropped your plugin into my project, the names of the classes were the default ones, rather than the classes I actually have. Does this make a difference?

Thank you.
But I have to admit that I am a little confused by your instructions.
My bad, I'll have to rewrite the instructions to make them clearer.
It's supposed to be the list of traits you have assigned to the class:
Spoiler: Trait List Screenshot
1687334190275.png
So for the example list in the screenshot, Ex-Parameter - Hit Rate +95% would have a Trait ID of 1.
When I dropped your plugin into my project, the names of the classes were the default ones, rather than the classes I actually have. Does this make a difference?
And that's odd, the selector should be showing the project's classes. The argument is set to type @class in the plugin, and so far in every project I've tested it in that shows the project's list rather than the default list.
Even in one of my projects that has a lot of classes (probably too many if I'm being honest with myself), it shows the right number of classes and the right names.
Just to cover all the bases that I can think of, have you tried closing the project and re-opening it? I don't know how much good that might do, but sometimes that's worked for getting other RMMZ engine oddities to behave themselves.
Thanks for the info.
I'm now not at my project computer for several hours, but will test this out as soon as I can.
I have got this working, and the correct classes did show up, so thank you for that.

I would like, if I may, to suggest a couple of tweaks to your instructions to make them a little clearer. Part of the reason for this is because anyone coming to this plugin from Shaz's script (VXA) or Yanfly's plugin (MV) may assume that this works in the same way. That was my mistake, I approached it with the wrong information in my head. Suggested changes to the text are in italics.

Trait - The trait that you want to modify, from the class's list of already assigned traits.

The plugin cannot modify a trait which is not already on that list. If you wish to modify a 'new' trait, enter it initially with a value of e.g. zero or 100% depending on what the neutral figure is. An example of a new trait might be 5% Magic Reflect which the actor did not have before.

Data ID - Some of the traits prompt you to select from a dropdown menu. If this is one such trait, the Data ID is the index for that dropdown. This starts from 0, so Data ID 0 would be the first item in the dropdown, Data ID 1 would be the second, and so on. For example Evasion Rate would be Data ID 1, Magic Reflect ID 5, and so on.

Value - Some of the traits prompt you to input a numerical value. If this is one such trait, the Value is the number you enter in that dropdown i.e. the number will be the new value, not the difference between the old value and the new. For percentages, this is a decimal value, but for everything else this is a whole number.

I hope you do not mind me making these suggestions. You might justifiably decide that so few people will make these mistakes that it's not worth altering the text.
I'm glad to hear that the correct classes did show up.
And I don't mind at all, thank you for those suggestions. I'd rather add a clarification that only a few people end up needing than not add it. Especially with this being my very first plugin.
I'm back with another query.
We will assume for this example that the actor has an initial trait giving CRI 4%
I want that to increase as a reward for doing something, so I put 6% in the plugin command.
6% duly shows up in the Status scene.

But, during the course of the game, the actor finds an accessory which gives CRI + 3%.
That gives CRI 7% in the Status scene.
My plugin command comes after this. As it does not increase the base amount, simply sets it to a new value, CRI does not go up to 9%, but down to 6%.

How do I get round this? Like many games, I have a lot of gear which changes the parameters like CRI, EVA and so on.
My plugin command comes after this. As it does not increase the base amount, simply sets it to a new value, CRI does not go up to 9%, but down to 6%.
I'm not following your logic to justify this 😛

There's no difference, aside from grammar, between "increasing the base amount" and "setting it to a new value".

I haven't looked at the code for this plugin, but if it only changes the trait data from the class, anything from other sources (e.g. items) should continue to get added correctly.
@ATT_Turan Perhaps I could have worded that more clearly.
If it were altering the base amount i.e. the amount in the database, then it would be 6% plus any additions from gear, in this instance making a total of 9%.
But what it does is simply set a value irrespective of what additional increases from gear might be. That is the total, period. It does not add to the database amount.

There is a poor workaround for this. If the actor unequips anything which alters xparams like CRI and then re-equips them, the bonus from the gear is back. However, I don't think I can ask players to do that each and every time.
Well, that's really odd. In testing this on my end, the plugin command is inconsistent in whether it successfully affects the CRI or not.
However, on the times where it does successfully affect the CRI, I can confirm that setting it to +6% and then later equipping an item that adds 3% does indeed result in 9% CRI.
I'm still trying to figure out exactly why it sometimes successfully pushes the change and sometimes doesn't. Though, bizarrely enough, it does seem to sometimes fail if you've opened the Status menu immediately before the plugin command. I'm not sure why that would affect it, though. (Maybe I ought to ask the VisuStella team about that, since that's the status plugin I'm using in the project that inspired this plugin - the default status menu doesn't show x-params, after all.)
There was a similar problem with refreshing the stats in the status menu when using a 'Party Artifact' and after I put in a bug report they corrected it in an update to the Items & Equips Core. It might be helpful to mention it. It's the bug fix dated March 16 2023, and was a problem with the cache.
Hm, I've updated all of the VisuMZ plugins to the versions that were released 22 hours ago, but that's still happening. So perhaps it's possible that the issue is on my end rather than VisuMZ's? (The joys of being very very new to plugin-writing - all of this is uncharted territory for me.)
Either way, I'm not sure what could be causing the equipment's traits to not work properly on your end.
To compare notes, could you share the plugin command you used and the equipment's traits, and the result in the status menu?
Spoiler: Plugin Command
1687445102027.png
Spoiler: Equipment Traits
1687445203964.png
Spoiler: Status Menu
1687445284325.png
Okay, here goes. The objective is to increase the CRI from 4% to 6%

Spoiler: Plugin command
1687451570322.png

Spoiler: Equipment Traits
1687451664163.png

With just the gear equipped. Raises the stats from the database values of EVA 6%, CRI 4%
Spoiler: Status window, just gear
1687451886542.png

After the plugin command - CRI only, the stat has not been updated
Spoiler: Status window after plugin use
1687452102960.png

With the accessory removed, the CRI stat shows the correct updated figure of 6%

Spoiler: Status window without the accessory but after the plugin command
1687452426614.png

If I then re-equip the accessory, everything is as it should be, with the new base rate of 6% plus the 3% from the accessory.
Spoiler: Accessory re-equipped
1687452589683.png

If I equip the accessory and DO NOT open the status screen but get the plugin command first and then open the status screen, it shows accurately as 9%

This is the same refresh problem that I mentioned earlier which VS had to do a bug fix for. Something to do with the cache.

I hope my explanation is clear.
Oh, I had the order backwards in my testing. I was doing the plugin command and then the equip. Was the issue you're having with equip and then plugin command?
Yes that's right, but only if I look at the status screen first.

By the time the player gets this bonus (and others) they will have gear which improves one or more stats. That, I think, is inevitable in most games. Therefore how the plugin refreshes the cache is quite important, as I saw with VS Items & Equip.

I've just remembered another test I did with the party artifact, and that was to see if having a battle forced the refresh. It did in that instance, I'll go now and see if it does in this one.
I see. I think the problem is that the script calls I figured out that ultimately led to this plugin ($dataClasses[x].traits[y].dataId and $dataClasses[x].traits[y].value) are directly setting the value of the trait. So instead of adding to the trait, it's replacing the current value.
I'll see if I can make a couple new plugin commands for adding/subtracting, for traits where number-inputting is involved. Hopefully that will work better for your needs.
Edit: Come to think of it, perhaps it would be better to change the existing plugin command so it asks whether you want to overwrite, add, or subtract the value.
Having a battle does indeed force the refresh of the stat in the status window.
Well, it looks like I've got the add/subtract functionality working. However, I'm not entirely sure how to fix the status window not always refreshing. I've tried a few different things, but they either don't work at all or only sort of work.
Does this plugin reference any particular VS plugin in its methods?
No, it doesn't. I didn't want it to be dependent on VS plugins if I could help it, especially since the script calls work in default vanilla RMMZ. It's basically just the script calls, plus some logic to make sure everything behaves the way it's supposed to (since even with the script calls themselves, value and dataId can do different things depending on which trait is being modified).

Original thread: https://forums.rpgmakerweb.com/threads/mz-dynamic-traits.158540/