MV How to add traits dynamically

So I'm using Yanfly's Item core to have special dynamic accessories in my game. I've created a piece of code that can at the proper time randomly select a skill using certain rules and I want to know if it would be possible to push a new trait onto it. Specifically one to add the chosen skill to the accessory so it becomes usable for the holder.

Yanfly's Regen Scroll tips and tricks leads me to think that it is possible but looking into the code makes me think it won't work that way.
While I could always do it the way the tips and tricks do by creating a status for each and every skill, that feels like a really inefficient way of doing that where there should be a neater one.

Can anyone could offer some suggestions?
Yes - if you Google the words you used in the title/post, you'll find plugins for dynamic traits. I believe Shaz and Galv have written ones.
While neither works perfectly, I did find this while googling:
But there is one bit that stands out as something I don't quite understand.
The Library I read for MV is here: https://kinoar.github.io/rmmv-doc-web/interfaces/rpg.trait.html
and it doesn't define what the "Code", or rather most of the variables in the "var trait = {code: 43, dataId: rdmId, value: 1}" code mean and I don't just want to use it without know what it's doing. Is there information on how to use those somewhere.
While neither works perfectly, I did find this while googling:
But there is one bit that stands out as something I don't quite understand.
The Library I read for MV is here: https://kinoar.github.io/rmmv-doc-web/interfaces/rpg.trait.html
and it doesn't define what the "Code", or rather most of the variables in the "var trait = {code: 43, dataId: rdmId, value: 1}" code mean and I don't just want to use it without know what it's doing. Is there information on how to use those somewhere.
You'll need to look at your rpg_objects.js corescript and find the function Game_BattlerBase to see what all the codes are.

Code 43 is Game_BattlerBase.TRAIT_SKILL_ADD.
Okay so...
Game_BattlerBase.TRAIT_ELEMENT_RATE = 11;
Game_BattlerBase.TRAIT_DEBUFF_RATE = 12;
Game_BattlerBase.TRAIT_STATE_RATE = 13;
Game_BattlerBase.TRAIT_STATE_RESIST = 14;
Game_BattlerBase.TRAIT_PARAM = 21;
Game_BattlerBase.TRAIT_XPARAM = 22;
Game_BattlerBase.TRAIT_SPARAM = 23;
Game_BattlerBase.TRAIT_ATTACK_ELEMENT = 31;
Game_BattlerBase.TRAIT_ATTACK_STATE = 32;
Game_BattlerBase.TRAIT_ATTACK_SPEED = 33;
Game_BattlerBase.TRAIT_ATTACK_TIMES = 34;
Game_BattlerBase.TRAIT_STYPE_ADD = 41;
Game_BattlerBase.TRAIT_STYPE_SEAL = 42;
Game_BattlerBase.TRAIT_SKILL_ADD = 43;
Game_BattlerBase.TRAIT_SKILL_SEAL = 44;
Game_BattlerBase.TRAIT_EQUIP_WTYPE = 51;
Game_BattlerBase.TRAIT_EQUIP_ATYPE = 52;
Game_BattlerBase.TRAIT_EQUIP_LOCK = 53;
Game_BattlerBase.TRAIT_EQUIP_SEAL = 54;
Game_BattlerBase.TRAIT_SLOT_TYPE = 55;
Game_BattlerBase.TRAIT_ACTION_PLUS = 61;
Game_BattlerBase.TRAIT_SPECIAL_FLAG = 62;
Game_BattlerBase.TRAIT_COLLAPSE_TYPE = 63;
Game_BattlerBase.TRAIT_PARTY_ABILITY = 64;
Game_BattlerBase.FLAG_ID_AUTO_BATTLE = 0;
Game_BattlerBase.FLAG_ID_GUARD = 1;
Game_BattlerBase.FLAG_ID_SUBSTITUTE = 2;
Game_BattlerBase.FLAG_ID_PRESERVE_TP = 3;
Game_BattlerBase.ICON_BUFF_START = 32;
Game_BattlerBase.ICON_DEBUFF_START = 48;
Then dataId is just the ID of the skill in question and... What's value: 1 doing in this context? I could understand it if it was a rate or a param, but... is it just being declared to avoid bugs?
Certain traits have values like rates, percentage, etc., like you said. For traits that do not use the value property, It does need to be declared even if it is not used (like {code: 31, dataId: 4, value: 1} - you need the value property to be present). Otherwise, it will skip the trait and make you 'miss' your attacks and other issues may arise.

Currently, I do not know for sure, but I think there would be an error in how the object is processed since it is looking for there to be a value property before evaluating it. It does look like other functions in BattlerBase reference the value property so that could be where some of the errors are occuring. I believe Game_Action might use it as well.

Changing it to 0/null/undefined will still process the trait. Completely deleting the property does not return an error, per se, but the action (attack, defend, etc.) is not processed properly and results in misses (and other possible errors).


Strike this - edited the wrong trait. Yay. haha. Turan has the correction below.
For traits that do not use the value property, It does need to be declared even if it is not used (like {code: 31, dataId: 4, value: 1} - you need the value property to be present). Otherwise, it will skip the trait and make you 'miss' your attacks and other issues may arise.
I don't think that's the case.

I haven't gone through installing Item Core and making a script call to add a trait and test it, but I don't see anywhere that looks at the value property of an ADD_SKILL trait to see whether it's defined. I certainly don't see how it would cause you to miss an attack, the hit roll calculation doesn't look at those traits at all.

Changing it to 0/null/undefined will still process the trait.
Labeling it undefined is the same thing as not typing it at all. If one works, the other necessarily does.

Completely deleting the property does not return an error, per se, but the action (attack, defend, etc.) is not processed properly and results in misses (and other possible errors).
Where/how do you see that happen?

Granted, it's very little typing to simply set the value to 1 since that's what the editor does for the add skill traits, I'm just curious where you're seeing this stuff.
I don't think that's the case.

I haven't gone through installing Item Core and making a script call to add a trait and test it, but I don't see anywhere that looks at the value property of an ADD_SKILL trait to see whether it's defined. I certainly don't see how it would cause you to miss an attack, the hit roll calculation doesn't look at those traits at all.


Labeling it undefined is the same thing as not typing it at all. If one works, the other necessarily does.


Where/how do you see that happen?

Granted, it's very little typing to simply set the value to 1 since that's what the editor does for the add skill traits, I'm just curious where you're seeing this stuff.
I used the console and typed in the values separately for certain skills that don't use the value at all and also used delete to completely remove the property (delete $dataActors[1].traits[1].value or similar script call to remove it from the object). This was to test the OP's question on whether or not it mattered and I thought it didn't matter until it started to act up.

I thought it wouldnt matter too until the skill was just completely missing. Adding it back made it work again (regardless of the value being 1 0, null, or undefined - it just needed that property to be present) in the same test which I do think it was weird because I agree with your thoughts on labeling it as undefined is the same as not typing it at all.

I'm just giving my results on a vanilla project and those were the conclusions I found within the short time that I tested it so it is far from being complete. Your feedback and correction is appreciated because I don't want to stand on a misunderstanding of the flow here nor have an incomplete answer. haha. Thanks @ATT_Turan !
I used the console and typed in the values separately
Well, we're truly in the realm of theoretical silliness here 😉 But...

Here's the default project Short Sword with the trait to Add Skill of Double Attack:

1715484887353.png


Then I removed that trait in the editor and added it manually in the console, omitting the value property:
1715485123515.png

The skill displayed correctly in the actor's list and had no problems being used in battle (it didn't spontaneously miss or anything).
Well, we're truly in the realm of theoretical silliness here 😉 But...

Here's the default project Short Sword with the trait to Add Skill of Double Attack:

View attachment 304871

Then I removed that trait in the editor and added it manually in the console, omitting the value property:
View attachment 304874
The skill displayed correctly in the actor's list and had no problems being used in battle (it didn't spontaneously miss or anything).
I am still missing like a Stars Wars Trooper though lol...
I'll double check it again with what you did and reassess what I am doing because it only happens when I removed that value.

Thanks for clarifying and testing! (Maybe it's just been a long day and I missed a parenthesis somewhere? Haha... it's usually that... sadly...)

EDIT:

Just tested it... I swear I'm not crazy... it's fine now...
PLEASE BELIEVE ME!... ... it was missing... all of it!... the skill... the value... star wars... trooper...

sad.png


Edit of Edit:

I changed the hit rate trait thinking I was changing another trait. That was the issue. That being said, deleting the value property on the hit rate doesn't register it, but setting it to 0 makes it miss... and... I'm not going to get into this rabbit hole hahaha.

I knew I was going crazy, but also didn't know...

Thanks for the help - note to self - don't work on any of this code when you are sick and tired.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-add-traits-dynamically.168574/